From 0e3d760826e209f3ae304ca0a7b12de300cd977e Mon Sep 17 00:00:00 2001 From: nixpkgs-review Date: Wed, 4 Nov 2020 07:50:57 -0300 Subject: Split sync-translations.sh into two scripts --- scripts/apply-translations.sh | 14 ++++++++++++++ scripts/extract-translations.sh | 17 +++++++++++++++++ scripts/sync-translations.sh | 34 ---------------------------------- 3 files changed, 31 insertions(+), 34 deletions(-) create mode 100755 scripts/apply-translations.sh create mode 100755 scripts/extract-translations.sh delete mode 100755 scripts/sync-translations.sh (limited to 'scripts') diff --git a/scripts/apply-translations.sh b/scripts/apply-translations.sh new file mode 100755 index 0000000..2620638 --- /dev/null +++ b/scripts/apply-translations.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +for f in $(find _tils -type f -name '*.md' | grep -v '^./vendor/' | grep -v '^./_site/' | grep -v './drafts/' | grep -v './templates/'); do + l="$(grep '^lang: ..$' "$f" | awk '{print $2}')" + if [[ "$l" != 'en' ]]; then + ref="$(grep '^ref: ' "$f" | awk '{print $2}')" + # shellcheck disable=2046 + FROM=$(find $(find . -name '*.md' -exec grep -l "^ref: $ref$" {} \;) -exec grep -l '^lang: en$' {} \;) + po2md "$FROM" --pofiles "locale/$l/LC_MESSAGES/${FROM%.md}.po" --quiet --save "$f" + fi +done diff --git a/scripts/extract-translations.sh b/scripts/extract-translations.sh new file mode 100755 index 0000000..e6d2071 --- /dev/null +++ b/scripts/extract-translations.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +TRANSLATIONS=(pt fr eo) + +for f in $(find . -type f -name '*.md' | grep -v '^./vendor' | grep -v '^./_site' | grep -v '^./drafts/' | grep -v './templates/'); do + file_lang="$(grep '^lang: ..$' "$f" | awk '{print $2}')" + if [[ "$file_lang" = 'en' ]]; then + for l in "${TRANSLATIONS[@]}"; do + OUT="locale/$l/LC_MESSAGES/${f%.md}.po" + mkdir -p "$(dirname "$OUT")" + md2po "$f" --quiet --save --po-filepath "$OUT" + done + fi +done diff --git a/scripts/sync-translations.sh b/scripts/sync-translations.sh deleted file mode 100755 index 149c7ff..0000000 --- a/scripts/sync-translations.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -set -Eeuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")" -cd ../ - -TRANSLATIONS=(pt fr eo) - -for f in $(find . -type f -name '*.md' | grep -v '^./vendor' | grep -v '^./_site' | grep -v '^./drafts/' | grep -v './templates/'); do - file_lang="$(grep '^lang: ..$' "$f" | awk '{print $2}')" - if [[ "$file_lang" = 'en' ]]; then - for l in "${TRANSLATIONS[@]}"; do - OUT="locale/$l/LC_MESSAGES/${f%.md}.po" - mkdir -p "$(dirname "$OUT")" - md2po "$f" --quiet --save --po-filepath "$OUT" - done - fi -done - -for f in $(find _tils -type f -name '*.md' | grep -v '^./vendor/' | grep -v '^./_site/' | grep -v './drafts/' | grep -v './templates/'); do - l="$(grep '^lang: ..$' "$f" | awk '{print $2}')" - if [[ "$l" != 'en' ]]; then - ref="$(grep '^ref: ' "$f" | awk '{print $2}')" - # shellcheck disable=2046 - FROM=$(find $(find . -name '*.md' -exec grep -l "^ref: $ref$" {} \;) -exec grep -l '^lang: en$' {} \;) - po2md "$FROM" --pofiles "locale/$l/LC_MESSAGES/$ref.po" --quiet --save "$f" - fi -done - -if [[ "${1:-}" = '--check' ]]; then - git diff --quiet || { - echo 'Translations are not in sync.' - exit 1 - } -fi -- cgit v1.2.3