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

Modification pre-commit Hook

* Fix regex bug
* Create missing keys on i18n files
parent a903472d
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
#!/bin/bash
$(git rev-parse --show-toplevel)/utils/findMissingI18nKeys.sh
FINDING_MISSING_KEYS=$?
......
#!/bin/sh
#!/bin/bash
TMP_FILE=temp
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 -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
# Verify all i18n files
FILES="i18n/locales/*.json"
RETURN_CODE=0
for f in $FILES
do
echo "Processing $f file..."
missingFile="$(basename $f).missing"
if [ -f $missingFile ]
then
rm -fr $missingFile
fi
tmp=$(mktemp)
while read key; do
# Verify if key exists
jq -e ".$key" < $f > /dev/null
status=$?
# If not, create it
if [ $status -ne 0 ]
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
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
# Return 0 if no key was created, or number of keys added
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