7 SCRIPT_DIR
=$
(readlink
-f "$(dirname "$0")")
8 TOR_TRANSLATION_REMOTE
='https://gitlab.torproject.org/tpo/translation.git'
9 TOR_TRANSLATION_DIR
="$SCRIPT_DIR/tmp/tor-translation"
10 GIT_IN_TOR_TRANSLATION_DIR
="git \
11 --work-tree=\"$TOR_TRANSLATION_DIR\" \
12 --git-dir=\"$TOR_TRANSLATION_DIR/.git\""
15 ### External libraries
16 .
"$SCRIPT_DIR/config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh"
19 LANG_DOT_PO_LAYOUT
=yes
21 # Detect which project is in current folder,
22 # and set parameters accordingly
23 # shellcheck disable=SC2016
24 if [ -f 'po/tails.pot' ]; then
25 POTFILE
='po/tails.pot'
27 AFTER_IMPORT
='intltool_update_po $(po_languages)'
28 elif [ -f 'po/onioncircuits.pot' ]; then
29 POTFILE
='po/onioncircuits.pot'
31 BRANCH
='tails-onioncircuits_release'
32 AFTER_IMPORT
='./setup.py build_i18n && ( cd po && for po in *.po ; do msgmerge --update "$po" onioncircuits.pot ; done )'
34 echo "Current folder is not a project known to this script!"
38 TOTAL
=$
(msgattrib
--no-obsolete "$POTFILE" | count_msgids
)
40 # Clone or update the translation repository
41 if [ -d "$TOR_TRANSLATION_DIR" ]; then
42 eval "$GIT_IN_TOR_TRANSLATION_DIR remote set-url origin ${TOR_TRANSLATION_REMOTE}"
43 eval "$GIT_IN_TOR_TRANSLATION_DIR fetch origin"
45 mkdir
-p "$SCRIPT_DIR/tmp"
46 git clone
"$TOR_TRANSLATION_REMOTE" "$TOR_TRANSLATION_DIR"
49 # Checkout the correct branch
50 eval "$GIT_IN_TOR_TRANSLATION_DIR checkout \"$BRANCH\""
51 eval "$GIT_IN_TOR_TRANSLATION_DIR reset --hard \"origin/$BRANCH\""
53 # Ensure we only keep PO files that are still present in the
54 # branch we import from.
55 find "$TAILS_PO_DIR" -name '*.po' -delete
61 # Always import the default locale, whose .mo file is needed
62 # at least by tailsgreeter.config.set_current_language.
63 if [ "$lang" = "en" ] ||
[ "$lang" = "en_US" ]; then
67 translated_strings
=$
(count_translated_strings
< "$po_file")
68 if [ $
((100*translated_strings
/TOTAL
)) -lt "$MINIMUM_PERCENT" ]; then
69 echo "Skipping $lang, that has less than $MINIMUM_PERCENT translated strings."
76 # Import PO files that have at least $MINIMUM_PERCENT % of strings translated
77 if [ "$LANG_DOT_PO_LAYOUT" = yes ] ; then
78 find "$TOR_TRANSLATION_DIR" -name '*.po' |
sort |
while read -r po_file
; do
79 lang
=$
(basename "$po_file" |
tr - _ |
sed 's/\.po$//')
80 po_import_filter
"$po_file" "$lang" ||
continue
81 echo "Importing translation for $lang..."
82 cp "$po_file" "$TAILS_PO_DIR"
85 find "$TOR_TRANSLATION_DIR" -name '*.pot' |
sort |
while read -r po_file
; do
86 lang
=$
(basename "$(dirname "$po_file" | tr - _ | sed 's/\.pot$//')")
87 po_import_filter
"$po_file" "$lang" ||
continue
88 echo "Importing translation for $lang..."
89 cp "$po_file" "$TAILS_PO_DIR/${lang}.po"
94 if [ -n "${AFTER_IMPORT:-}" ]; then