clarify when we use our own name for the language instead of using whatver is provided by the system

This commit is contained in:
Helium314 2025-04-19 08:35:46 +02:00
parent c32b3bada4
commit 7748ed75fe
2 changed files with 8 additions and 2 deletions

View file

@ -188,7 +188,8 @@ object LocaleUtils {
fun getLocaleDisplayNameInLocale(locale: Locale, resources: Resources, displayLocale: Locale): String {
val languageTag = locale.toLanguageTag()
if (languageTag == SubtypeLocaleUtils.NO_LANGUAGE) return resources.getString(R.string.subtype_no_language)
if (locale.script() != locale.language.constructLocale().script() || locale.language == "mns" || locale.language == "xdq" || locale.language=="dru" || locale.language=="st" || locale.language=="dag") {
if (hasNonDefaultScript(locale) || doesNotHaveAndroidName(locale.language)) {
// supply our own name for the language instead of using name provided by the system
val resId = resources.getIdentifier(
"subtype_${languageTag.replace("-", "_")}",
"string",
@ -203,4 +204,9 @@ object LocaleUtils {
localeDisplayName
}
}
private fun hasNonDefaultScript(locale: Locale) = locale.script() != locale.language.constructLocale().script()
private fun doesNotHaveAndroidName(language: String) =
language == "mns" || language == "xdq" || language=="dru" || language == "st" || language == "dag"
}

View file

@ -125,7 +125,7 @@ You can also specify special key codes like `a|!code/key_action_previous` or `ab
* `[number_row]` may contain a custom number row (1-9 and 0 separated by space). You should also add the language to `numberRowLocales` in [`PreferencesSettingsFragment`](app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java) so the user can opt into having a localized number row.
* `[extra_keys]` are typically keys shown in the default layout of the language. This is currently only used for latin layouts to avoid duplicating layouts for just adding few keys on the right side. The layout name need to end with `+`, but the `+` is removed when looking up the actual layout.
* If you add a new language for which Android does not have a display name, it will be displayed using the language tag
* Avoiding this currently is more complicated than necessary: add the language tag to [LocaleUtils.getLocaleDisplayNameInSystemLocale](/app/src/main/java/helium314/keyboard/latin/common/LocaleUtils.kt#L181) to have an exception, and add a string named `subtype_<langage tag, but with _ instead of ->` to [`strings.xml`](/app/src/main/res/values/strings.xml). Further you may need to add a `subtype_in_root_locale_<language tag>` to [donottranslate.xml](/app/src/main/res/values/donottranslate.xml), and add the language tag to `subtype_locale_exception_keys` and `subtype_locale_displayed_in_root_locale`.
* Avoiding this currently is more complicated than necessary: add the language to [LocaleUtils.doesNotHaveAndroidName](/app/src/main/java/helium314/keyboard/latin/common/LocaleUtils.kt#L210) to have an exception, and add a string named `subtype_<langage tag, but with _ instead of ->` to [`strings.xml`](/app/src/main/res/values/strings.xml). In case you still have it not displayed properly, you may need to add a `subtype_in_root_locale_<language tag>` to [donottranslate.xml](/app/src/main/res/values/donottranslate.xml), and add the language tag to `subtype_locale_exception_keys` and `subtype_locale_displayed_in_root_locale`.
* If a newly added language does not use latin script, please update the default scripts method `Locale.script` in [ScriptUtils](app/src/main/java/helium314/keyboard/latin/utils/ScriptUtils.kt)
## Functional key layouts