mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Set Locale only once
This commit is contained in:
@@ -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 {
|
|||||||
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 {
|
|||||||
} 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user