mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-28 19:59:55 +00:00
Move non-com
global TLDs to end of list (#1668)
This commit is contained in:
parent
49c9d77978
commit
871ac110ad
1 changed files with 16 additions and 26 deletions
|
@ -45,7 +45,7 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) {
|
|||
"mns" -> Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO
|
||||
else -> 0
|
||||
}
|
||||
val tlds = getLocaleTlds(locale)
|
||||
val tlds = mutableListOf<String>()
|
||||
|
||||
init {
|
||||
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_LABELS -> if (!onlyPopupKeys) addLabel(line.split(colonSpaceRegex, 2))
|
||||
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>) {
|
||||
|
@ -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_ALL -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_all.txt"), false)
|
||||
}
|
||||
lkt.addLocaleTlds(params.mId.locale)
|
||||
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()
|
||||
|
||||
// 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"
|
||||
|
||||
// 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",
|
||||
"bq" to ".bq .an .nl",
|
||||
"bl" to ".bl .gp .fr",
|
||||
|
@ -351,4 +340,5 @@ private val specialCountryTlds = listOf(
|
|||
"mf" to ".mf .gp .fr",
|
||||
"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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue