Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't switch languages that we don't support. #944

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
)
}

}
Loading