add language tags to method.xml (using language codes and python module langcodes)

This commit is contained in:
Helium314 2023-09-25 15:22:30 +02:00
parent e6495f5868
commit 7074302798
3 changed files with 103 additions and 11 deletions

View file

@ -262,7 +262,9 @@ private const val SUBTYPE_SEPARATOR = ";"
private const val LOCALE_LAYOUT_SEPARATOR = ":"
@Suppress("deprecation") // it's deprecated, but no replacement for API < 24
// todo: add language tags in method.xml, and adjust this method to use locale only if necessary
// but then language tag should be converted to locale, or other way!
// todo: subtypes should now have language tags -> use them for api >= 24
// but only replace subtype-related usage, otherwise the api mess will be horrible
// maybe rather return a locale instead of a string...
// is this acceptable for performance? any place where there are many call to locale()?
// see also InputMethodSubtypeCompatUtils
fun InputMethodSubtype.locale() = locale

View file

@ -16,12 +16,14 @@
package org.dslul.openboard.inputmethod.latin.utils;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.inputmethod.InputMethodSubtype;
import org.dslul.openboard.inputmethod.annotations.UsedForTesting;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils;
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
import java.util.ArrayList;
@ -64,7 +66,7 @@ public final class AdditionalSubtypeUtils {
localeString, keyboardLayoutSetName, isAsciiCapable, isEmojiCapable);
final int platformVersionIndependentSubtypeId =
getPlatformVersionIndependentSubtypeId(localeString, keyboardLayoutSetName);
return new InputMethodSubtype.InputMethodSubtypeBuilder()
final InputMethodSubtype.InputMethodSubtypeBuilder builder = new InputMethodSubtype.InputMethodSubtypeBuilder()
.setSubtypeNameResId(nameId)
.setSubtypeIconResId(R.drawable.ic_ime_switcher_dark)
.setSubtypeLocale(localeString)
@ -73,8 +75,10 @@ public final class AdditionalSubtypeUtils {
.setIsAuxiliary(false)
.setOverridesImplicitlyEnabledSubtype(false)
.setSubtypeId(platformVersionIndependentSubtypeId)
.setIsAsciiCapable(isAsciiCapable)
.build();
.setIsAsciiCapable(isAsciiCapable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builder.setLanguageTag(LocaleUtils.constructLocaleFromString(localeString).toLanguageTag());
return builder.build();
}
public static InputMethodSubtype createDummyAdditionalSubtype(