mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Detect if system language changed
This commit is contained in:
@@ -21,8 +21,9 @@ public class Localizer {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private static Localizer INSTANCE;
|
private static Localizer INSTANCE;
|
||||||
private final Locale systemLocale;
|
private final Locale systemLocale;
|
||||||
|
// Locking: this
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile Locale locale;
|
private Locale locale;
|
||||||
|
|
||||||
private Localizer(SharedPreferences sharedPreferences) {
|
private Localizer(SharedPreferences sharedPreferences) {
|
||||||
systemLocale = Locale.getDefault();
|
systemLocale = Locale.getDefault();
|
||||||
@@ -61,9 +62,8 @@ public class Localizer {
|
|||||||
return new Locale(tag);
|
return new Locale(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the localized version of context
|
||||||
public Context setLocale(Context context) {
|
public Context setLocale(Context context) {
|
||||||
if (locale == null)
|
|
||||||
return context;
|
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
Configuration conf = res.getConfiguration();
|
Configuration conf = res.getConfiguration();
|
||||||
Locale currentLocale;
|
Locale currentLocale;
|
||||||
@@ -71,6 +71,14 @@ public class Localizer {
|
|||||||
currentLocale = conf.getLocales().get(0);
|
currentLocale = conf.getLocales().get(0);
|
||||||
} else
|
} else
|
||||||
currentLocale = conf.locale;
|
currentLocale = conf.locale;
|
||||||
|
synchronized (this) {
|
||||||
|
if (locale == null) {
|
||||||
|
// Detect if the user changed the system language
|
||||||
|
if (systemLocale.equals(currentLocale))
|
||||||
|
return context;
|
||||||
|
locale = systemLocale;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (locale.equals(currentLocale))
|
if (locale.equals(currentLocale))
|
||||||
return context;
|
return context;
|
||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
|
|||||||
Reference in New Issue
Block a user