import-translations.sh 2.68 KB
Newer Older
1
#!/bin/bash -e
2
3
4

# This var comes from the TBB locale list.
# XXX: Find some way to keep this, tor-launcher, and Tor Browser in sync
5
BUNDLE_LOCALES="ar ca cs da de el es fa fr ga he hu id is it ja ka ko nb nl pl pt-BR ru sv tr vi zh-CN zh-TW"
6

7
8
9
10
11
# XXX: Basque (eu) by request in #10687.
# This is not used for official builds, but should remain 
# so Basque XPIs can be build independently. We can do
# this for other languages too, if anyone requests this
# and translations are available.
12
13
14
# XXX: Adding bn-BD as well as we don't ship that locale ourselves due to bug
# 26498. Others might want to fix, build, and use it, though.
BUNDLE_LOCALES="$BUNDLE_LOCALES eu bn-BD"
15

16
17
18
19
20
LOCALE_DIR=../src/chrome/locale

# FILEMAP is an array of "localeFile:translationBranch" strings.
FILEMAP=( "aboutDialog.dtd:torbutton-aboutdialogdtd"
          "aboutTor.dtd:abouttor-homepage"
21
          "aboutTBUpdate.dtd:torbutton-abouttbupdatedtd"
22
23
          "brand.dtd:torbutton-branddtd"
          "brand.properties:torbutton-brandproperties"
24
          "browserOnboarding.properties:torbutton-browseronboardingproperties"
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
          "torbutton.dtd:torbutton-torbuttondtd"
          "torbutton.properties:torbutton-torbuttonproperties"
         )

# Verify that the FILEMAP contains an entry for each Torbutton file.
FILES_ARE_MISSING=0
for DEST_PATH in $LOCALE_DIR/en/*.dtd $LOCALE_DIR/en/*.properties;
do
  IS_FILE_IN_MAP=0
  DEST_FILE=${DEST_PATH##*/}
  for KEYVAL in "${FILEMAP[@]}";
  do
    FILE="${KEYVAL%%:*}"
    if [ $FILE = $DEST_FILE ];
    then
      IS_FILE_IN_MAP=1
      break;
    fi
  done

  if [ $IS_FILE_IN_MAP -eq 0 ];
  then
    echo "Please add $DEST_FILE to FILEMAP." 1>&2
    FILES_ARE_MISSING=1
  fi
done

if [ $FILES_ARE_MISSING -ne 0 ];
then
  exit 1
fi

# Clone or update our translation repo.
58
59
60
61
62
63
64
65
66
if [ -d translation ];
then
  cd translation
  git fetch origin
  cd ..
else
  git clone https://git.torproject.org/translation.git
fi

67
68
# Update each translated file for each locale.
echo "Locales: $BUNDLE_LOCALES"
69
cd translation
70
for KEYVAL in "${FILEMAP[@]}"; do
71
  DEST_FILE="${KEYVAL%%:*}"
72
  BRANCH="${KEYVAL##*:}"
73
  echo "Updating ${DEST_FILE}..."
74
75
76
77
78
79
  git checkout -q "$BRANCH"
  git merge -q origin/"$BRANCH"
  for i in $BUNDLE_LOCALES;
  do
    UL="`echo $i|tr - _`"
    mkdir -p ../$LOCALE_DIR/$i/
80
81
82
83
84
85
# Some file names are lowercase in Transifex.
    if [ -f $UL/"$DEST_FILE" ]; then
      SRCFILE="$DEST_FILE"
    else
      SRCFILE="`echo $DEST_FILE | tr '[:upper:]' '[:lower:]'`"
    fi
86
87
88
# Use sed to work around a Transifex "double entity" issue.
    sed -e 's/\&brandShortName;/\&brandShortName;/g'			\
        -e 's/\&vendorShortName;/\&vendorShortName;/g'			\
89
        $UL/"$SRCFILE" > ../$LOCALE_DIR/$i/"$DEST_FILE"
90
  done
91
done