From 97636b23f50d19fcad9f58310858e75982d5b1f4 Mon Sep 17 00:00:00 2001 From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com> Date: Sat, 11 May 2024 21:02:57 +0200 Subject: [PATCH] Check translations keys in CI (#279) --- .github/workflows/go.yml | 5 ++- Makefile | 5 ++- .../i18n/locales/{de_DE.yml => de-DE.yml} | 3 -- internal/i18n/locales/es-ES.yml | 1 - internal/i18n/locales/fr-FR.yml | 1 - internal/i18n/locales/pt-BR.yml | 3 -- scripts/check-translations.sh | 39 +++++++++++++++++++ 7 files changed, 47 insertions(+), 10 deletions(-) rename internal/i18n/locales/{de_DE.yml => de-DE.yml} (98%) create mode 100755 scripts/check-translations.sh diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cb05551..cb38328 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -41,9 +41,12 @@ jobs: with: go-version: "1.22" - - name: Check + - name: Check Go modules run: make go_mod check_changes + - name: Check translations + run: make check-tr + test: strategy: fail-fast: false diff --git a/Makefile b/Makefile index 3fe8704..0f0e2cc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all all_crosscompile install build_frontend build_backend build build_crosscompile build_docker build_dev_docker run_dev_docker watch_frontend watch_backend watch clean clean_docker check_changes go_mod fmt test +.PHONY: all all_crosscompile install build_frontend build_backend build build_crosscompile build_docker build_dev_docker run_dev_docker watch_frontend watch_backend watch clean clean_docker check_changes go_mod fmt test check-tr # Specify the name of your Go binary output BINARY_NAME := opengist @@ -73,3 +73,6 @@ fmt: test: @go test ./... -p 1 + +check-tr: + @bash ./scripts/check-translations.sh \ No newline at end of file diff --git a/internal/i18n/locales/de_DE.yml b/internal/i18n/locales/de-DE.yml similarity index 98% rename from internal/i18n/locales/de_DE.yml rename to internal/i18n/locales/de-DE.yml index 1e2e83b..6056052 100644 --- a/internal/i18n/locales/de_DE.yml +++ b/internal/i18n/locales/de-DE.yml @@ -132,9 +132,6 @@ auth.username: 'Benutzername' auth.password: 'Passwort' auth.register-instead: 'Stattdessen registrieren' auth.login-instead: 'Stattdessen anmelden' -auth.github-oauth: 'Mit GitHub-Account fortfahren' -auth.gitlab-oauth: 'Mit GitLab-Account fortfahren' -auth.gitea-oauth: 'Mit Gitea-Account fortfahren' error: 'Fehler' diff --git a/internal/i18n/locales/es-ES.yml b/internal/i18n/locales/es-ES.yml index 244fd17..1fd70b2 100644 --- a/internal/i18n/locales/es-ES.yml +++ b/internal/i18n/locales/es-ES.yml @@ -157,7 +157,6 @@ admin.delete: Eliminar admin.created_at: Creado admin.config-link: Esta configuración puede ser %s por un archivo de configuración YAML y/o variables de entorno. -admin.config-link-overridden: sobrescrito admin.disable-signup: Deshabilitar registro admin.disable-signup_help: Prohibir la creación de nuevas cuentas. admin.require-login: Requerir inicio de sesión diff --git a/internal/i18n/locales/fr-FR.yml b/internal/i18n/locales/fr-FR.yml index f268249..d6716f8 100644 --- a/internal/i18n/locales/fr-FR.yml +++ b/internal/i18n/locales/fr-FR.yml @@ -187,7 +187,6 @@ settings.create-password-help: Créer un mot de passe pour se connecter à Openg settings.change-password: Changer le mot de passe settings.change-password-help: Changer le mot de passe pour se connecter à Opengist via HTTP settings.password-label-title: Mot de passe -auth.gitlab-oauth: Continuer avec un compte GitLab admin.actions.sync-previews: Synchroniser l'aperçu des gists admin.actions.reset-hooks: Réinitialiser les hooks de Git pour tous les dépôts gist.new.url: URL diff --git a/internal/i18n/locales/pt-BR.yml b/internal/i18n/locales/pt-BR.yml index 2eee31e..4e71c5b 100644 --- a/internal/i18n/locales/pt-BR.yml +++ b/internal/i18n/locales/pt-BR.yml @@ -17,8 +17,6 @@ gist.header.clone-http: Clonar via %s gist.header.clone-http-help: Clonar com Git usando autenticação básica HTTP. gist.header.clone-ssh: Clonar via SSH gist.header.clone-ssh-help: Clonar com Git usando uma chave SSH. -gist.header.share: Compartilhar -gist.header.share-help: Copiar link para compartilhar este gist. gist.header.download-zip: Baixar ZIP gist.raw: Bruto @@ -157,7 +155,6 @@ admin.delete: Excluir admin.created_at: Criado admin.config-link: Esta configuração pode ser %s por um arquivo de configuração YAML e/ou variáveis de ambiente. -admin.config-link-overridden: sobrescrito admin.disable-signup: Desabilitar registro admin.disable-signup_help: Proibir a criação de novas contas. admin.require-login: Exigir login diff --git a/scripts/check-translations.sh b/scripts/check-translations.sh new file mode 100755 index 0000000..bfe8891 --- /dev/null +++ b/scripts/check-translations.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +differences_found=0 + +# Extract keys from the reference file and sort them +sort <(awk -F':' '{print $1}' internal/i18n/locales/en-US.yml) > sorted_reference_keys.txt +sed -i '/^\s*$/d' sorted_reference_keys.txt + +for new_file in internal/i18n/locales/*.yml; do + filename=$(basename $new_file) + echo "" + echo "Checking $filename..." + + # Extract keys from the current file and sort them + sort <(awk -F':' '{print $1}' $new_file) > sorted_new_keys.txt + sed -i '/^\s*$/d' sorted_new_keys.txt + + comm -3 sorted_reference_keys.txt sorted_new_keys.txt > differences.txt + + if [ -s differences.txt ]; then + echo "Error in $filename: The YAML file has differences in keys." + while IFS= read -r line; do + if [[ $line == $'\t'* ]]; then + echo "+ Additional key in $filename: $(echo $line | awk '{$1=$1; print}')" + else + echo "- Missing key in $filename: $(echo $line | awk '{$1=$1; print}')" + fi + done < differences.txt + differences_found=1 + else + echo "All keys in $filename match perfectly." + fi + + rm sorted_new_keys.txt +done + +rm sorted_reference_keys.txt differences.txt + +exit $differences_found