Merge "ImageGenerator: ignore the duplicate locales"
am: 7846823125
Change-Id: I8a50e53fa5da77f264bc45fcbe51f9f0308b3e3d
This commit is contained in:
@@ -41,6 +41,7 @@ import java.io.IOException;
|
|||||||
import java.text.AttributedString;
|
import java.text.AttributedString;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -605,11 +606,15 @@ public class ImageGenerator {
|
|||||||
mDefaultFont = defaultFontMetrics.getFont();
|
mDefaultFont = defaultFontMetrics.getFont();
|
||||||
mAndroidStringWidth = defaultFontMetrics.stringWidth(ANDROID_STRING);
|
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;
|
int textWidth = 0;
|
||||||
for (Locale locale : localizedTextMap.keySet()) {
|
for (Locale locale : localizedTextMap.keySet()) {
|
||||||
String language = locale.getLanguage();
|
// Updates the fallback locale if we have a new language variant. Don't do it for en-XC
|
||||||
languageCount.put(language, languageCount.getOrDefault(language, 0) + 1);
|
// 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));
|
textWidth = Math.max(textWidth, measureTextWidth(localizedTextMap.get(locale), locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,15 +622,16 @@ public class ImageGenerator {
|
|||||||
resize(textWidth, mImageHeight);
|
resize(textWidth, mImageHeight);
|
||||||
|
|
||||||
for (Locale locale : localizedTextMap.keySet()) {
|
for (Locale locale : localizedTextMap.keySet()) {
|
||||||
Integer count = languageCount.get(locale.getLanguage());
|
|
||||||
// Recovery expects en-US instead of en_US.
|
// Recovery expects en-US instead of en_US.
|
||||||
String languageTag = locale.toLanguageTag();
|
String languageTag = locale.toLanguageTag();
|
||||||
if (count == 1) {
|
Locale fallbackLocale = fallbackLocaleMap.get(locale.getLanguage());
|
||||||
// Make the last country variant for a given language be the catch-all for that
|
if (locale.equals(fallbackLocale)) {
|
||||||
|
// Makes the last country variant for a given language be the catch-all for that
|
||||||
// language.
|
// language.
|
||||||
languageTag = locale.getLanguage();
|
languageTag = locale.getLanguage();
|
||||||
} else {
|
} else if (localizedTextMap.get(locale).equals(localizedTextMap.get(fallbackLocale))) {
|
||||||
languageCount.put(locale.getLanguage(), count - 1);
|
LOGGER.info("Skip parsing text for duplicate locale " + locale);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawText(localizedTextMap.get(locale), locale, languageTag);
|
drawText(localizedTextMap.get(locale), locale, languageTag);
|
||||||
|
|||||||
Reference in New Issue
Block a user