aboutsummaryrefslogtreecommitdiff
path: root/scripts/sync-translations.sh
blob: 149c7ff6ad86be9ade9f5999f35eff93f72d5fe5 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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