Bug 1045053 - Part 1: set intl.accept_languages from Android OS/app locale. r=bnicholson

This commit is contained in:
Richard Newman
2014-10-01 18:09:42 -07:00
parent e14cdad32e
commit d2b6d51d0d
3 changed files with 146 additions and 11 deletions

View File

@@ -248,6 +248,37 @@ public class BrowserLocaleManager implements LocaleManager {
return changed;
}
/**
* Gecko needs to know the OS locale to compute a useful Accept-Language
* header. If it changed since last time, send a message to Gecko and
* persist the new value. If unchanged, returns immediately.
*
* @param prefs the SharedPreferences instance to use. Cannot be null.
* @param osLocale the new locale instance. Safe if null.
*/
public static void storeAndNotifyOSLocale(final SharedPreferences prefs,
final Locale osLocale) {
if (osLocale == null) {
return;
}
final String lastOSLocale = prefs.getString("osLocale", null);
final String osLocaleString = osLocale.toString();
if (osLocaleString.equals(lastOSLocale)) {
return;
}
// Store the Java-native form.
prefs.edit().putString("osLocale", osLocaleString).apply();
// The value we send to Gecko should be a language tag, not
// a Java locale string.
final String osLanguageTag = BrowserLocaleManager.getLanguageTag(osLocale);
final GeckoEvent localeOSEvent = GeckoEvent.createBroadcastEvent("Locale:OS", osLanguageTag);
GeckoAppShell.sendEventToGecko(localeOSEvent);
}
@Override
public String getAndApplyPersistedLocale(Context context) {
initialize(context);