Skip to content
Snippets Groups Projects
Commit 432f74f5 authored by Julian Dehm's avatar Julian Dehm Committed by jd
Browse files

Set Locale only once

parent a9c199c1
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ public class Localizer { ...@@ -32,6 +32,7 @@ public class Localizer {
this.systemLocale = systemLocale; this.systemLocale = systemLocale;
if (userLocale == null) locale = systemLocale; if (userLocale == null) locale = systemLocale;
else locale = userLocale; else locale = userLocale;
setLocaleAndSystemConfiguration();
} }
// Instantiate the Localizer. // Instantiate the Localizer.
...@@ -72,18 +73,11 @@ public class Localizer { ...@@ -72,18 +73,11 @@ public class Localizer {
public Context setLocale(Context context) { public Context setLocale(Context context) {
Resources res = context.getResources(); Resources res = context.getResources();
Configuration conf = res.getConfiguration(); Configuration conf = res.getConfiguration();
Locale.setDefault(locale);
updateConfiguration(conf, locale); updateConfiguration(conf, locale);
Configuration systemConfiguration =
Resources.getSystem().getConfiguration();
updateConfiguration(systemConfiguration, locale);
// DateUtils uses the system resources, so we need to update them too.
// Apparently updateConfiguration is not deprecated here but is below.
Resources.getSystem().updateConfiguration(systemConfiguration,
Resources.getSystem().getDisplayMetrics());
if (SDK_INT >= 17) if (SDK_INT >= 17)
return context.createConfigurationContext(conf); return context.createConfigurationContext(conf);
//noinspection deprecation //noinspection deprecation
// Use the old API on < 17
res.updateConfiguration(conf, res.getDisplayMetrics()); res.updateConfiguration(conf, res.getDisplayMetrics());
return context; return context;
} }
...@@ -94,4 +88,14 @@ public class Localizer { ...@@ -94,4 +88,14 @@ public class Localizer {
} else } else
conf.locale = locale; conf.locale = locale;
} }
private void setLocaleAndSystemConfiguration() {
Locale.setDefault(locale);
Configuration systemConfiguration =
Resources.getSystem().getConfiguration();
updateConfiguration(systemConfiguration, locale);
// DateUtils uses the system resources, so we need to update them too.
Resources.getSystem().updateConfiguration(systemConfiguration,
Resources.getSystem().getDisplayMetrics());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment