diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000000000000000000000000000000000000..2757b67b63795d58868d769f8b03ad967544fa8b --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,27 @@ +#!/bin/bash + +# Color for echo +RED='\e[31m' +GREEN='\e[32m' +BLUE='\e[34m' +UNDERLINE='\e[4m' +BOLD='\e[1m' +NC='\e[0m' + +if ! command -v jq &> /dev/null +then + echo -e "${RED}I require jq but it's not installed." + echo -e "${BOLD}${GREEN}See informations here : ${NC}${BLUE}${UNDERLINE}https://stedolan.github.io/jq/download/${NC}" + echo -e "${RED}We can't check if you have put all i18n keys in JSON files${NC}" + exit 0 +else + $(git rev-parse --show-toplevel)/utils/findMissingI18nKeys.sh + FINDING_MISSING_KEYS=$? + echo -e "$BLUE$FINDING_MISSING_KEYS$NC" + if [ $FINDING_MISSING_KEYS -ne 0 ]; then + echo -e "${RED}You must to complete all i18n keys used in pages${NC}" + git st i18n/locales/*.json + exit $FINDING_MISSING_KEYS + fi +fi +exit 0 diff --git a/.gitignore b/.gitignore index 3fea6ecc2abc86553c5c0bee1c9219f11693f547..60cde3202016ffdb87282e29a32c1eae0c7349d0 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,7 @@ sw.* # Vim swap files *.swp + +# Script generated files +*.missing +keysUsed \ No newline at end of file diff --git a/README.md b/README.md index 94a7691793fa08fa76319dca7327f35751dafc00..3c45cf6c293766037474b38f9bfc1d56a037ceaf 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,16 @@ This project needs NodeJS v16 +In order to use the hooks, this project needs : + +- jq ([Site pour le download](https://stedolan.github.io/jq/download/)) + ## Contribute ```bash $ git clone https://git.duniter.org/paidge/wotwizard-ui.git $ cd wotwizard-ui +$ git config --local core.hooksPath .githooks/ $ nvm use 16 $ git checkout -b my-branch $ npm install diff --git a/i18n/locales/fr.json b/i18n/locales/fr.json index 1e0f7247e3d0e486ce3edb9473dbb28d715aaf4f..293d3a38a99be4f3f220951ef10d1b04e656555d 100644 --- a/i18n/locales/fr.json +++ b/i18n/locales/fr.json @@ -12,8 +12,8 @@ "developpeurs": "Développeurs :", "graphql": "API grahQL", "participants": "Liste des participants au projet :", - "title": "À propos", "testeurs": "Testeurs :", + "title": "À propos", "traducteurs": "Traducteurs :" }, "aurevoir": "Au revoir à ", @@ -83,8 +83,8 @@ "title": "Mes favoris", "use": "Mes favoris uniquement" }, - "futuremembers": "Futures entrées", "futureexits": "Futures sorties", + "futuremembers": "Futures entrées", "infos": "Informations", "inout": "Entrées et sorties de la toile de confiance des 2 derniers jours", "inpreparation": "En préparation", @@ -168,8 +168,8 @@ "pardate": "Prévisions par date", "parmembre": "Prévisions par membres", "period": { - "title": "Période de recherche", - "desc": "Sélectionnez le nombre de jours souhaités" + "desc": "Sélectionnez le nombre de jours souhaités", + "title": "Période de recherche" }, "title": "Prévisions" }, diff --git a/utils/findMissingI18nKeys.sh b/utils/findMissingI18nKeys.sh new file mode 100755 index 0000000000000000000000000000000000000000..920c4ed3a839acd457f35bfea26ff2422f91af6f --- /dev/null +++ b/utils/findMissingI18nKeys.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Color for echo +RED='\e[31m' +GREEN='\e[32m' +NC='\e[0m' + +TMP_FILE=temp +KEY_FILE=keysUsed + +# 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-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 -e "Processing ${GREEN}$f${NC} file..." + + 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 -e "create ${RED}$key${NC} in file ${GREEN}$f${NC}" + value=$(jq -e ".$key" i18n/locales/fr.json) + if [ "$value" == "null" ] + then + filter=".$key = \"TO_TRANSLATE\"" + else + filter=".$key = $value" + fi + jq --sort-keys "$filter" $f > "$tmp" && mv "$tmp" $f + RETURN_CODE=$((RETURN_CODE+1)) + fi + done < $KEY_FILE +done + +rm $KEY_FILE $TMP_FILE +# Return 0 if no key was created, or number of keys added +exit $RETURN_CODE