Normalize some locale names

(cherry picked from commit 36f307e3bbf5a52277fba3033a08201cd37f779a)

# Conflicts:
#	app/src/main/java/eu/kanade/presentation/browse/GlobalSearchScreen.kt
This commit is contained in:
arkon 2024-01-06 18:14:45 -05:00 committed by Jobobby04
parent ff00c301e1
commit 3e561f7b67
3 changed files with 19 additions and 9 deletions

View File

@ -75,9 +75,10 @@ internal fun GlobalSearchContent(
items.forEach { (source, result) -> items.forEach { (source, result) ->
item(key = source.id) { item(key = source.id) {
GlobalSearchResultItem( GlobalSearchResultItem(
title = fromSourceId?.let { "${source.name}".takeIf { source.id == fromSourceId } } title = fromSourceId?.let {
?: source.name, "${source.name}".takeIf { source.id == fromSourceId }
subtitle = LocaleHelper.getDisplayName(source.lang), } ?: source.name,
subtitle = LocaleHelper.getLocalizedDisplayName(source.lang),
onClick = { onClickSource(source) }, onClick = { onClickSource(source) },
) { ) {
when (result) { when (result) {

View File

@ -34,7 +34,6 @@ import tachiyomi.core.i18n.stringResource
import tachiyomi.i18n.MR import tachiyomi.i18n.MR
import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.i18n.stringResource import tachiyomi.presentation.core.i18n.stringResource
import java.util.Locale
class AppLanguageScreen : Screen() { class AppLanguageScreen : Screen() {
@ -104,9 +103,9 @@ class AppLanguageScreen : Screen() {
for (i in 0..<parser.attributeCount) { for (i in 0..<parser.attributeCount) {
if (parser.getAttributeName(i) == "name") { if (parser.getAttributeName(i) == "name") {
val langTag = parser.getAttributeValue(i) val langTag = parser.getAttributeValue(i)
val displayName = LocaleHelper.getDisplayName(langTag) val displayName = LocaleHelper.getLocalizedDisplayName(langTag)
if (displayName.isNotEmpty()) { if (displayName.isNotEmpty()) {
langs.add(Language(langTag, displayName, Locale.forLanguageTag(langTag).displayName)) langs.add(Language(langTag, displayName, LocaleHelper.getDisplayName(langTag)))
} }
} }
} }

View File

@ -21,7 +21,7 @@ object LocaleHelper {
} else if (b == "all") { } else if (b == "all") {
1 1
} else { } else {
getDisplayName(a).compareTo(getDisplayName(b)) getLocalizedDisplayName(a).compareTo(getLocalizedDisplayName(b))
} }
} }
@ -39,16 +39,26 @@ object LocaleHelper {
SourcesScreenModel.PINNED_KEY -> context.stringResource(MR.strings.pinned_sources) SourcesScreenModel.PINNED_KEY -> context.stringResource(MR.strings.pinned_sources)
"other" -> context.stringResource(MR.strings.other_source) "other" -> context.stringResource(MR.strings.other_source)
"all" -> context.stringResource(MR.strings.multi_lang) "all" -> context.stringResource(MR.strings.multi_lang)
else -> getDisplayName(lang) else -> getLocalizedDisplayName(lang)
} }
} }
fun getDisplayName(lang: String): String {
val normalizedLang = when (lang) {
"zh-CN" -> "zh-Hans"
"zh-TW" -> "zh-Hant"
else -> lang
}
return Locale.forLanguageTag(normalizedLang).displayName
}
/** /**
* Returns display name of a string language code. * Returns display name of a string language code.
* *
* @param lang empty for system language * @param lang empty for system language
*/ */
fun getDisplayName(lang: String?): String { fun getLocalizedDisplayName(lang: String?): String {
if (lang == null) { if (lang == null) {
return "" return ""
} }