Upgrade Tor Browser to 14.0a6 (refs: tails#20448)
[tails.git] / config / chroot_local-hooks / 11-localize_browser
blob3870686501c4132d0c8947768b9b08e1c15d7d66
1 #!/bin/sh
3 set -e
5 echo "Localize each supported browser locale"
7 # Import the TBB_INSTALL variable and
8 # supported_tor_browser_locales(), locale_is_supported_by_tor_browser(), set_mozilla_pref()
9 . /usr/local/lib/tails-shell-library/tor-browser.sh
11 # Import language_code_from_locale()
12 . /usr/local/lib/tails-shell-library/localization.sh
14 # Import TAILS_WIKI_SUPPORTED_LANGUAGES
15 . /etc/tails/environment
17 BROWSER_LOCALIZATION_DIR="/usr/share/tails/browser-localization"
18 DESCRIPTIONS_FILE="${BROWSER_LOCALIZATION_DIR}/descriptions"
19 LOCALE_PROFILES_DIR="/etc/tor-browser/locale-profiles/"
21 # Sanity check that each supported Tor Browser locale has a
22 # description for how to localize it further.
23 BROKEN_LOCALES=""
24 for LOCALE in $(supported_tor_browser_locales); do
25 if ! grep -q "^${LOCALE}:" "${DESCRIPTIONS_FILE}" 2>/dev/null; then
26 BROKEN_LOCALES="${BROKEN_LOCALES} ${LOCALE}"
28 done
29 if [ -n "${BROKEN_LOCALES}" ]; then
30 echo "The following supported browser locales lack descriptions in ${DESCRIPTIONS_FILE}:${BROKEN_LOCALES}" >&2
31 exit 1
34 # This very long while-loop is fed the DESCRIPTIONS_FILE (IO
35 # redirection at the bottom), which describes how we will localize
36 # each supported Tor Browser locale. The format is:
37 # MOZILLA_LOCALE:LOCATION
38 # Note that we're forced to pick some representative location for the
39 # language-only locales, like Egypt (EG) for Arabic (ar).
40 while IFS=: read -r MOZILLA_LOCALE LOCATION; do
41 if [ -z "${MOZILLA_LOCALE}" ] || [ -z "${LOCATION}" ]; then
42 echo "Something is wrong with ${DESCRIPTIONS_FILE}" >&2
43 echo "Description: ${MOZILLA_LOCALE}:${LOCATION}" >&2
44 exit 1
47 if ! locale_is_supported_by_tor_browser "$MOZILLA_LOCALE"; then
48 echo "- Skipping localization of ${MOZILLA_LOCALE} for browsers:" \
49 "not supported by Tor Browser"
50 continue
53 echo "- Localizing ${MOZILLA_LOCALE} for browsers..."
55 # In some places we'll need the locale in xx_YY format instead of
56 # Mozilla's xx-YY fromat. Over all, the greatest difficulty in
57 # this whole script is really to know when to use the correct
58 # locale format, since Firefox isn't very consistent in it.
59 if echo "${MOZILLA_LOCALE}" | grep -q '-'; then
60 NORMAL_LOCALE="$(echo "${MOZILLA_LOCALE}" | tr - _)"
61 else
62 NORMAL_LOCALE="${MOZILLA_LOCALE}_${LOCATION}"
64 LANG_CODE="$(language_code_from_locale "${NORMAL_LOCALE}")"
66 # Our Tor Browser wrapper script will make use of the following
67 # per-locale profiles to set localized defaults for various prefs.
68 mkdir -p "${LOCALE_PROFILES_DIR}"
69 LOCALE_PROFILE_FILE="${LOCALE_PROFILES_DIR}/${MOZILLA_LOCALE}.js"
70 TBB_DICTIONARIES_DIR="${TBB_INSTALL}/dictionaries"
71 unset SPELLCHECKER_LOCALE
72 for LOCALE in "${NORMAL_LOCALE}" "${LANG_CODE}"; do
73 if [ -e "${TBB_DICTIONARIES_DIR}/${LOCALE}.dic" ]; then
74 SPELLCHECKER_LOCALE="${LOCALE}"
76 done
77 if [ -z "${SPELLCHECKER_LOCALE}" ]; then
78 SPELLCHECKER_LOCALE="en_US"
80 set_mozilla_pref "${LOCALE_PROFILE_FILE}" \
81 "spellchecker.dictionary" \
82 "\"${SPELLCHECKER_LOCALE}\"" \
83 "user_pref"
84 HOMEPAGE="https://tails.net/home/"
85 . /etc/os-release # get $TAILS_CHANNEL and $TAILS_DISTRIBUTION
86 if [ "${TAILS_DISTRIBUTION}" = UNRELEASED ] \
87 || [ "${TAILS_CHANNEL:-stable}" != stable ]; then
88 HOMEPAGE="${HOMEPAGE}testing/"
90 if echo "${TAILS_WIKI_SUPPORTED_LANGUAGES}" | grep -qw "${LANG_CODE}"; then
91 HOMEPAGE="${HOMEPAGE}index.${LANG_CODE}.html"
93 set_mozilla_pref "${LOCALE_PROFILE_FILE}" \
94 "browser.startup.homepage" "\"${HOMEPAGE}\"" "user_pref"
95 set_mozilla_pref "${LOCALE_PROFILE_FILE}" \
96 "browser.startup.homepage.new_identity" "\"${HOMEPAGE}\"" \
97 "user_pref"
98 done < "${DESCRIPTIONS_FILE}"
100 # This directory is not needed after build time.
101 rm -r "${BROWSER_LOCALIZATION_DIR}"
103 # All generated and modified files must remain world-readable.
104 chmod -R a+rX "${LOCALE_PROFILES_DIR}"