mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 05:52:47 +00:00
workaround for languages that don't have a display name in all languages
This commit is contained in:
parent
dc4cdea687
commit
4476456b83
2 changed files with 21 additions and 5 deletions
|
@ -6,7 +6,9 @@
|
|||
package helium314.keyboard.latin.common
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import helium314.keyboard.compat.locale
|
||||
import helium314.keyboard.latin.BuildConfig
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.utils.ScriptUtils.script
|
||||
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
|
||||
|
@ -181,12 +183,26 @@ object LocaleUtils {
|
|||
|
||||
@JvmStatic
|
||||
fun getLocaleDisplayNameInSystemLocale(locale: Locale, context: Context): String {
|
||||
return getLocaleDisplayNameInLocale(locale, context.resources, context.resources.configuration.locale())
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getLocaleDisplayNameInLocale(locale: Locale, resources: Resources, displayLocale: Locale): String {
|
||||
val languageTag = locale.toLanguageTag()
|
||||
if (languageTag == SubtypeLocaleUtils.NO_LANGUAGE) return context.getString(R.string.subtype_no_language)
|
||||
if (languageTag == SubtypeLocaleUtils.NO_LANGUAGE) return resources.getString(R.string.subtype_no_language)
|
||||
if (locale.script() != locale.language.constructLocale().script() || locale.language == "xdq") {
|
||||
val resId = context.resources.getIdentifier("subtype_${languageTag.replace("-", "_")}", "string", context.packageName)
|
||||
if (resId != 0) return context.getString(resId)
|
||||
val resId = resources.getIdentifier(
|
||||
"subtype_${languageTag.replace("-", "_")}",
|
||||
"string",
|
||||
BuildConfig.APPLICATION_ID // replaces context.packageName, see https://stackoverflow.com/a/24525379
|
||||
)
|
||||
if (resId != 0) return resources.getString(resId)
|
||||
}
|
||||
val localeDisplayName = locale.getDisplayName(displayLocale)
|
||||
return if (localeDisplayName == languageTag) {
|
||||
locale.getDisplayName(Locale.US) // try fallback to English name, relevant e.g. fpr pms, see https://github.com/Helium314/HeliBoard/pull/748
|
||||
} else {
|
||||
localeDisplayName
|
||||
}
|
||||
return locale.getDisplayName(context.resources.configuration.locale())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public final class SubtypeLocaleUtils {
|
|||
if (exceptionalNameResId != null) {
|
||||
displayName = RunInLocaleKt.runInLocale(sResources, displayLocale, res -> res.getString(exceptionalNameResId));
|
||||
} else {
|
||||
displayName = locale.getDisplayName(displayLocale);
|
||||
displayName = LocaleUtils.getLocaleDisplayNameInLocale(locale, sResources, displayLocale);
|
||||
}
|
||||
return StringUtils.capitalizeFirstCodePoint(displayName, displayLocale);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue