summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-12-01 05:29:20 +0100
committerandroid-build-merger <android-build-merger@google.com>2018-12-01 05:29:20 +0100
commite633849dc9c49f0168c97fbea3503cd503fd0cf4 (patch)
treeccbce6408daef0d1c5f82303fa1ab58a9fa68757
parentMerge "SYSTEM_ROOT -> get_system_root" am: cbfeb7f6af am: fe00ae099c (diff)
parentMerge "ImageGenerator: ignore the duplicate locales" am: 7846823125 (diff)
downloadandroid_bootable_recovery-e633849dc9c49f0168c97fbea3503cd503fd0cf4.tar
android_bootable_recovery-e633849dc9c49f0168c97fbea3503cd503fd0cf4.tar.gz
android_bootable_recovery-e633849dc9c49f0168c97fbea3503cd503fd0cf4.tar.bz2
android_bootable_recovery-e633849dc9c49f0168c97fbea3503cd503fd0cf4.tar.lz
android_bootable_recovery-e633849dc9c49f0168c97fbea3503cd503fd0cf4.tar.xz
android_bootable_recovery-e633849dc9c49f0168c97fbea3503cd503fd0cf4.tar.zst
android_bootable_recovery-e633849dc9c49f0168c97fbea3503cd503fd0cf4.zip
-rw-r--r--tools/image_generator/ImageGenerator.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/tools/image_generator/ImageGenerator.java b/tools/image_generator/ImageGenerator.java
index 50a498456..fd8e54295 100644
--- a/tools/image_generator/ImageGenerator.java
+++ b/tools/image_generator/ImageGenerator.java
@@ -41,6 +41,7 @@ import java.io.IOException;
import java.text.AttributedString;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@@ -605,11 +606,15 @@ public class ImageGenerator {
mDefaultFont = defaultFontMetrics.getFont();
mAndroidStringWidth = defaultFontMetrics.stringWidth(ANDROID_STRING);
- Map<String, Integer> languageCount = new TreeMap<>();
+ // The last country variant should be the fallback locale for a given language.
+ Map<String, Locale> fallbackLocaleMap = new HashMap<>();
int textWidth = 0;
for (Locale locale : localizedTextMap.keySet()) {
- String language = locale.getLanguage();
- languageCount.put(language, languageCount.getOrDefault(language, 0) + 1);
+ // Updates the fallback locale if we have a new language variant. Don't do it for en-XC
+ // as it's a pseudo-locale.
+ if (!locale.toLanguageTag().equals("en-XC")) {
+ fallbackLocaleMap.put(locale.getLanguage(), locale);
+ }
textWidth = Math.max(textWidth, measureTextWidth(localizedTextMap.get(locale), locale));
}
@@ -617,15 +622,16 @@ public class ImageGenerator {
resize(textWidth, mImageHeight);
for (Locale locale : localizedTextMap.keySet()) {
- Integer count = languageCount.get(locale.getLanguage());
// Recovery expects en-US instead of en_US.
String languageTag = locale.toLanguageTag();
- if (count == 1) {
- // Make the last country variant for a given language be the catch-all for that
+ Locale fallbackLocale = fallbackLocaleMap.get(locale.getLanguage());
+ if (locale.equals(fallbackLocale)) {
+ // Makes the last country variant for a given language be the catch-all for that
// language.
languageTag = locale.getLanguage();
- } else {
- languageCount.put(locale.getLanguage(), count - 1);
+ } else if (localizedTextMap.get(locale).equals(localizedTextMap.get(fallbackLocale))) {
+ LOGGER.info("Skip parsing text for duplicate locale " + locale);
+ continue;
}
drawText(localizedTextMap.get(locale), locale, languageTag);