add TLD information to LocaleKeyboardInfos

preparation for #492
This commit is contained in:
Helium314 2025-01-20 21:28:12 +01:00
parent df8c0c6c59
commit 35e0fe6be3
39 changed files with 148 additions and 1 deletions

View file

@ -6,3 +6,6 @@ o ó ô ö ò õ œ ø ō
u ú û ü ù ū
n ñ ń
y ý ij
[tlds]
za

View file

@ -24,3 +24,6 @@ question: ؟
[number_row]
١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩ ٠
[tlds]
sa

View file

@ -3,3 +3,6 @@
[labels]
alphabet: АБВ
[tlds]
bg

View file

@ -10,3 +10,6 @@ punctuation !autoColumnOrder!9 \, ? ! · # ) ( / ; ' @ : - " + \% &
[extra_keys]
2: ç
[tlds]
cat es

View file

@ -14,3 +14,6 @@ y ý
z ž
'
" ” „ “ » «
[tlds]
cz

View file

@ -9,3 +9,6 @@ o ø
1: å
2: æ ä
2: ø ö
[tlds]
dk

View file

@ -5,3 +5,6 @@ u ü
s ß
'
" ” „ “ » «
[tlds]
de at ch

View file

@ -9,3 +9,6 @@
[labels]
alphabet: ΑΒΓ
[tlds]
gr

View file

@ -10,3 +10,6 @@ punctuation !autoColumnOrder!9 \, ? ! # ) ( / ; ¡ ' @ : - " + \% & ¿
[extra_keys]
2: ñ
[tlds]
es com.es

View file

@ -12,3 +12,6 @@ z ž
2: ö õ
2: ä
3: õ
[tlds]
ee

View file

@ -17,3 +17,6 @@ question: ؟
[number_row]
۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹ ۰
[tlds]
ir

View file

@ -8,3 +8,6 @@ z ž
1: å
2: ö ø
2: ä æ
[tlds]
fi

View file

@ -11,3 +11,6 @@ y ÿ
1: è ü
2: é ö
2: à ä
[tlds]
fr

View file

@ -0,0 +1,2 @@
[tlds]
in

View file

@ -73,3 +73,6 @@ period: ।
[number_row]
१ २ ३ ४ ५ ६ ७ ८ ९
[tlds]
in

View file

@ -5,3 +5,6 @@ c č ć
d đ
'
" “ „ ” » «
[tlds]
hr

View file

@ -6,3 +6,6 @@ o ó ö ő
u ú ü ű
'
" “ „ ” » «
[tlds]
hu gov.hu

View file

@ -6,3 +6,6 @@ punctuation !autoColumnOrder!8 \, ՞ ՜ … ' = / ՝ ՛ ֊ » « ― ) (
[labels]
alphabet: ԱԲԳ
period: ։
[tlds]
am

View file

@ -9,3 +9,6 @@ y ý
t þ
'
" ” „ “
[tlds]
is

View file

@ -4,3 +4,6 @@ e è é ə
i ì
o ò ó º
u ù
[tlds]
it gov.it edu.it

View file

@ -10,3 +10,6 @@
[labels]
alphabet: אבג
[tlds]
il co.il gov.il

View file

@ -14,3 +14,5 @@ b p
[labels]
alphabet: AƐΓ
[tlds]
dz fr

View file

@ -1,2 +1,5 @@
[labels]
alphabet: ㄱㄴㄷ
[tlds]
kr

View file

@ -8,3 +8,6 @@ u ū ų
z ž
'
" ” „ “
[tlds]
lt

View file

@ -13,3 +13,6 @@ u ū
z ž
'
" ” „ “
[tlds]
lv

View file

@ -9,3 +9,6 @@ o ø
1: å
2: ø ö
2: æ ä
[tlds]
no

View file

@ -9,3 +9,6 @@ z ż ź
l ł
'
" “ „ ”
[tlds]
pl

View file

@ -5,3 +5,6 @@ s ș
t ț
'
" “ „ ”
[tlds]
ro

View file

@ -6,3 +6,6 @@
[labels]
alphabet: АБВ
[tlds]
ru

View file

@ -15,3 +15,6 @@ z ž
l ľ ĺ
'
" ” „ “ » «
[tlds]
sk

View file

@ -4,3 +4,6 @@ c č ć
z ž
'
" ” „ “ » «
[tlds]
si

View file

@ -10,3 +10,6 @@ d đ
2: ć
3: đ
3: ž
[tlds]
rs

