import-translations 2.97 KB
Newer Older
1 2 3
#!/bin/sh

set -e
4
set -u
5

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 13
	--work-tree=\"$TOR_TRANSLATION_DIR\" \
	--git-dir=\"$TOR_TRANSLATION_DIR/.git\""
14

15
### External libraries
16
. "$SCRIPT_DIR/config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh"
17

18 19 20 21
lang_is_excluded () {
	local lang="$1"
	echo -n "$EXCLUDE_LANGS" | grep -qs -w "$lang"
}
22

23 24 25
# Defaults
LANG_DOT_PO_LAYOUT=yes

26 27 28 29 30 31
# Detect which project is in current folder,
# and set parameters accordingly
if [ -f 'po/tails.pot' ]; then
	BRANCH='tails-misc_completed'
	AFTER_IMPORT='intltool_update_po $(po_languages)'
elif [ -f 'po/tails-greeter.pot' ]; then
32
	BRANCH='tails-greeter-2_completed'
33
	AFTER_IMPORT='./setup.py build_i18n'
34 35 36
elif [ -f 'po/tails-iuk.pot' ]; then
	BRANCH='tails-iuk_completed'
	AFTER_IMPORT='make -C po pot && make -C po update-po'
37
elif [ -f 'po/onioncircuits.pot' ]; then
38 39
	LANG_DOT_PO_LAYOUT=no
	POTFILE=onioncircuits.pot
40 41
	BRANCH='tails-onioncircuits_completed'
	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 49 50 51 52 53 54 55 56 57 58
elif [ -f 'po/tails-persistence-setup.pot' ]; then
	BRANCH='tails-persistence-setup_completed'
	AFTER_IMPORT='make -C po pot && make -C po update-po'
elif [ -f 'po/whisperback.pot' ]; then
	BRANCH='whisperback_completed'
	AFTER_IMPORT=''
else
	echo "Current folder is not a project known to this script!"
	exit 1
fi

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 64
	mkdir -p "$SCRIPT_DIR/tmp"
	git clone "$TOR_TRANSLATION_REMOTE" "$TOR_TRANSLATION_DIR"
65 66 67
fi

# Checkout the correct branch
68 69
eval "$GIT_IN_TOR_TRANSLATION_DIR checkout \"$BRANCH\""
eval "$GIT_IN_TOR_TRANSLATION_DIR reset --hard \"origin/$BRANCH\""
70 71 72

# For each completely translated language, merge it,
# unless it is translated outside Transifex
73 74 75 76 77 78 79 80 81 82 83 84
if [ "$LANG_DOT_PO_LAYOUT" = yes ] ; then
	find "$TOR_TRANSLATION_DIR" -name '*.po' | while read po_file; do
		lang=$(basename "$po_file" | tr - _ | sed 's/\.po$//')

		if ! lang_is_excluded "$lang"; then
			echo "Importing translation for $lang..."
			cp "$po_file" "$TAILS_PO_DIR"
		fi
	done
else
	find "$TOR_TRANSLATION_DIR" -name '*.pot' | while read po_file; do
		lang=$(basename $(dirname "$po_file" | tr - _ | sed 's/\.pot$//'))
85

86 87 88 89 90 91
		if ! lang_is_excluded "$lang"; then
			echo "Importing translation for $lang..."
			cp "$po_file" "$TAILS_PO_DIR/${lang}.po"
		fi
	done
fi
92 93

# Update PO files
94
if [ -n "${AFTER_IMPORT:-}" ]; then
95 96
	eval "$AFTER_IMPORT"
fi