diff options
| author | Roozbeh Pournader <roozbeh@google.com> | 2016-06-17 22:13:12 -0700 |
|---|---|---|
| committer | Roozbeh Pournader <roozbeh@google.com> | 2016-06-17 22:24:54 -0700 |
| commit | 309ebd6430a7df246110f614966e614290d6486b (patch) | |
| tree | 11d76c527d22ca84f6db077a2f1ea29eef4bbeda /core/java/android | |
| parent | a65d8b660986520a8d7b6ec4c363ce13e4560667 (diff) | |
Fix AAPT-compatible output format for locales
The previous code used a format that is not supported by AAPT,
although it claimed it was. The new code generates locale codes in
the format AAPT can consume, using xx and xx-rYY for simple locales,
and the b+ format for everything else.
Bug: 25599046
Change-Id: I34d432f23b84913d313d6562c110d7fad87c457a
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/res/Configuration.java | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java index 6f43d99ecb95..b2d518c56ca0 100644 --- a/core/java/android/content/res/Configuration.java +++ b/core/java/android/content/res/Configuration.java @@ -1543,27 +1543,41 @@ public final class Configuration implements Parcelable, Comparable<Configuration * @hide */ public static String localesToResourceQualifier(LocaleList locs) { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < locs.size(); i++) { - Locale loc = locs.get(i); - boolean l = (loc.getLanguage().length() != 0); - boolean c = (loc.getCountry().length() != 0); - boolean s = (loc.getScript().length() != 0); - boolean v = (loc.getVariant().length() != 0); - // TODO: take script and extensions into account - if (l) { - if (sb.length() != 0) { - sb.append(","); - } + final Locale loc = locs.get(i); + final int l = loc.getLanguage().length(); + if (l == 0) { + continue; + } + final int s = loc.getScript().length(); + final int c = loc.getCountry().length(); + final int v = loc.getVariant().length(); + // We ignore locale extensions, since they are not supported by AAPT + + if (sb.length() != 0) { + sb.append(","); + } + if (l == 2 && s == 0 && (c == 0 || c == 2) && v == 0) { + // Traditional locale format: xx or xx-rYY sb.append(loc.getLanguage()); - if (c) { + if (c == 2) { sb.append("-r").append(loc.getCountry()); - if (s) { - sb.append("-s").append(loc.getScript()); - if (v) { - sb.append("-v").append(loc.getVariant()); - } - } + } + } else { + sb.append("b+"); + sb.append(loc.getLanguage()); + if (s != 0) { + sb.append("+"); + sb.append(loc.getScript()); + } + if (c != 0) { + sb.append("+"); + sb.append(loc.getCountry()); + } + if (v != 0) { + sb.append("+"); + sb.append(loc.getVariant()); } } } |
