Skip to content

Commit

Permalink
add missing lang selector options
Browse files Browse the repository at this point in the history
  • Loading branch information
yurtpage committed May 5, 2024
1 parent 6d0c626 commit 880e058
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ sealed class LanguagesPreference(val value: Int) {
object UseDeviceLanguages : LanguagesPreference(0)
object English : LanguagesPreference(1)
object ChineseSimplified : LanguagesPreference(2)
object Farsi : LanguagesPreference(3)
object Russian : LanguagesPreference(4)

fun put(context: Context, scope: CoroutineScope) {
scope.launch {
Expand All @@ -32,13 +34,17 @@ sealed class LanguagesPreference(val value: Int) {
UseDeviceLanguages -> context.getString(R.string.use_device_languages)
English -> context.getString(R.string.english)
ChineseSimplified -> context.getString(R.string.chinese_simplified)
Farsi -> context.getString(R.string.farsi)
Russian -> context.getString(R.string.russian)
}

fun getLocale(): Locale =
when (this) {
UseDeviceLanguages -> LocaleList.getDefault().get(0)
English -> Locale("en", "US")
ChineseSimplified -> Locale("zh", "CN")
Farsi -> Locale("zh", "CN")
Russian -> Locale("ru", "RU")
}

fun setLocale(context: Context) {
Expand All @@ -65,14 +71,18 @@ sealed class LanguagesPreference(val value: Int) {
val values = listOf(
UseDeviceLanguages,
English,
ChineseSimplified
ChineseSimplified,
Farsi,
Russian
)

fun fromPreferences(preferences: Preferences): LanguagesPreference =
when (preferences[DataStoreKeys.Languages.key]) {
0 -> UseDeviceLanguages
1 -> English
2 -> ChineseSimplified
3 -> Farsi
4 -> Russian
else -> default
}

Expand All @@ -81,6 +91,8 @@ sealed class LanguagesPreference(val value: Int) {
0 -> UseDeviceLanguages
1 -> English
2 -> ChineseSimplified
3 -> Farsi
4 -> Russian
else -> default
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
<string name="about_setting_desc">Version, issue, credits</string>
<string name="languages">Languages</string>
<string name="use_device_languages">Use Device Languages</string>
<string name="languages_setting_desc">English, Chinese, more</string>
<string name="languages_setting_desc">English, Chinese, Farsi, Russian, more</string>
<string name="english" translatable="false">English</string>
<string name="chinese_simplified" translatable="false">简体中文</string>
<string name="farsi" translatable="false">فارسی</string>
<string name="russian" translatable="false">Русский</string>
<string name="joplin_server">Joplin Server</string>
<string name="syncing">Syncing</string>
<string name="every_15_minutes">Every 15 minutes</string>
Expand Down

0 comments on commit 880e058

Please sign in to comment.