From 0ce8c24b66bff815567dc384abab3fa467e4cb29 Mon Sep 17 00:00:00 2001 From: ialokim <ialokim@mailbox.org> Date: Thu, 17 Feb 2022 10:12:34 +0100 Subject: [PATCH] update TRANSLATION.md, mark some hardcoded strings and avoid screen redraw if same setting is selected --- HACKING.md | 6 ++++-- TRANSLATION.md | 2 +- .../androidx/compose/material/ExposedDropDownMenu.kt | 3 ++- .../briar/desktop/settings/UnencryptedSettings.kt | 4 ++-- .../briar/desktop/settings/UnencryptedSettingsImpl.kt | 8 ++++++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/HACKING.md b/HACKING.md index 815abd4e80..6cdd07f57f 100644 --- a/HACKING.md +++ b/HACKING.md @@ -26,7 +26,9 @@ will also run tests on briar core: ## Testing different locales -To test the app with a different locale, add this e.g. in `Main.kt`: +You can simply switch the language in the settings screen of the application. + +To test the app with a different *default* locale, add this e.g. in `Main.kt`: ``` Locale.setDefault(Locale("ar")) @@ -36,7 +38,7 @@ and replace `ar` with a different language you would like to test, such as Arabic in this example. It is also possible to run from the command line using Gradle with a -different language setting: +different *default* language setting: ``` GRADLE_OPTS="-Duser.language=fr -Duser.country=FR" ./gradlew run diff --git a/TRANSLATION.md b/TRANSLATION.md index 4b5bd0f5e8..43ab7bd131 100644 --- a/TRANSLATION.md +++ b/TRANSLATION.md @@ -14,7 +14,7 @@ _This section is of interest only for developers of Briar Desktop_. To update translations locally, first install `transifex-client`. You can then pull updates with `tx pull -a`. If that command added a language that was previously not supported, -you have to manually insert the language code in [Settings.kt](./src/main/kotlin/org/briarproject/briar/desktop/settings/Settings.kt) +you have to manually insert the language code in [UnencryptedSettings.kt](./src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettings.kt) for it to be shown in the language selection. The Localization Lab has some instructions and advice for diff --git a/src/main/kotlin/androidx/compose/material/ExposedDropDownMenu.kt b/src/main/kotlin/androidx/compose/material/ExposedDropDownMenu.kt index 92450c6cfb..ffbe92e8bd 100644 --- a/src/main/kotlin/androidx/compose/material/ExposedDropDownMenu.kt +++ b/src/main/kotlin/androidx/compose/material/ExposedDropDownMenu.kt @@ -58,6 +58,7 @@ import org.briarproject.briar.desktop.utils.PreviewUtils.preview // Taken from https://stackoverflow.com/a/69042850 and slightly adapted to follow Material theming // See https://github.com/JetBrains/compose-jb/issues/1673 as tracking issue +@Suppress("HardCodedStringLiteral") fun main() = preview { val values = (0..5).map { "Test $it" } var selected by remember { mutableStateOf(-1) } @@ -196,7 +197,7 @@ private fun ExposedDropDownMenuImpl( } Icon( imageVector = Icons.Filled.ArrowDropDown, - contentDescription = "Change", + contentDescription = "Change", // NON-NLS since this will be replaced by a toolkit native version at some point tint = trailingIconColor, modifier = Modifier .align(Alignment.CenterEnd) diff --git a/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettings.kt b/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettings.kt index 8c78db28ae..af1d1b9aa6 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettings.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettings.kt @@ -30,12 +30,12 @@ interface UnencryptedSettings { DEFAULT, EN, // languages as present in resources - AR, BG, DE, ES, FA, GL, HU, IS, IT, LT, PL, RO, RU, SK, SQ, SV, TR, ZH_CN; + AR, BG, DE, ES, FA, FR, GL, HE, HU, IS, IT, JA, KO, LT, MY, NL, PL, PT_BR, RO, RU, SK, SQ, SV, TR, ZH_CN; val locale: Locale get() = if (this == DEFAULT) Locale.getDefault() - else Locale.forLanguageTag(this.name.replace('_', '-')) + else Locale.forLanguageTag(name.replace('_', '-')) } var theme: Theme diff --git a/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt b/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt index 255458ce57..c434459e33 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt @@ -27,8 +27,8 @@ import org.briarproject.briar.desktop.viewmodel.SingleStateEvent import java.util.prefs.Preferences import javax.inject.Inject -const val PREF_THEME = "theme" -const val PREF_LANG = "language" +const val PREF_THEME = "theme" // NON-NLS +const val PREF_LANG = "language" // NON-NLS class UnencryptedSettingsImpl @Inject internal constructor() : UnencryptedSettings { @@ -40,6 +40,8 @@ class UnencryptedSettingsImpl @Inject internal constructor() : UnencryptedSettin override var theme: Theme get() = Theme.valueOf(prefs.get(PREF_THEME, AUTO.name)) set(value) { + if (theme == value) return + prefs.put(PREF_THEME, value.name) prefs.flush() // write preferences to disk invalidateScreen.emit(Unit) @@ -48,6 +50,8 @@ class UnencryptedSettingsImpl @Inject internal constructor() : UnencryptedSettin override var language: Language get() = Language.valueOf(prefs.get(PREF_LANG, DEFAULT.name)) set(value) { + if (language == value) return + prefs.put(PREF_LANG, value.name) prefs.flush() // write preferences to disk updateLocale(value) -- GitLab