better check for scripts supporting uppercase

previously language was used, which fails for hinglish
This commit is contained in:
Helium314 2023-08-29 12:22:39 +02:00
parent cb09538b32
commit e623d14829
3 changed files with 15 additions and 26 deletions

View file

@ -608,7 +608,7 @@ public final class StringUtils {
@Nullable @Nullable
public static String toTitleCaseOfKeyLabel(@Nullable final String label, public static String toTitleCaseOfKeyLabel(@Nullable final String label,
@Nonnull final Locale locale) { @Nonnull final Locale locale) {
if (label == null || !ScriptUtils.scriptSupportsUppercase(locale.getLanguage())) { if (label == null || !ScriptUtils.scriptSupportsUppercase(locale)) {
return label; return label;
} }

View file

@ -155,7 +155,7 @@ public class SettingsValues {
mInputAttributes = inputAttributes; mInputAttributes = inputAttributes;
// Get the settings preferences // Get the settings preferences
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true) && ScriptUtils.scriptSupportsUppercase(mLocale.getLanguage()); mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true) && ScriptUtils.scriptSupportsUppercase(mLocale);
mVibrateOn = Settings.readVibrationEnabled(prefs, res); mVibrateOn = Settings.readVibrationEnabled(prefs, res);
mSoundOn = Settings.readKeypressSoundEnabled(prefs, res); mSoundOn = Settings.readKeypressSoundEnabled(prefs, res);
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res); mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);

View file

@ -50,19 +50,8 @@ public class ScriptUtils {
public static final int SCRIPT_THAI = 17; public static final int SCRIPT_THAI = 17;
public static final int SCRIPT_BULGARIAN = 18; public static final int SCRIPT_BULGARIAN = 18;
public static final String LANGUAGE_GEORGIAN = "ka";
public static final String LANGUAGE_BENGALI = "bn";
public static final String LANGUAGE_HINDI = "hi";
public static final String LANGUAGE_THAI = "th";
public static final String LANGUAGE_KHMER = "km";
public static final String LANGUAGE_LAO = "lo";
public static final String LANGUAGE_SINHALA = "si";
public static final String LANGUAGE_NEPALI = "ne";
private static final TreeMap<String, Integer> mLanguageCodeToScriptCode; private static final TreeMap<String, Integer> mLanguageCodeToScriptCode;
private final static ArraySet<String> NON_UPPERCASE_SCRIPTS = new ArraySet<>(); private final static ArraySet<Integer> UPPERCASE_SCRIPTS = new ArraySet<>();
static { static {
@ -87,19 +76,19 @@ public class ScriptUtils {
mLanguageCodeToScriptCode.put("th", SCRIPT_THAI); mLanguageCodeToScriptCode.put("th", SCRIPT_THAI);
mLanguageCodeToScriptCode.put("uk", SCRIPT_CYRILLIC); mLanguageCodeToScriptCode.put("uk", SCRIPT_CYRILLIC);
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_GEORGIAN); // only Latin, Cyrillic, Greek and Armenian have upper/lower case
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_BENGALI); // https://unicode.org/faq/casemap_charprop.html#3
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_HINDI); // adding Bulgarian because internally it uses a separate script value
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_THAI); UPPERCASE_SCRIPTS.add(SCRIPT_LATIN);
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_KHMER); UPPERCASE_SCRIPTS.add(SCRIPT_CYRILLIC);
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_LAO); UPPERCASE_SCRIPTS.add(SCRIPT_BULGARIAN);
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_SINHALA); UPPERCASE_SCRIPTS.add(SCRIPT_GREEK);
NON_UPPERCASE_SCRIPTS.add(LANGUAGE_NEPALI); UPPERCASE_SCRIPTS.add(SCRIPT_ARMENIAN);
} }
public static boolean scriptSupportsUppercase(String language) { public static boolean scriptSupportsUppercase(Locale locale) {
return !NON_UPPERCASE_SCRIPTS.contains(language); return UPPERCASE_SCRIPTS.contains(getScriptFromSpellCheckerLocale(locale));
} }
/* /*
@ -217,8 +206,8 @@ public class ScriptUtils {
* {@see http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes} * {@see http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes}
*/ */
public static int getScriptFromSpellCheckerLocale(final Locale locale) { public static int getScriptFromSpellCheckerLocale(final Locale locale) {
// need special treatment of serbian latin, which would get detected as cyrillic // need special treatment of serbian latin and hinglish, which would get detected as cyrillic /
if (locale.toString().toLowerCase(Locale.ENGLISH).equals("sr_zz")) if (locale.toString().toLowerCase(Locale.ENGLISH).endsWith("_zz"))
return ScriptUtils.SCRIPT_LATIN; return ScriptUtils.SCRIPT_LATIN;
String language = locale.getLanguage(); String language = locale.getLanguage();
Integer script = mLanguageCodeToScriptCode.get(language); Integer script = mLanguageCodeToScriptCode.get(language);