Move non-com global TLDs to end of list (#1668)

This commit is contained in:
Eran Leshem 2025-06-11 23:16:39 +03:00 committed by GitHub
parent 49c9d77978
commit 871ac110ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,7 +45,7 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) {
"mns" -> Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO "mns" -> Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO
else -> 0 else -> 0
} }
val tlds = getLocaleTlds(locale) val tlds = mutableListOf<String>()
init { init {
readStream(dataStream, false, true) readStream(dataStream, false, true)
@ -84,7 +84,7 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) {
READER_MODE_EXTRA_KEYS -> if (!onlyPopupKeys) addExtraKey(line.split(colonSpaceRegex, 2)) READER_MODE_EXTRA_KEYS -> if (!onlyPopupKeys) addExtraKey(line.split(colonSpaceRegex, 2))
READER_MODE_LABELS -> if (!onlyPopupKeys) addLabel(line.split(colonSpaceRegex, 2)) READER_MODE_LABELS -> if (!onlyPopupKeys) addLabel(line.split(colonSpaceRegex, 2))
READER_MODE_NUMBER_ROW -> localizedNumberKeys = line.splitOnWhitespace() READER_MODE_NUMBER_ROW -> localizedNumberKeys = line.splitOnWhitespace()
READER_MODE_TLD -> SpacedTokens(line).forEach { tlds.add(".$it") } READER_MODE_TLD -> tlds.addAll(SpacedTokens(line).map { ".$it" })
} }
} }
} }
@ -156,6 +156,16 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) {
} }
} }
fun addLocaleTlds(locale: Locale) {
tlds.add(0, comTld)
val ccLower = locale.country.lowercase()
if (ccLower.isNotEmpty() && locale.language != SubtypeLocaleUtils.NO_LANGUAGE) {
specialCountryTlds[ccLower]?.let { tlds.addAll(SpacedTokens(it)) } ?: tlds.add(".$ccLower")
}
if ((locale.language != "en" && euroLocales.matches(locale.language)) || euroCountries.matches(locale.country))
tlds.add(".eu")
tlds.addAll(SpacedTokens(otherDefaultTlds))
}
} }
private fun addFixedColumnOrder(popupKeys: MutableCollection<String>) { private fun addFixedColumnOrder(popupKeys: MutableCollection<String>) {
@ -205,6 +215,7 @@ private fun createLocaleKeyTexts(context: Context, params: KeyboardParams, popup
POPUP_KEYS_MORE -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_more.txt"), false) POPUP_KEYS_MORE -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_more.txt"), false)
POPUP_KEYS_ALL -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_all.txt"), false) POPUP_KEYS_ALL -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_all.txt"), false)
} }
lkt.addLocaleTlds(params.mId.locale)
return lkt return lkt
} }
@ -220,28 +231,6 @@ private fun getStreamForLocale(locale: Locale, context: Context) =
} }
} }
private fun getLocaleTlds(locale: Locale): LinkedHashSet<String> {
val tlds = getDefaultTlds(locale)
val ccLower = locale.country.lowercase()
if (ccLower.isEmpty() || locale.language == SubtypeLocaleUtils.NO_LANGUAGE)
return tlds
specialCountryTlds.forEach {
if (ccLower != it.first) return@forEach
tlds.addAll(SpacedTokens(it.second))
return@getLocaleTlds tlds
}
tlds.add(".$ccLower")
return tlds
}
private fun getDefaultTlds(locale: Locale): LinkedHashSet<String> {
val tlds = linkedSetOf<String>()
tlds.addAll(SpacedTokens(defaultTlds))
if ((locale.language != "en" && euroLocales.matches(locale.language)) || euroCountries.matches(locale.country))
tlds.add(".eu")
return tlds
}
fun clearCache() = localeKeyboardInfosCache.clear() fun clearCache() = localeKeyboardInfosCache.clear()
// cache the texts, so they don't need to be read over and over // cache the texts, so they don't need to be read over and over
@ -341,7 +330,7 @@ const val POPUP_KEYS_NORMAL = "normal"
private const val LOCALE_TEXTS_FOLDER = "locale_key_texts" private const val LOCALE_TEXTS_FOLDER = "locale_key_texts"
// either tld is not simply lowercase ISO 3166-1 code, or there are multiple according to some list // either tld is not simply lowercase ISO 3166-1 code, or there are multiple according to some list
private val specialCountryTlds = listOf( private val specialCountryTlds = hashMapOf<String, String>(
"bd" to ".bd .com.bd", "bd" to ".bd .com.bd",
"bq" to ".bq .an .nl", "bq" to ".bq .an .nl",
"bl" to ".bl .gp .fr", "bl" to ".bl .gp .fr",
@ -351,4 +340,5 @@ private val specialCountryTlds = listOf(
"mf" to ".mf .gp .fr", "mf" to ".mf .gp .fr",
"tl" to ".tl .tp", "tl" to ".tl .tp",
) )
private const val defaultTlds = ".com .gov .edu .org .net" private const val comTld = ".com"
private const val otherDefaultTlds = ".gov .edu .org .net"