Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Launcher: locale takes tags with a script or extensions, such as ar-EG-u-nu-latn

Abdallah Emad3ac0dcc6f178
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/LauncherLocale.java b/launcher/app/src/main/java/com/gathin/tvhome/LauncherLocale.java
index 4bfeb0d1c..f46e599ef 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/LauncherLocale.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/LauncherLocale.java
@@ -11,12 +11,13 @@ import java.util.regex.Pattern;
* Each activity wraps its base context here; an empty or malformed tag leaves the TV's language.
*/
final class LauncherLocale {
- private static final Pattern TAG = Pattern.compile("[a-z]{2,3}(-[A-Za-z0-9]{2,8})?");
+ // Subtags after the language, so "sr-Latn" and "ar-EG-u-nu-latn" (Arabic with Western digits) pass too.
+ private static final Pattern TAG = Pattern.compile("[a-z]{2,3}(-[A-Za-z0-9]{1,8})*");
private LauncherLocale() {
}
- /** The Locale for a config tag such as "vi" or "pt-BR", or null for "" or anything that is not a plain tag. */
+ /** The Locale for a config tag such as "vi", "pt-BR" or "ar-EG-u-nu-latn", or null for "" or anything that is not a plain tag. */
static Locale parse(String tag) {
if (tag == null || !TAG.matcher(tag.trim()).matches()) return null;
return Locale.forLanguageTag(tag.trim());
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index a9987423b..30a5bd9d7 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -234,7 +234,8 @@
<!-- The date (with the Shamsi and lunar lines) on its own line under the clock instead of beside it, for a top bar
whose pills leave the date too little room. Can also be set with "date_below_clock" in a theme. -->
<bool name="date_below_clock">false</bool>
- <!-- The language the launcher shows itself in, as a language tag ("vi", "pt-BR"), instead of the TV's. For firmware
+ <!-- The language the launcher shows itself in, as a language tag ("vi", "pt-BR", "ar-EG-u-nu-latn"
+ for Arabic with Western digits), instead of the TV's. For firmware
that has no menu entry for the owner's language although the launcher is translated into it (a China-market
Xiaomi offers Chinese and English only). Empty, the default, follows the TV. A theme can set it ("locale"). -->
<string name="locale" translatable="false"></string>
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/LauncherLocaleTest.java b/launcher/app/src/test/java/com/gathin/tvhome/LauncherLocaleTest.java
index b924582d4..558665765 100644
--- a/launcher/app/src/test/java/com/gathin/tvhome/LauncherLocaleTest.java
+++ b/launcher/app/src/test/java/com/gathin/tvhome/LauncherLocaleTest.java
@@ -13,6 +13,13 @@ public class LauncherLocaleTest {
assertEquals("fil", LauncherLocale.parse(" fil ").getLanguage());
}
+ @Test
+ public void tagsWithScriptsAndExtensionsBecomeLocales() {
+ assertEquals("Latn", LauncherLocale.parse("sr-Latn").getScript());
+ assertEquals("ar", LauncherLocale.parse("ar-EG-u-nu-latn").getLanguage());
+ assertEquals("latn", LauncherLocale.parse("ar-EG-u-nu-latn").getUnicodeLocaleType("nu"));
+ }
+
@Test
public void emptyOrMalformedTagsFollowTheTv() {
assertNull(LauncherLocale.parse(""));
@@ -20,5 +27,7 @@ public class LauncherLocaleTest {
assertNull(LauncherLocale.parse("Vietnamese"));
assertNull(LauncherLocale.parse("vi_VN"));
assertNull(LauncherLocale.parse("../vi"));
+ assertNull(LauncherLocale.parse("vi-"));
+ assertNull(LauncherLocale.parse("vi--VN"));
}
}
diff --git a/themes/README.md b/themes/README.md
index 0b416c67a..ceb0f8e73 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -85,7 +85,7 @@ A new key needs one there in the same pull request.
| `lunar_date` | bool | Show the lunisolar date under the Gregorian one, e.g. `LUNAR 13/9 · YEAR OF THE HORSE`, or `13/9 ÂM LỊCH · BÍNH NGỌ` in Vietnamese; a leap month is marked. Off by default |
| `lunar_utc_offset` | 0 to 14 | Hours east of UTC the lunar calendar is computed for: `7` is the Vietnamese calendar, `8` the Chinese one; they differ by a day now and then (and by a month in 1985). Unset: 7 when the TV is in Vietnamese, 8 otherwise |
| `date_below_clock` | bool | The date (with the Shamsi and lunar lines) on its own line under the clock instead of beside it, for a top bar whose pills leave the date too little room (`false` by default) |
-| `locale` | string | The language the launcher shows itself in, as a language tag (`"vi"`, `"pt-BR"`), instead of the TV's: for firmware with no menu entry for a language the launcher speaks (a China-market Xiaomi offers Chinese and English only). Empty by default, which follows the TV |
+| `locale` | string | The language the launcher shows itself in, as a language tag (`"vi"`, `"pt-BR"`, `"ar-EG-u-nu-latn"` for Arabic with Western digits), instead of the TV's: for firmware with no menu entry for a language the launcher speaks (a China-market Xiaomi offers Chinese and English only). Empty by default, which follows the TV |
| `greeting_name` | string | A name after the greeting, e.g. `"Mr. Trịnh"` for GOOD MORNING, MR. TRỊNH; empty for the greeting alone |
| `show_greeting` | bool | The greeting above the clock (`true` by default); `false` hides it |
| `header_white` | bool | The date and the line between the clock and the date in the clock's full white instead of dimmed (`false` by default) |