From abc5a740048d077ea027e33046a1d601a201cf77 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Wed, 24 Jan 2024 02:09:19 +0200 Subject: [PATCH] Add fallback for getting dictionary resid a more normal way --- build.gradle | 3 +- .../inputmethod/latin/utils/Dictionaries.kt | 37 +++++++++++++++++++ .../latin/utils/DictionaryInfoUtils.java | 12 +++++- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 java/src/org/futo/inputmethod/latin/utils/Dictionaries.kt diff --git a/build.gradle b/build.gradle index dd455433d..9691ac5f2 100644 --- a/build.gradle +++ b/build.gradle @@ -65,11 +65,12 @@ android { buildTypes { debug { minifyEnabled false + shrinkResources false signingConfig signingConfigs.debug } release { minifyEnabled true - shrinkResources true + shrinkResources false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' signingConfig releaseSigning } diff --git a/java/src/org/futo/inputmethod/latin/utils/Dictionaries.kt b/java/src/org/futo/inputmethod/latin/utils/Dictionaries.kt new file mode 100644 index 000000000..e315f3ce6 --- /dev/null +++ b/java/src/org/futo/inputmethod/latin/utils/Dictionaries.kt @@ -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 + } +} \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/org/futo/inputmethod/latin/utils/DictionaryInfoUtils.java index 70b7433ee..27ea5a0fe 100644 --- a/java/src/org/futo/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/java/src/org/futo/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -368,6 +368,10 @@ public class DictionaryInfoUtils { return resId; } + if ((resId = Dictionaries.INSTANCE.getDictionaryId(locale)) != 0) { + return resId; + } + // Not found, return 0 return 0; } @@ -383,8 +387,14 @@ public class DictionaryInfoUtils { if (0 != 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); + + if (0 != resourceId) { + return resourceId; + } + + return R.raw.main; } /**