View file

@ -6,3 +6,6 @@
[labels]
alphabet: АБВ
[tlds]
rs

View file

@ -8,3 +8,6 @@ o ö
1: å
2: ö
2: ä
[tlds]
sv

View file

@ -7,3 +7,6 @@ u ü û
s ş
g ğ
c ç
[tlds]
tr gov.tr edu.tr com.tr

View file

@ -7,3 +7,6 @@
[labels]
alphabet: АБВ
[tlds]
ua

View file

@ -6,3 +6,6 @@ o ò ó ỏ õ ọ ô ồ ố ổ ỗ ộ ơ ờ ớ ở ỡ ợ
u ù ú ủ ũ ụ ư ừ ứ ử ữ ự
y ỳ ý ỷ ỹ ỵ
d đ
[tlds]
vn

View file

@ -43,6 +43,7 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) {
"mns" -> Key.LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO
else -> 0
}
val tlds = getLocaleTlds(locale) // todo: USE IT
init {
readStream(dataStream, false, true)
@ -74,17 +75,25 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) {
"[extra_keys]" -> { mode = READER_MODE_EXTRA_KEYS; return@forEachLine }
"[labels]" -> { mode = READER_MODE_LABELS; return@forEachLine }
"[number_row]" -> { mode = READER_MODE_NUMBER_ROW; return@forEachLine }
"[tlds]" -> { mode = READER_MODE_TLD; return@forEachLine }
}
when (mode) {
READER_MODE_POPUP_KEYS -> addPopupKeys(line, priority)
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 -> line.splitOnWhitespace().forEach { tlds.add(".$it") }
}
}
}
}
fun addDefaultTlds(locale: Locale) {
if ((locale.language != "en" && euroLocales.matches(locale.language)) || euroCountries.matches(locale.country))
tlds.add(".eu")
tlds.addAll(defaultTlds.splitOnWhitespace())
}
/** Pair(extraKeysLeft, extraKeysRight) */
fun getTabletExtraKeys(elementId: Int): Pair<List<KeyData>, List<KeyData>> {
val flags = Key.LABEL_FLAGS_FONT_DEFAULT
@ -192,6 +201,7 @@ private fun createLocaleKeyTexts(context: Context, params: KeyboardParams, popup
if (locale == params.mId.locale) return@forEach
lkt.addFile(getStreamForLocale(locale, context), true)
}
lkt.addDefaultTlds(params.mId.locale)
when (popupKeysSetting) {
POPUP_KEYS_MAIN -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_main.txt"), false)
POPUP_KEYS_MORE -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_more.txt"), false)
@ -212,6 +222,20 @@ private fun getStreamForLocale(locale: Locale, context: Context) =
}
}
private fun getLocaleTlds(locale: Locale): LinkedHashSet<String> {
val ccLower = locale.country.lowercase()
val tlds = LinkedHashSet<String>()
if (ccLower.isEmpty() || ccLower == "zz")
return tlds
specialCountryTlds.forEach {
if (ccLower != it.first) return@forEach
tlds.addAll(it.second.splitOnWhitespace())
return tlds
}
tlds.add(".$ccLower")
return tlds
}
fun clearCache() = localeKeyboardInfosCache.clear()
// cache the texts, so they don't need to be read over and over
@ -222,6 +246,7 @@ private const val READER_MODE_POPUP_KEYS = 1
private const val READER_MODE_EXTRA_KEYS = 2
private const val READER_MODE_LABELS = 3
private const val READER_MODE_NUMBER_ROW = 4
private const val READER_MODE_TLD = 5
// probably could be improved and extended, currently this is what's done in key_styles_currency.xml
private fun getCurrencyKey(locale: Locale): Pair<String, List<String>> {
@ -294,3 +319,16 @@ const val POPUP_KEYS_MAIN = 3
const val POPUP_KEYS_NORMAL = 0
private const val LOCALE_TEXTS_FOLDER = "locale_key_texts"
// either tld is not lowecase ISO 3166-1 code, or there are multiple according to some list
private val specialCountryTlds = listOf(
"bd" to ".bd .com.bd",
"bq" to ".bq .an .nl",
"bl" to ".bl .gp .fr",
"sx" to ".sx .an",
"gb" to ".uk .co.uk",
"eh" to ".eh .ma",
"mf" to ".mf .gp .fr",
"tl" to ".tl .tp",
)
private const val defaultTlds = ".com .gov .edu .org .net"