Add fallback for getting dictionary resid a more normal way

This commit is contained in:
Aleksandras Kostarevas 2024-01-24 02:09:19 +02:00
parent 7aea41eede
commit abc5a74004
3 changed files with 50 additions and 2 deletions

View File

@ -65,11 +65,12 @@ android {
buildTypes { buildTypes {
debug { debug {
minifyEnabled false minifyEnabled false
shrinkResources false
signingConfig signingConfigs.debug signingConfig signingConfigs.debug
} }
release { release {
minifyEnabled true minifyEnabled true
shrinkResources true shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig releaseSigning signingConfig releaseSigning
} }

View File

@ -0,0 +1,37 @@
package org.futo.inputmethod.latin.utils
import androidx.annotation.RawRes
import org.futo.inputmethod.latin.R
import java.util.Locale
object Dictionaries {
private val dictionaries = mapOf(
"" to R.raw.main,
"de" to R.raw.main_de,
"en" to R.raw.main_en,
"es" to R.raw.main_es,
"fr" to R.raw.main_fr,
"it" to R.raw.main_it,
"pt_br" to R.raw.main_pt_br,
"ru" to R.raw.main_ru
)
@RawRes
public fun getDictionaryId(locale: Locale): Int {
var resId = 0
// Try to find main_language_country dictionary.
if (locale.country.isNotEmpty()) {
val dictLanguageCountry = locale.toString().lowercase()
resId = dictionaries[dictLanguageCountry] ?: 0
}
// Try to find main_language dictionary.
if(resId == 0) {
val dictLanguage = locale.language
resId = dictionaries[dictLanguage] ?: 0
}
return resId
}
}

View File

@ -368,6 +368,10 @@ public class DictionaryInfoUtils {
return resId; return resId;
} }
if ((resId = Dictionaries.INSTANCE.getDictionaryId(locale)) != 0) {
return resId;
}
// Not found, return 0 // Not found, return 0
return 0; return 0;
} }
@ -383,8 +387,14 @@ public class DictionaryInfoUtils {
if (0 != resourceId) { if (0 != resourceId) {
return resourceId; return resourceId;
} }
return res.getIdentifier(DEFAULT_MAIN_DICT + DecoderSpecificConstants.DECODER_DICT_SUFFIX, resourceId = res.getIdentifier(DEFAULT_MAIN_DICT + DecoderSpecificConstants.DECODER_DICT_SUFFIX,
"raw", RESOURCE_PACKAGE_NAME); "raw", RESOURCE_PACKAGE_NAME);
if (0 != resourceId) {
return resourceId;
}
return R.raw.main;
} }
/** /**