summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-03-05 18:42:23 +0000
committerNarayan Kamath <narayan@google.com>2014-06-13 19:03:13 +0100
commite79c8ce682173671a9b086004bf4753169ca34c3 (patch)
tree3df42e3b2376d1a77b4c7d2c3e65325eb5cf4eae /core/java
parent77d28ca25378530f92d409fbd72a38a1e256b59f (diff)
Support deprecated language codes.
Locale.toLanguageTag will transform the obsolete (and deprecated) language codes "in", "ji" and "iw" to "id", "yi" and "he" respectively. All versions of android prior to "L" used the deprecated language tags, so we will need to support them for backwards compatibility. bug: 13230947 (cherry-picked from commit 21fc8ba39c4799a346caf95) (also contains a partial cherry-pick of 857ba4af because including it is the easiest way to avoid conflicts.) Change-Id: Ia1d0f2d8e20f5679ff3990506f6468ebf789c94a
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/res/Resources.java43
1 files changed, 42 insertions, 1 deletions
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 3d9daca6dedf..3db9ddb673aa 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -1569,7 +1569,7 @@ public class Resources {
String locale = null;
if (mConfiguration.locale != null) {
- locale = mConfiguration.locale.toLanguageTag();
+ locale = adjustLanguageTag(localeToLanguageTag(mConfiguration.locale));
}
int width, height;
if (mMetrics.widthPixels >= mMetrics.heightPixels) {
@@ -1650,6 +1650,47 @@ public class Resources {
}
}
+ // Locale.toLanguageTag() is not available in Java6. LayoutLib overrides
+ // this method to enable users to use Java6.
+ private String localeToLanguageTag(Locale locale) {
+ return locale.toLanguageTag();
+ }
+
+ /**
+ * {@code Locale.toLanguageTag} will transform the obsolete (and deprecated)
+ * language codes "in", "ji" and "iw" to "id", "yi" and "he" respectively.
+ *
+ * All released versions of android prior to "L" used the deprecated language
+ * tags, so we will need to support them for backwards compatibility.
+ *
+ * Note that this conversion needs to take place *after* the call to
+ * {@code toLanguageTag} because that will convert all the deprecated codes to
+ * the new ones, even if they're set manually.
+ */
+ private static String adjustLanguageTag(String languageTag) {
+ final int separator = languageTag.indexOf('-');
+ final String language;
+ final String remainder;
+
+ if (separator == -1) {
+ language = languageTag;
+ remainder = "";
+ } else {
+ language = languageTag.substring(0, separator);
+ remainder = languageTag.substring(separator);
+ }
+
+ if ("id".equals(language)) {
+ return "in" + remainder;
+ } else if ("yi".equals(language)) {
+ return "ji" + remainder;
+ } else if ("he".equals(language)) {
+ return "iw" + remainder;
+ } else {
+ return languageTag;
+ }
+ }
+
/**
* Update the system resources configuration if they have previously
* been initialized.