Map ISO 15924 codes to internal IME script codes.
This way we can support all the languages for which we define a script code. Bug 19340741. Change-Id: Ia80eca4cc2511b70f11058f73bd31746948ded19main
parent
4084fa5cae
commit
98596e51a1
|
@ -23,9 +23,10 @@ import java.util.TreeMap;
|
||||||
* A class to help with handling different writing scripts.
|
* A class to help with handling different writing scripts.
|
||||||
*/
|
*/
|
||||||
public class ScriptUtils {
|
public class ScriptUtils {
|
||||||
|
|
||||||
// Used for hardware keyboards
|
// Used for hardware keyboards
|
||||||
public static final int SCRIPT_UNKNOWN = -1;
|
public static final int SCRIPT_UNKNOWN = -1;
|
||||||
// TODO: should we use ISO 15924 identifiers instead?
|
|
||||||
public static final int SCRIPT_ARABIC = 0;
|
public static final int SCRIPT_ARABIC = 0;
|
||||||
public static final int SCRIPT_ARMENIAN = 1;
|
public static final int SCRIPT_ARMENIAN = 1;
|
||||||
public static final int SCRIPT_BENGALI = 2;
|
public static final int SCRIPT_BENGALI = 2;
|
||||||
|
@ -44,34 +45,29 @@ public class ScriptUtils {
|
||||||
public static final int SCRIPT_TAMIL = 15;
|
public static final int SCRIPT_TAMIL = 15;
|
||||||
public static final int SCRIPT_TELUGU = 16;
|
public static final int SCRIPT_TELUGU = 16;
|
||||||
public static final int SCRIPT_THAI = 17;
|
public static final int SCRIPT_THAI = 17;
|
||||||
public static final TreeMap<String, Integer> mSpellCheckerLanguageToScript;
|
|
||||||
|
private static final TreeMap<String, Integer> mIso15924toImeScriptCode;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// List of the supported languages and their associated script. We won't check
|
mIso15924toImeScriptCode = new TreeMap<>();
|
||||||
// words written in another script than the selected script, because we know we
|
mIso15924toImeScriptCode.put("Arab", SCRIPT_ARABIC);
|
||||||
// don't have those in our dictionary so we will underline everything and we
|
mIso15924toImeScriptCode.put("Armn", SCRIPT_ARMENIAN);
|
||||||
// will never have any suggestions, so it makes no sense checking them, and this
|
mIso15924toImeScriptCode.put("Beng", SCRIPT_BENGALI);
|
||||||
// is done in {@link #shouldFilterOut}. Also, the script is used to choose which
|
mIso15924toImeScriptCode.put("Cyrl", SCRIPT_CYRILLIC);
|
||||||
// proximity to pass to the dictionary descent algorithm.
|
mIso15924toImeScriptCode.put("Deva", SCRIPT_DEVANAGARI);
|
||||||
// IMPORTANT: this only contains languages - do not write countries in there.
|
mIso15924toImeScriptCode.put("Geor", SCRIPT_GEORGIAN);
|
||||||
// Only the language is searched from the map.
|
mIso15924toImeScriptCode.put("Grek", SCRIPT_GREEK);
|
||||||
mSpellCheckerLanguageToScript = new TreeMap<>();
|
mIso15924toImeScriptCode.put("Hebr", SCRIPT_HEBREW);
|
||||||
mSpellCheckerLanguageToScript.put("cs", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Knda", SCRIPT_KANNADA);
|
||||||
mSpellCheckerLanguageToScript.put("da", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Khmr", SCRIPT_KHMER);
|
||||||
mSpellCheckerLanguageToScript.put("de", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Laoo", SCRIPT_LAO);
|
||||||
mSpellCheckerLanguageToScript.put("el", SCRIPT_GREEK);
|
mIso15924toImeScriptCode.put("Latn", SCRIPT_LATIN);
|
||||||
mSpellCheckerLanguageToScript.put("en", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Mlym", SCRIPT_MALAYALAM);
|
||||||
mSpellCheckerLanguageToScript.put("es", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Mymr", SCRIPT_MYANMAR);
|
||||||
mSpellCheckerLanguageToScript.put("fi", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Sinh", SCRIPT_SINHALA);
|
||||||
mSpellCheckerLanguageToScript.put("fr", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Taml", SCRIPT_TAMIL);
|
||||||
mSpellCheckerLanguageToScript.put("hr", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Telu", SCRIPT_TELUGU);
|
||||||
mSpellCheckerLanguageToScript.put("it", SCRIPT_LATIN);
|
mIso15924toImeScriptCode.put("Thai", SCRIPT_THAI);
|
||||||
mSpellCheckerLanguageToScript.put("lt", SCRIPT_LATIN);
|
|
||||||
mSpellCheckerLanguageToScript.put("lv", SCRIPT_LATIN);
|
|
||||||
mSpellCheckerLanguageToScript.put("nb", SCRIPT_LATIN);
|
|
||||||
mSpellCheckerLanguageToScript.put("nl", SCRIPT_LATIN);
|
|
||||||
mSpellCheckerLanguageToScript.put("pt", SCRIPT_LATIN);
|
|
||||||
mSpellCheckerLanguageToScript.put("sl", SCRIPT_LATIN);
|
|
||||||
mSpellCheckerLanguageToScript.put("ru", SCRIPT_CYRILLIC);
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Returns whether the code point is a letter that makes sense for the specified
|
* Returns whether the code point is a letter that makes sense for the specified
|
||||||
|
@ -181,12 +177,17 @@ public class ScriptUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param locale spell checker locale
|
||||||
|
* @return internal Latin IME script code that maps to an ISO 15924 script code
|
||||||
|
* {@see http://unicode.org/iso15924/iso15924-codes.html}
|
||||||
|
*/
|
||||||
public static int getScriptFromSpellCheckerLocale(final Locale locale) {
|
public static int getScriptFromSpellCheckerLocale(final Locale locale) {
|
||||||
final Integer script = mSpellCheckerLanguageToScript.get(locale.getLanguage());
|
String isoScriptCode = locale.getScript();
|
||||||
if (null == script) {
|
Integer imeScriptCode = mIso15924toImeScriptCode.get(isoScriptCode);
|
||||||
throw new RuntimeException("We have been called with an unsupported language: \""
|
if (imeScriptCode == null) {
|
||||||
+ locale.getLanguage() + "\". Framework bug?");
|
throw new RuntimeException("Unsupported ISO 15924 code: " + isoScriptCode);
|
||||||
}
|
}
|
||||||
return script;
|
return imeScriptCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue