Skip to content

Commit

Permalink
Don't switch languages that we don't support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Oct 31, 2023
1 parent 8aace0a commit 1fb5d21
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.getlantern.mobilesdk.util

class LanguageHelper {

companion object {
val supportLanguages = arrayListOf<String>(
"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",
)
}

}

0 comments on commit 1fb5d21

Please sign in to comment.