Skip to content
Snippets Groups Projects
Commit 860ce85f authored by CaTasTrOOf's avatar CaTasTrOOf
Browse files

Add pre-commit hook to check i18n keys

parent 1de626e0
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
#!/bin/sh
$(git rev-parse --show-toplevel)/utils/findMissingI18nKeys.sh
FINDING_MISSING_KEYS=$?
if [ $FINDING_MISSING_KEYS -ne 0 ]; then
echo "You must to complete all i18n keys used in pages"
exit $FINDING_MISSING_KEYS
fi
exit 0
......@@ -89,3 +89,7 @@ sw.*
# Vim swap files
*.swp
# Script generated files
*.missing
keysUsed
\ No newline at end of file
#!/bin/sh
TMP_FILE=temp
KEY_FILE=keysUsed
grep --include=\*.vue --exclude=\*template.vue -roE -e "\\\$(t|tc)\((\"|')([a-Z.]*)(\"|')(, [a-Z._]*){0,1}\)" . > $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
sort $TMP_FILE | uniq > $KEY_FILE
FILES="i18n/locales/*.json"
for f in $FILES
do
echo "Processing $f file..."
missingFile="$(basename $f).missing"
if [ -f $missingFile ]
then
rm -fr $missingFile
fi
while read key; do
jq -e ".$key" < $f > /dev/null
status=$?
if [ $status -ne 0 ]
then
echo $key >> $missingFile
fi
done < $KEY_FILE
# take action on each file. $f store current file name
# cat "$f"
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
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