Skip to content
Snippets Groups Projects
Commit 45ebabcd authored by CaTasTrOOf's avatar CaTasTrOOf
Browse files

Modification pre-commit Hook

* Fix regex bug
* Create missing keys on i18n files
parent 63133e13
No related branches found
No related tags found
1 merge request!12Script verify i18 n
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
#!/bin/sh #!/bin/bash
$(git rev-parse --show-toplevel)/utils/findMissingI18nKeys.sh $(git rev-parse --show-toplevel)/utils/findMissingI18nKeys.sh
FINDING_MISSING_KEYS=$? FINDING_MISSING_KEYS=$?
......
#!/bin/sh #!/bin/bash
TMP_FILE=temp TMP_FILE=temp
KEY_FILE=keysUsed KEY_FILE=keysUsed
grep --include=\*.vue --exclude=\*template.vue -roE -e "\\\$(t|tc)\((\"|')([a-Z.]*)(\"|')(, [a-Z._]*){0,1}\)" . > $TMP_FILE # Get all used keys in Vue files
grep --include=\*.vue --exclude=\*template.vue -roE -e "\\\$(t|tc)\((\"|')([a-zA-Z.]*)(\"|')(, [a-zA-Z._]*){0,1}\)" . > $TMP_FILE
sed -i -e "s/'/\"/" $TMP_FILE sed -i -e "s/'/\"/" $TMP_FILE
sed -i -e "s/'/\"/" $TMP_FILE sed -i -e "s/'/\"/" $TMP_FILE
sed -i -E -e 's/\..*:\$(t|tc)\("([a-Z.]*).*$/\2/' $TMP_FILE sed -i -E -e 's/\..*:\$(t|tc)\("([a-zA-Z.]*).*$/\2/' $TMP_FILE
# Remove duplicates keys
sort $TMP_FILE | uniq > $KEY_FILE sort $TMP_FILE | uniq > $KEY_FILE
# Verify all i18n files
FILES="i18n/locales/*.json" FILES="i18n/locales/*.json"
RETURN_CODE=0
for f in $FILES for f in $FILES
do do
echo "Processing $f file..." echo "Processing $f file..."
missingFile="$(basename $f).missing"
if [ -f $missingFile ] tmp=$(mktemp)
then
rm -fr $missingFile
fi
while read key; do while read key; do
# Verify if key exists
jq -e ".$key" < $f > /dev/null jq -e ".$key" < $f > /dev/null
status=$? status=$?
# If not, create it
if [ $status -ne 0 ] if [ $status -ne 0 ]
then then
echo $key >> $missingFile echo "create $key in file $f"
filter=".${key} = \"TO_TRANSLATE\""
jq --sort-keys "$filter" $f > "$tmp" && mv "$tmp" $f
RETURN_CODE=$((RETURN_CODE+1))
fi fi
done < $KEY_FILE done < $KEY_FILE
# take action on each file. $f store current file name
# cat "$f"
done done
MISSING_FILES="*.missing"
RETURN_CODE=0
if ls $MISSING_FILES 1> /dev/null 2>&1; then
for f in $MISSING_FILES
do
RETURN_CODE=$((RETURN_CODE+1))
echo "Missing keys in $f"
cat $f
done
fi
rm $KEY_FILE $TMP_FILE rm $KEY_FILE $TMP_FILE
# Return 0 if no key was created, or number of keys added
exit $RETURN_CODE exit $RETURN_CODE
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment