mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #1391 from deltachat/1209_switching_to_default_language
Switching to "Default" Language behaves as it should be
This commit is contained in:
@@ -5,15 +5,22 @@ import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class DynamicLanguage {
|
||||
|
||||
private static final String TAG = DynamicLanguage.class.getSimpleName();
|
||||
|
||||
private static final String DEFAULT = "zz";
|
||||
|
||||
private Locale currentLocale;
|
||||
@@ -65,11 +72,23 @@ public class DynamicLanguage {
|
||||
return activity.getResources().getConfiguration().locale;
|
||||
}
|
||||
|
||||
// Beware that Locale.getDefault() returns the locale the App was STARTED in, not the locale of the system.
|
||||
// It just happens to be the same for the majority of use cases.
|
||||
private static Locale getDefaultLocale() {
|
||||
Locale locale = null;
|
||||
try {
|
||||
locale = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0);
|
||||
} catch(Exception e) {
|
||||
Log.e(TAG, "could not determine the system locale.", e);
|
||||
}
|
||||
return locale != null ? locale : Locale.getDefault();
|
||||
}
|
||||
|
||||
public static Locale getSelectedLocale(Context context) {
|
||||
String language[] = TextUtils.split(Prefs.getLanguage(context), "_");
|
||||
|
||||
if (language[0].equals(DEFAULT)) {
|
||||
return Locale.getDefault();
|
||||
return getDefaultLocale();
|
||||
} else if (language.length == 2) {
|
||||
return new Locale(language[0], language[1]);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user