summaryrefslogtreecommitdiffstats
path: root/import-translations
blob: 79ef56dda695a0712bcc1b24373b5cd9fb09d0b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh

set -e
set -u

EXCLUDE_LANGS=''
TAILS_PO_DIR='po'
SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
TOR_TRANSLATION_REMOTE='https://git.torproject.org/translation.git'
TOR_TRANSLATION_DIR="$SCRIPT_DIR/tmp/tor-translation"
GIT_IN_TOR_TRANSLATION_DIR="git \
	--work-tree=\"$TOR_TRANSLATION_DIR\" \
	--git-dir=\"$TOR_TRANSLATION_DIR/.git\""

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

lang_is_excluded () {
	local lang="$1"
	echo -n "$EXCLUDE_LANGS" | grep -qs -w "$lang"
}

# Defaults
LANG_DOT_PO_LAYOUT=yes

# Detect which project is in current folder,
# and set parameters accordingly
if [ -f 'po/tails.pot' ]; then
	BRANCH='tails-misc_release'
	AFTER_IMPORT='intltool_update_po $(po_languages)'
elif [ -f 'po/tails-greeter.pot' ]; then
	BRANCH='tails-greeter-2_completed'
	AFTER_IMPORT='./setup.py build_i18n'
elif [ -f 'po/tails-iuk.pot' ]; then
	BRANCH='tails-iuk_completed'
	AFTER_IMPORT='make -C po pot && make -C po update-po'
elif [ -f 'po/onioncircuits.pot' ]; then
	LANG_DOT_PO_LAYOUT=no
	POTFILE=onioncircuits.pot
	BRANCH='tails-onioncircuits_completed'
	AFTER_IMPORT='./setup.py build_i18n && ( cd po && for po in *.po ; do msgmerge --update "$po" onioncircuits.pot ; done )'
elif [ -f 'po/tails-perl5lib.pot' ]; then
	BRANCH='tails-perl5lib_completed'
	AFTER_IMPORT='make -C po pot && make -C po update-po'
elif [ -f 'po/tails-installer.pot' ]; then
	BRANCH='liveusb-creator_completed'
	AFTER_IMPORT='./setup.py build && ( cd po && for po in *.po ; do msgmerge --update "$po" tails-installer.pot ; done )'
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

# Clone or update the translation repository
if [ -d "$TOR_TRANSLATION_DIR" ]; then
	eval "$GIT_IN_TOR_TRANSLATION_DIR fetch origin"
else
	mkdir -p "$SCRIPT_DIR/tmp"
	git clone "$TOR_TRANSLATION_REMOTE" "$TOR_TRANSLATION_DIR"
fi

# Checkout the correct branch
eval "$GIT_IN_TOR_TRANSLATION_DIR checkout \"$BRANCH\""
eval "$GIT_IN_TOR_TRANSLATION_DIR reset --hard \"origin/$BRANCH\""

# Ensure we only keep PO files that are still present in the Transifex
# branch we import from.
find "$TAILS_PO_DIR" -name '*.po' -delete

# For each completely translated language, merge it,
# unless it is translated outside Transifex
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$//')

		! lang_is_excluded "$lang" || continue
		if [ "$(cat "$po_file" | count_translated_strings)" -lt 1 ]; then
			echo "Skipping $lang, that has no translated strings."
			continue
		fi
		echo "Importing translation for $lang..."
		cp "$po_file" "$TAILS_PO_DIR"
	done
else
	find "$TOR_TRANSLATION_DIR" -name '*.pot' | while read po_file; do
		lang=$(basename $(dirname "$po_file" | tr - _ | sed 's/\.pot$//'))

		! lang_is_excluded "$lang" || continue
		if [ "$(cat "$po_file" | count_translated_strings)" -lt 1 ]; then
			echo "Skipping $lang, that has no translated strings."
			continue
		fi
		echo "Importing translation for $lang..."
		cp "$po_file" "$TAILS_PO_DIR/${lang}.po"
	done
fi

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