Skip to content

Commit

Permalink
Check translations keys in CI (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiceli committed May 11, 2024
1 parent f705e87 commit 97636b2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -73,3 +73,6 @@ fmt:

test:
@go test ./... -p 1

check-tr:
@bash ./scripts/check-translations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
1 change: 0 additions & 1 deletion internal/i18n/locales/es-ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/i18n/locales/fr-FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions internal/i18n/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions scripts/check-translations.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 97636b2

Please sign in to comment.