Better real estate use
[tails.git] / import-translations
blobc348758b59b5c4754ff901161563b4603719123c
1 #!/bin/sh
3 set -e
4 set -u
6 EXCLUDE_LANGS=''
7 TAILS_PO_DIR='po'
8 SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
9 TOR_TRANSLATION_REMOTE='https://gitlab.torproject.org/tpo/translation.git'
10 TOR_TRANSLATION_DIR="$SCRIPT_DIR/tmp/tor-translation"
11 GIT_IN_TOR_TRANSLATION_DIR="git \
12 --work-tree=\"$TOR_TRANSLATION_DIR\" \
13 --git-dir=\"$TOR_TRANSLATION_DIR/.git\""
15 ### External libraries
16 . "$SCRIPT_DIR/config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh"
18 lang_is_excluded () {
19 local lang="$1"
20 echo -n "$EXCLUDE_LANGS" | grep -qs -w "$lang"
23 # Defaults
24 LANG_DOT_PO_LAYOUT=yes
26 # Detect which project is in current folder,
27 # and set parameters accordingly
28 # shellcheck disable=SC2016
29 if [ -f 'po/tails.pot' ]; then
30 BRANCH='tails-misc_release'
31 AFTER_IMPORT='intltool_update_po $(po_languages)'
32 elif [ -f 'po/onioncircuits.pot' ]; then
33 LANG_DOT_PO_LAYOUT=no
34 BRANCH='tails-onioncircuits_release'
35 AFTER_IMPORT='./setup.py build_i18n && ( cd po && for po in *.po ; do msgmerge --update "$po" onioncircuits.pot ; done )'
36 else
37 echo "Current folder is not a project known to this script!"
38 exit 1
41 # Clone or update the translation repository
42 if [ -d "$TOR_TRANSLATION_DIR" ]; then
43 eval "$GIT_IN_TOR_TRANSLATION_DIR remote set-url origin ${TOR_TRANSLATION_REMOTE}"
44 eval "$GIT_IN_TOR_TRANSLATION_DIR fetch origin"
45 else
46 mkdir -p "$SCRIPT_DIR/tmp"
47 git clone "$TOR_TRANSLATION_REMOTE" "$TOR_TRANSLATION_DIR"
50 # Checkout the correct branch
51 eval "$GIT_IN_TOR_TRANSLATION_DIR checkout \"$BRANCH\""
52 eval "$GIT_IN_TOR_TRANSLATION_DIR reset --hard \"origin/$BRANCH\""
54 # Ensure we only keep PO files that are still present in the Transifex
55 # branch we import from.
56 find "$TAILS_PO_DIR" -name '*.po' -delete
58 # For each completely translated language, merge it,
59 # unless it is translated outside Transifex
60 if [ "$LANG_DOT_PO_LAYOUT" = yes ] ; then
61 find "$TOR_TRANSLATION_DIR" -name '*.po' | sort | while read -r po_file; do
62 lang=$(basename "$po_file" | tr - _ | sed 's/\.po$//')
64 ! lang_is_excluded "$lang" || continue
65 if [ "$(count_translated_strings < "$po_file")" -lt 1 ]; then
66 echo "Skipping $lang, that has no translated strings."
67 continue
69 echo "Importing translation for $lang..."
70 cp "$po_file" "$TAILS_PO_DIR"
71 done
72 else
73 find "$TOR_TRANSLATION_DIR" -name '*.pot' | sort | while read -r po_file; do
74 lang=$(basename "$(dirname "$po_file" | tr - _ | sed 's/\.pot$//')")
76 ! lang_is_excluded "$lang" || continue
77 if [ "$(count_translated_strings < "$po_file")" -lt 1 ]; then
78 echo "Skipping $lang, that has no translated strings."
79 continue
81 echo "Importing translation for $lang..."
82 cp "$po_file" "$TAILS_PO_DIR/${lang}.po"
83 done
86 # Update PO files
87 if [ -n "${AFTER_IMPORT:-}" ]; then
88 eval "$AFTER_IMPORT"