Building and testing multi-locale Firefox for Android

This is a follow-up to my earlier post on locale switching.

By default, local Firefox builds are English-only. Including other locales involves merging in content from the l10n repositories. Building an APK that includes other locales, then, means performing the following steps. You only have to do them once.

In short:

  1. Get checkouts of the appropriate l10n repositories for the locales you care about.
  2. Put some incantations in your .mozconfig.
  3. Install compare-locales. (See Bug 940103 to remove this step.)

Then, each time you build, run a small script between ./mach build and ./mach package.

Getting checkouts for Fennec’s supported locales

mkdir -P $L10NBASEDIR
pushd $L10NBASEDIR
while read line; do hg clone "$line"; done < $LOCALES

Augmenting your .mozconfig

Add the following lines:

# Make this match your checkouts.
mk_add_options 'export MOZ_CHROME_MULTILOCALE=en-US cs da de es-ES fi fr ja ko it nb-NO nl pl pt-BR pt-PT ru sk sv-SE zh-CN zh-TW'

# Use absolute paths.
mk_add_options 'export L10NBASEDIR=/Users/rnewman/moz/hg/l10n'
ac_add_options --with-l10n-base=/Users/rnewman/moz/hg/l10n

Install compare-locales

pip install compare-locales

Build and package

This step should be improved when we fix Bug 934196. Personally, I’ve just dumped the extra stuff in a script and moved on with my life.

./mach build && \
pushd objdir-droid/mobile/android/locales && \
for loc in $(cat ../../../../mobile/android/locales/maemo-locales); do LOCALE_MERGEDIR=$PWD/merge-$loc make merge-$loc LOCALE_MERGEDIR=$PWD/merge-$loc; make LOCALE_MERGEDIR=$PWD/merge-$loc chrome-$loc LOCALE_MERGEDIR=$PWD/merge-$loc; done && \
popd && \
./mach package

Note that the new stuff is in bold.

Once this completes (assuming no errors), you’ll have an APK that contains multiple locales. Install it on your device!

Updating your l10n checkouts

Every now and then, do something like this:

for loc in $(cat $MOZILLA_CENTRAL/mobile/android/locales/maemo-locales); do \
  pushd $loc && hg pull && hg up -C && popd; done

Testing locale switching

Until we ship a UI for this, you’ll need to use a trivial testing add-on. That add-on puts menu items in the Tools menu; pick one, and it’ll switch your app locale.

The code for this add-on is on GitHub. You can also install the XPI directly. Then you’ll see the Tools menu full of locales, like this:

Switching to es-ES at runtime

Try it out… and whenever you make a change to UI code, use it to make sure you haven’t broken anything!