I recently landed the first steps towards a new way of choosing your language and locale in Firefox for Android. This is of interest as a feature, of course, but it also means some new capabilities and obligations for Fennec front-end developers, so I thought I’d put pen to paper.
Right now, Firefox on Android — like most Android apps — displays its UI and web content in the locale you’ve selected in Android’s settings. In short: if your phone is set to use
es_ES (Español [España]), then so is Firefox… and without digging around in
about:config, you will also get web content in Spanish by default.
That’s not ideal for a number of reasons. Firstly, carriers tend to restrict the locales that you can select, sometimes to as few as four. If you only speak (or prefer to speak) a language that your carrier doesn’t let you choose, that’s a bad scene. Secondly, the Mozilla community extends beyond the locales that Android itself supports. The only way to address these two issues is to decouple Firefox’s locale selection from Android.
The work that just landed to do so is Bug 936756, upon which we will build two selection UIs — Bug 917480 for the app locale, and Bug 881510 for choosing which locales you wish to use when browsing the web.
What does this mean for users?
Quite simply: once a UI has been layered on top, you’ll be able to switch between each of Firefox for Android’s supported locales without restarting your browser, and maintain that selection independently of the Android OS locale. If you’re happy continuing to use Android’s settings to make that choice, that will continue to work, too.
How does it work?
It works by persisting a selected language in
SharedPreferences, manipulating both the Gecko locale prefs and the Android/Java
Resources frameworks to impose that language. To do so we hook into
onConfigurationChanged events. For more details, read the bug!
(This is also a small step toward supporting l20n on Android. More on that at a later date.)
What does this mean for developers?
Historically, there’s been a sizable rift between day-to-day development and the final localized builds that users see. We front-end developers build
en_US-only builds for testing, while our localization communities work with Aurora, 6-12 weeks later. Partly that’s because locale switching itself is cumbersome (watch Android restart everything under the sun!). Partly it’s because building a multi-locale APK has been difficult.
Unfortunately, that results in a failure to detect even obvious l10n issues during development. Take, for example, Bug 933272. Between Firefox 23 and 28, we displayed all plugin-related text in English, regardless of your selected locale. This is the kind of thing that’s easy to find by testing a local build in a non-English locale.
With switchable locales, two things are true:
- It’s now easy to switch locales, so you can (and should!) routinely test with multiple locales, just as we test with tablets and phones, with screens rotated, etc.
- You must test locale switching if you’re working on front-end code that includes strings, so that your new or changed feature doesn’t break locale switching!
I hope that’s a fair trade. Next post: how to build a multi-locale APK, without too much disruption to your existing toolchain.