From 7748ed75fe5a6a124dff26eae57218357d6853e7 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sat, 19 Apr 2025 08:35:46 +0200 Subject: [PATCH] clarify when we use our own name for the language instead of using whatver is provided by the system --- .../java/helium314/keyboard/latin/common/LocaleUtils.kt | 8 +++++++- layouts.md | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/common/LocaleUtils.kt b/app/src/main/java/helium314/keyboard/latin/common/LocaleUtils.kt index 85f8f8850..ab37a9adb 100644 --- a/app/src/main/java/helium314/keyboard/latin/common/LocaleUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/common/LocaleUtils.kt @@ -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" } diff --git a/layouts.md b/layouts.md index 9464abea6..8612a2e97 100644 --- a/layouts.md +++ b/layouts.md @@ -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_` to [`strings.xml`](/app/src/main/res/values/strings.xml). Further you may need to add a `subtype_in_root_locale_` 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_` 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_` 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