Release preparations for 1.9.5.2
[torbutton.git] / trans_tools / import-translations.sh
blobcfaa05c5747cd0d0cce2ac4200326b7d1ec9502a
1 #!/bin/bash -e
3 # This var comes from the TBB locale list.
4 # XXX: Find some way to keep this, tor-launcher, and Tor Browser in sync
5 BUNDLE_LOCALES="ar de es fa fr it ko nl pl pt ru tr vi zh-CN"
7 # XXX: Basque (eu) by request in #10687.
8 # This is not used for official builds, but should remain
9 # so Basque XPIs can be build independently. We can do
10 # this for other languages too, if anyone requests this
11 # and translations are available.
12 BUNDLE_LOCALES="$BUNDLE_LOCALES eu ja sv"
14 LOCALE_DIR=../src/chrome/locale
16 # FILEMAP is an array of "localeFile:translationBranch" strings.
17 FILEMAP=( "aboutDialog.dtd:torbutton-aboutdialogdtd"
18 "aboutTor.dtd:abouttor-homepage"
19 "aboutTor.properties:torbutton-abouttorproperties"
20 "aboutTBUpdate.dtd:torbutton-abouttbupdatedtd"
21 "brand.dtd:torbutton-branddtd"
22 "brand.properties:torbutton-brandproperties"
23 "torbutton.dtd:torbutton-torbuttondtd"
24 "torbutton.properties:torbutton-torbuttonproperties"
27 # Verify that the FILEMAP contains an entry for each Torbutton file.
28 FILES_ARE_MISSING=0
29 for DEST_PATH in $LOCALE_DIR/en/*.dtd $LOCALE_DIR/en/*.properties;
31 IS_FILE_IN_MAP=0
32 DEST_FILE=${DEST_PATH##*/}
33 for KEYVAL in "${FILEMAP[@]}";
35 FILE="${KEYVAL%%:*}"
36 if [ $FILE = $DEST_FILE ];
37 then
38 IS_FILE_IN_MAP=1
39 break;
41 done
43 if [ $IS_FILE_IN_MAP -eq 0 ];
44 then
45 echo "Please add $DEST_FILE to FILEMAP." 1>&2
46 FILES_ARE_MISSING=1
48 done
50 if [ $FILES_ARE_MISSING -ne 0 ];
51 then
52 exit 1
55 # Clone or update our translation repo.
56 if [ -d translation ];
57 then
58 cd translation
59 git fetch origin
60 cd ..
61 else
62 git clone https://git.torproject.org/translation.git
65 # Update each translated file for each locale.
66 echo "Locales: $BUNDLE_LOCALES"
67 cd translation
68 for KEYVAL in "${FILEMAP[@]}"; do
69 DEST_FILE="${KEYVAL%%:*}"
70 BRANCH="${KEYVAL##*:}"
71 echo "Updating ${DEST_FILE}..."
72 git checkout -q "$BRANCH"
73 git merge -q origin/"$BRANCH"
74 for i in $BUNDLE_LOCALES;
76 UL="`echo $i|tr - _`"
77 mkdir -p ../$LOCALE_DIR/$i/
78 # Some file names are lowercase in Transifex.
79 if [ -f $UL/"$DEST_FILE" ]; then
80 SRCFILE="$DEST_FILE"
81 else
82 SRCFILE="`echo $DEST_FILE | tr '[:upper:]' '[:lower:]'`"
84 # Use sed to work around a Transifex "double entity" issue.
85 sed -e 's/\&brandShortName;/\&brandShortName;/g' \
86 -e 's/\&vendorShortName;/\&vendorShortName;/g' \
87 $UL/"$SRCFILE" > ../$LOCALE_DIR/$i/"$DEST_FILE"
88 done
89 done