Calendar: remove past event
[tails/test.git] / import-translations
blobce2b9ce685529a4eeacb5aa33fdb74ba0ef67d73
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://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_release'
30 AFTER_IMPORT='intltool_update_po $(po_languages)'
31 elif [ -f 'po/onioncircuits.pot' ]; then
32 LANG_DOT_PO_LAYOUT=no
33 POTFILE=onioncircuits.pot
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 elif [ -f 'po/whisperback.pot' ]; then
37 BRANCH='whisperback_release'
38 AFTER_IMPORT=''
39 else
40 echo "Current folder is not a project known to this script!"
41 exit 1
44 # Clone or update the translation repository
45 if [ -d "$TOR_TRANSLATION_DIR" ]; then
46 eval "$GIT_IN_TOR_TRANSLATION_DIR fetch origin"
47 else
48 mkdir -p "$SCRIPT_DIR/tmp"
49 git clone "$TOR_TRANSLATION_REMOTE" "$TOR_TRANSLATION_DIR"
52 # Checkout the correct branch
53 eval "$GIT_IN_TOR_TRANSLATION_DIR checkout \"$BRANCH\""
54 eval "$GIT_IN_TOR_TRANSLATION_DIR reset --hard \"origin/$BRANCH\""
56 # Ensure we only keep PO files that are still present in the Transifex
57 # branch we import from.
58 find "$TAILS_PO_DIR" -name '*.po' -delete
60 # For each completely translated language, merge it,
61 # unless it is translated outside Transifex
62 if [ "$LANG_DOT_PO_LAYOUT" = yes ] ; then
63 find "$TOR_TRANSLATION_DIR" -name '*.po' | sort | while read po_file; do
64 lang=$(basename "$po_file" | tr - _ | sed 's/\.po$//')
66 ! lang_is_excluded "$lang" || continue
67 if [ "$(cat "$po_file" | count_translated_strings)" -lt 1 ]; then
68 echo "Skipping $lang, that has no translated strings."
69 continue
71 echo "Importing translation for $lang..."
72 cp "$po_file" "$TAILS_PO_DIR"
73 done
74 else
75 find "$TOR_TRANSLATION_DIR" -name '*.pot' | sort | while read po_file; do
76 lang=$(basename $(dirname "$po_file" | tr - _ | sed 's/\.pot$//'))
78 ! lang_is_excluded "$lang" || continue
79 if [ "$(cat "$po_file" | count_translated_strings)" -lt 1 ]; then
80 echo "Skipping $lang, that has no translated strings."
81 continue
83 echo "Importing translation for $lang..."
84 cp "$po_file" "$TAILS_PO_DIR/${lang}.po"
85 done
88 # Update PO files
89 if [ -n "${AFTER_IMPORT:-}" ]; then
90 eval "$AFTER_IMPORT"