Test suite: work around the empty, unnamed frame.
[tails.git] / import-translations
blob20a6f6e4e4405f58294a6d9f6f0e4f1b99eed96e
1 #!/bin/sh
3 set -e
4 set -u
6 EXCLUDE_LANGS='fr'
7 TAILS_PO_DIR='po'
8 SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
9 TOR_TRANSLATION_REMOTE='https://git.torproject.org/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 if [ -f 'po/tails.pot' ]; then
29 BRANCH='tails-misc_completed'
30 AFTER_IMPORT='intltool_update_po $(po_languages)'
31 elif [ -f 'po/tails-greeter.pot' ]; then
32 BRANCH='tails-greeter-2_completed'
33 AFTER_IMPORT='./setup.py build_i18n'
34 elif [ -f 'po/tails-iuk.pot' ]; then
35 BRANCH='tails-iuk_completed'
36 AFTER_IMPORT='make -C po pot && make -C po update-po'
37 elif [ -f 'po/onioncircuits.pot' ]; then
38 LANG_DOT_PO_LAYOUT=no
39 POTFILE=onioncircuits.pot
40 BRANCH='tails-onioncircuits_completed'
41 AFTER_IMPORT='./setup.py build_i18n && ( cd po && for po in *.po ; do msgmerge --update "$po" onioncircuits.pot ; done )'
42 elif [ -f 'po/tails-perl5lib.pot' ]; then
43 BRANCH='tails-perl5lib_completed'
44 AFTER_IMPORT='make -C po pot && make -C po update-po'
45 elif [ -f 'po/tails-installer.pot' ]; then
46 BRANCH='liveusb-creator_completed'
47 AFTER_IMPORT='./setup.py build && cd po && for po in *.po ; do msgmerge --update "$po" tails-installer.pot ; done'
48 elif [ -f 'po/tails-persistence-setup.pot' ]; then
49 BRANCH='tails-persistence-setup_completed'
50 AFTER_IMPORT='make -C po pot && make -C po update-po'
51 elif [ -f 'po/whisperback.pot' ]; then
52 BRANCH='whisperback_completed'
53 AFTER_IMPORT=''
54 else
55 echo "Current folder is not a project known to this script!"
56 exit 1
59 # Clone or update the translation repository
60 if [ -d "$TOR_TRANSLATION_DIR" ]; then
61 eval "$GIT_IN_TOR_TRANSLATION_DIR fetch origin"
62 else
63 mkdir -p "$SCRIPT_DIR/tmp"
64 git clone "$TOR_TRANSLATION_REMOTE" "$TOR_TRANSLATION_DIR"
67 # Checkout the correct branch
68 eval "$GIT_IN_TOR_TRANSLATION_DIR checkout \"$BRANCH\""
69 eval "$GIT_IN_TOR_TRANSLATION_DIR reset --hard \"origin/$BRANCH\""
71 # For each completely translated language, merge it,
72 # unless it is translated outside Transifex
73 if [ "$LANG_DOT_PO_LAYOUT" = yes ] ; then
74 find "$TOR_TRANSLATION_DIR" -name '*.po' | while read po_file; do
75 lang=$(basename "$po_file" | tr - _ | sed 's/\.po$//')
77 if ! lang_is_excluded "$lang"; then
78 echo "Importing translation for $lang..."
79 cp "$po_file" "$TAILS_PO_DIR"
81 done
82 else
83 find "$TOR_TRANSLATION_DIR" -name '*.pot' | while read po_file; do
84 lang=$(basename $(dirname "$po_file" | tr - _ | sed 's/\.pot$//'))
86 if ! lang_is_excluded "$lang"; then
87 echo "Importing translation for $lang..."
88 cp "$po_file" "$TAILS_PO_DIR/${lang}.po"
90 done
93 # Update PO files
94 if [ -n "${AFTER_IMPORT:-}" ]; then
95 eval "$AFTER_IMPORT"