Bug 1045053 - Part 0: add descriptive comments for locale handling. r=me
--- a/mobile/android/base/BrowserLocaleManager.java
+++ b/mobile/android/base/BrowserLocaleManager.java
@@ -325,16 +325,19 @@ public class BrowserLocaleManager implem
config.locale = locale;
res.updateConfiguration(config, null);
}
private SharedPreferences getSharedPreferences(Context context) {
return GeckoSharedPrefs.forApp(context);
}
+ /**
+ * @return the persisted locale in Java format: "en_US".
+ */
private String getPersistedLocale(Context context) {
final SharedPreferences settings = getSharedPreferences(context);
final String locale = settings.getString(PREF_LOCALE, "");
if ("".equals(locale)) {
return null;
}
return locale;
@@ -359,29 +362,35 @@ public class BrowserLocaleManager implem
}
/**
* Updates the Java locale and the Android configuration.
*
* Returns the persisted locale if it differed.
*
* Does not notify Gecko.
+ *
+ * @param localeCode a locale string in Java format: "en_US".
+ * @return if it differed, a locale string in Java format: "en_US".
*/
private String updateLocale(Context context, String localeCode) {
// Fast path.
final Locale defaultLocale = Locale.getDefault();
if (defaultLocale.toString().equals(localeCode)) {
return null;
}
final Locale locale = parseLocaleCode(localeCode);
return updateLocale(context, locale);
}
+ /**
+ * @return the Java locale string: e.g., "en_US".
+ */
private String updateLocale(Context context, final Locale locale) {
// Fast path.
if (Locale.getDefault().equals(locale)) {
return null;
}
Locale.setDefault(locale);
currentLocale = locale;
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1319,16 +1319,17 @@ public abstract class GeckoApp
editor.apply();
// The lifecycle of mHealthRecorder is "shortly after onCreate"
// through "onDestroy" -- essentially the same as the lifecycle
// of the activity itself.
final String profilePath = getProfile().getDir().getAbsolutePath();
final EventDispatcher dispatcher = EventDispatcher.getInstance();
+ // Both of these are Java-format locale strings: "en_US", not "en-US".
final String osLocale = Locale.getDefault().toString();
String appLocale = localeManager.getAndApplyPersistedLocale(GeckoApp.this);
Log.d(LOGTAG, "OS locale is " + osLocale + ", app locale is " + appLocale);
if (appLocale == null) {
appLocale = osLocale;
}