diff --git a/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt b/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt index 4d0e071ba..0a04d9c00 100644 --- a/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt +++ b/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt @@ -31,6 +31,7 @@ import org.getlantern.mobilesdk.Logger import org.getlantern.mobilesdk.Settings import org.getlantern.mobilesdk.StartResult import org.getlantern.mobilesdk.util.DnsDetector +import org.getlantern.mobilesdk.util.LanguageHelper import org.greenrobot.eventbus.EventBus import java.io.PrintWriter import java.io.StringWriter @@ -583,7 +584,8 @@ abstract class SessionManager(application: Application) : Session { // initialize email address to empty string (if it doesn't already exist) if (email().isEmpty()) setEmail("") - if (prefs.getInt(ACCEPTED_TERMS_VERSION, 0) == 0) prefs.edit().putInt(ACCEPTED_TERMS_VERSION, 0).apply() + if (prefs.getInt(ACCEPTED_TERMS_VERSION, 0) == 0) prefs.edit() + .putInt(ACCEPTED_TERMS_VERSION, 0).apply() Logger.debug(TAG, "prefs.edit() finished at ${System.currentTimeMillis() - start}") internalHeaders = context.getSharedPreferences( @@ -605,6 +607,15 @@ abstract class SessionManager(application: Application) : Session { Logger.debug(TAG, "Lingver.init() finished at ${System.currentTimeMillis() - start}") } else { locale = Lingver.init(application).getLocale() + // Here check if we support device language localization + // if not then set default language to English + locale = + if (LanguageHelper.supportLanguages.contains("${locale!!.language}_${locale!!.country}")) { + locale + } else { + // Default language is English + Locale("en", "US") + } Logger.debug(TAG, "Lingver.init() finished at ${System.currentTimeMillis() - start}") Logger.debug(TAG, "Configured language was empty, using %1\$s", locale) setLocale(locale) diff --git a/android/app/src/main/java/org/getlantern/mobilesdk/util/LanguageHelper.kt b/android/app/src/main/java/org/getlantern/mobilesdk/util/LanguageHelper.kt new file mode 100644 index 000000000..211659563 --- /dev/null +++ b/android/app/src/main/java/org/getlantern/mobilesdk/util/LanguageHelper.kt @@ -0,0 +1,26 @@ +package org.getlantern.mobilesdk.util + +class LanguageHelper { + + companion object { + val supportLanguages = arrayListOf( + "en_US", + "fa_IR", + "zh_CN", + "zh_HK", + "ms_MY", + "my_MM", + "ru_RU", + "tr_TR", + "hi_IN", + "ur_IN", + "ar_EG", + "vi_VN", + "th_TH", + "es_ES", + "fr_FR", + "bn_BD", + ) + } + +} \ No newline at end of file