Merge "Get nicer output of make-keyboard-text"
commit
d495cc36b7
|
@ -3476,60 +3476,61 @@ public final class KeyboardTextsTable {
|
||||||
// TODO: Use the language + "_" + region representation for the locale string key.
|
// TODO: Use the language + "_" + region representation for the locale string key.
|
||||||
// Currently we are dropping the region from the key.
|
// Currently we are dropping the region from the key.
|
||||||
private static final Object[] LANGUAGES_AND_TEXTS = {
|
private static final Object[] LANGUAGES_AND_TEXTS = {
|
||||||
"DEFAULT", LANGUAGE_DEFAULT, /* default */
|
// "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */
|
||||||
"af", LANGUAGE_af, /* Afrikaans */
|
"DEFAULT", LANGUAGE_DEFAULT, /* 156/156 default */
|
||||||
"ar", LANGUAGE_ar, /* Arabic */
|
"af", LANGUAGE_af, /* 8/ 9 Afrikaans */
|
||||||
"az" /* "az_AZ" */, LANGUAGE_az_AZ, /* Azerbaijani (Azerbaijan) */
|
"ar", LANGUAGE_ar, /* 48/119 Arabic */
|
||||||
"be" /* "be_BY" */, LANGUAGE_be_BY, /* Belarusian (Belarus) */
|
"az", LANGUAGE_az_AZ, /* 8/ 16 Azerbaijani (Azerbaijan) */
|
||||||
"bg", LANGUAGE_bg, /* Bulgarian */
|
"be", LANGUAGE_be_BY, /* 10/ 54 Belarusian (Belarus) */
|
||||||
"ca", LANGUAGE_ca, /* Catalan */
|
"bg", LANGUAGE_bg, /* 2/ 54 Bulgarian */
|
||||||
"cs", LANGUAGE_cs, /* Czech */
|
"ca", LANGUAGE_ca, /* 11/126 Catalan */
|
||||||
"da", LANGUAGE_da, /* Danish */
|
"cs", LANGUAGE_cs, /* 17/ 56 Czech */
|
||||||
"de", LANGUAGE_de, /* German */
|
"da", LANGUAGE_da, /* 19/ 56 Danish */
|
||||||
"el", LANGUAGE_el, /* Greek */
|
"de", LANGUAGE_de, /* 16/ 56 German */
|
||||||
"en", LANGUAGE_en, /* English */
|
"el", LANGUAGE_el, /* 1/ 52 Greek */
|
||||||
"eo", LANGUAGE_eo, /* Esperanto */
|
"en", LANGUAGE_en, /* 8/ 8 English */
|
||||||
"es", LANGUAGE_es, /* Spanish */
|
"eo", LANGUAGE_eo, /* 26/126 Esperanto */
|
||||||
"et" /* "et_EE" */, LANGUAGE_et_EE, /* Estonian (Estonia) */
|
"es", LANGUAGE_es, /* 8/ 60 Spanish */
|
||||||
"fa", LANGUAGE_fa, /* Persian */
|
"et", LANGUAGE_et_EE, /* 22/ 54 Estonian (Estonia) */
|
||||||
"fi", LANGUAGE_fi, /* Finnish */
|
"fa", LANGUAGE_fa, /* 49/119 Persian */
|
||||||
"fr", LANGUAGE_fr, /* French */
|
"fi", LANGUAGE_fi, /* 10/ 25 Finnish */
|
||||||
"hi", LANGUAGE_hi, /* Hindi */
|
"fr", LANGUAGE_fr, /* 13/ 51 French */
|
||||||
"hr", LANGUAGE_hr, /* Croatian */
|
"hi", LANGUAGE_hi, /* 24/ 91 Hindi */
|
||||||
"hu", LANGUAGE_hu, /* Hungarian */
|
"hr", LANGUAGE_hr, /* 9/ 56 Croatian */
|
||||||
"hy" /* "hy_AM" */, LANGUAGE_hy_AM, /* Armenian (Armenia) */
|
"hu", LANGUAGE_hu, /* 9/ 56 Hungarian */
|
||||||
"is", LANGUAGE_is, /* Icelandic */
|
"hy", LANGUAGE_hy_AM, /* 7/117 Armenian (Armenia) */
|
||||||
"it", LANGUAGE_it, /* Italian */
|
"is", LANGUAGE_is, /* 13/ 54 Icelandic */
|
||||||
"iw", LANGUAGE_iw, /* Hebrew */
|
"it", LANGUAGE_it, /* 5/ 5 Italian */
|
||||||
"ka" /* "ka_GE" */, LANGUAGE_ka_GE, /* Georgian (Georgia) */
|
"iw", LANGUAGE_iw, /* 14/ 68 Hebrew */
|
||||||
"kk", LANGUAGE_kk, /* Kazakh */
|
"ka", LANGUAGE_ka_GE, /* 3/ 54 Georgian (Georgia) */
|
||||||
"km" /* "km_KH" */, LANGUAGE_km_KH, /* Khmer (Cambodia) */
|
"kk", LANGUAGE_kk, /* 16/ 52 Kazakh */
|
||||||
"ky", LANGUAGE_ky, /* Kirghiz */
|
"km", LANGUAGE_km_KH, /* 2/ 57 Khmer (Cambodia) */
|
||||||
"lo" /* "lo_LA" */, LANGUAGE_lo_LA, /* Lao (Laos) */
|
"ky", LANGUAGE_ky, /* 11/ 52 Kirghiz */
|
||||||
"lt", LANGUAGE_lt, /* Lithuanian */
|
"lo", LANGUAGE_lo_LA, /* 2/ 58 Lao (Laos) */
|
||||||
"lv", LANGUAGE_lv, /* Latvian */
|
"lt", LANGUAGE_lt, /* 18/ 54 Lithuanian */
|
||||||
"mk", LANGUAGE_mk, /* Macedonian */
|
"lv", LANGUAGE_lv, /* 18/ 54 Latvian */
|
||||||
"mn" /* "mn_MN" */, LANGUAGE_mn_MN, /* Mongolian (Mongolia) */
|
"mk", LANGUAGE_mk, /* 9/ 54 Macedonian */
|
||||||
"nb", LANGUAGE_nb, /* Norwegian Bokmål */
|
"mn", LANGUAGE_mn_MN, /* 2/ 58 Mongolian (Mongolia) */
|
||||||
"ne" /* "ne_NP" */, LANGUAGE_ne_NP, /* Nepali (Nepal) */
|
"nb", LANGUAGE_nb, /* 11/ 54 Norwegian Bokmål */
|
||||||
"nl", LANGUAGE_nl, /* Dutch */
|
"ne", LANGUAGE_ne_NP, /* 24/ 91 Nepali (Nepal) */
|
||||||
"pl", LANGUAGE_pl, /* Polish */
|
"nl", LANGUAGE_nl, /* 9/ 54 Dutch */
|
||||||
"pt", LANGUAGE_pt, /* Portuguese */
|
"pl", LANGUAGE_pl, /* 10/ 54 Polish */
|
||||||
"rm", LANGUAGE_rm, /* Raeto-Romance */
|
"pt", LANGUAGE_pt, /* 6/ 8 Portuguese */
|
||||||
"ro", LANGUAGE_ro, /* Romanian */
|
"rm", LANGUAGE_rm, /* 1/ 4 Raeto-Romance */
|
||||||
"ru", LANGUAGE_ru, /* Russian */
|
"ro", LANGUAGE_ro, /* 6/ 54 Romanian */
|
||||||
"sk", LANGUAGE_sk, /* Slovak */
|
"ru", LANGUAGE_ru, /* 10/ 54 Russian */
|
||||||
"sl", LANGUAGE_sl, /* Slovenian */
|
"sk", LANGUAGE_sk, /* 20/ 56 Slovak */
|
||||||
"sr", LANGUAGE_sr, /* Serbian */
|
"sl", LANGUAGE_sl, /* 8/ 56 Slovenian */
|
||||||
"sv", LANGUAGE_sv, /* Swedish */
|
"sr", LANGUAGE_sr, /* 11/ 56 Serbian */
|
||||||
"sw", LANGUAGE_sw, /* Swahili */
|
"sv", LANGUAGE_sv, /* 21/ 56 Swedish */
|
||||||
"th", LANGUAGE_th, /* Thai */
|
"sw", LANGUAGE_sw, /* 9/ 16 Swahili */
|
||||||
"tl", LANGUAGE_tl, /* Tagalog */
|
"th", LANGUAGE_th, /* 2/ 58 Thai */
|
||||||
"tr", LANGUAGE_tr, /* Turkish */
|
"tl", LANGUAGE_tl, /* 7/ 8 Tagalog */
|
||||||
"uk", LANGUAGE_uk, /* Ukrainian */
|
"tr", LANGUAGE_tr, /* 7/ 16 Turkish */
|
||||||
"vi", LANGUAGE_vi, /* Vietnamese */
|
"uk", LANGUAGE_uk, /* 12/ 58 Ukrainian */
|
||||||
"zu", LANGUAGE_zu, /* Zulu */
|
"vi", LANGUAGE_vi, /* 8/ 58 Vietnamese */
|
||||||
"zz", LANGUAGE_zz, /* Alphabet */
|
"zu", LANGUAGE_zu, /* 8/ 8 Zulu */
|
||||||
|
"zz", LANGUAGE_zz, /* 19/ 20 Alphabet */
|
||||||
};
|
};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -77,6 +77,7 @@ public final class KeyboardTextsTable {
|
||||||
// TODO: Use the language + "_" + region representation for the locale string key.
|
// TODO: Use the language + "_" + region representation for the locale string key.
|
||||||
// Currently we are dropping the region from the key.
|
// Currently we are dropping the region from the key.
|
||||||
private static final Object[] LANGUAGES_AND_TEXTS = {
|
private static final Object[] LANGUAGES_AND_TEXTS = {
|
||||||
|
// "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */
|
||||||
/* @LANGUAGES_AND_TEXTS@ */
|
/* @LANGUAGES_AND_TEXTS@ */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,16 @@ public class ArrayInitializerFormatter {
|
||||||
private int mBufferedLen;
|
private int mBufferedLen;
|
||||||
private int mBufferedIndex = Integer.MIN_VALUE;
|
private int mBufferedIndex = Integer.MIN_VALUE;
|
||||||
|
|
||||||
public ArrayInitializerFormatter(PrintStream out, int width, String indent) {
|
public ArrayInitializerFormatter(final PrintStream out, final int width, final String indent) {
|
||||||
mOut = out;
|
mOut = out;
|
||||||
mMaxWidth = width - indent.length();
|
mMaxWidth = width - indent.length();
|
||||||
mIndent = indent;
|
mIndent = indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCurrentIndex() {
|
||||||
|
return mCurrentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
public void flush() {
|
public void flush() {
|
||||||
if (mBuffer.length() == 0) {
|
if (mBuffer.length() == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -59,13 +63,13 @@ public class ArrayInitializerFormatter {
|
||||||
mBufferedLen = 0;
|
mBufferedLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outCommentLines(String lines) {
|
public void outCommentLines(final String lines) {
|
||||||
flush();
|
flush();
|
||||||
mOut.print(lines);
|
mOut.print(lines);
|
||||||
mFixedElement = null;
|
mFixedElement = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outElement(String element) {
|
public void outElement(final String element) {
|
||||||
if (!element.equals(mFixedElement)) {
|
if (!element.equals(mFixedElement)) {
|
||||||
flush();
|
flush();
|
||||||
mBufferedIndex = mCurrentIndex;
|
mBufferedIndex = mCurrentIndex;
|
||||||
|
|
|
@ -38,7 +38,6 @@ public class MoreKeysResources {
|
||||||
private static final String MARK_TEXTS = "@TEXTS@";
|
private static final String MARK_TEXTS = "@TEXTS@";
|
||||||
private static final String MARK_LANGUAGES_AND_TEXTS = "@LANGUAGES_AND_TEXTS@";
|
private static final String MARK_LANGUAGES_AND_TEXTS = "@LANGUAGES_AND_TEXTS@";
|
||||||
private static final String DEFAULT_LANGUAGE_NAME = "DEFAULT";
|
private static final String DEFAULT_LANGUAGE_NAME = "DEFAULT";
|
||||||
private static final String ARRAY_NAME_FOR_LANGUAGE = "LANGUAGE_%s";
|
|
||||||
private static final String EMPTY_STRING_VAR = "EMPTY";
|
private static final String EMPTY_STRING_VAR = "EMPTY";
|
||||||
|
|
||||||
private static final String NO_LANGUAGE_CODE = "zz";
|
private static final String NO_LANGUAGE_CODE = "zz";
|
||||||
|
@ -144,7 +143,12 @@ public class MoreKeysResources {
|
||||||
|
|
||||||
private void dumpDefaultTexts(final PrintStream out) {
|
private void dumpDefaultTexts(final PrintStream out) {
|
||||||
final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME);
|
final StringResourceMap defaultResMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME);
|
||||||
dumpTextsInternal(out, defaultResMap, defaultResMap);
|
final int outputArraySize = dumpTextsInternal(out, defaultResMap, defaultResMap);
|
||||||
|
defaultResMap.setOutputArraySize(outputArraySize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getArrayNameForLanguage(final String language) {
|
||||||
|
return "LANGUAGE_" + language;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dumpTexts(final PrintStream out) {
|
private void dumpTexts(final PrintStream out) {
|
||||||
|
@ -157,8 +161,8 @@ public class MoreKeysResources {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
out.format(" /* Language %s: %s */\n", language, getLanguageDisplayName(language));
|
out.format(" /* Language %s: %s */\n", language, getLanguageDisplayName(language));
|
||||||
out.format(" private static final String[] " + ARRAY_NAME_FOR_LANGUAGE + " = {\n",
|
out.format(" private static final String[] " + getArrayNameForLanguage(language)
|
||||||
language);
|
+ " = {\n");
|
||||||
final StringResourceMap resMap = mResourcesMap.get(language);
|
final StringResourceMap resMap = mResourcesMap.get(language);
|
||||||
for (final StringResource res : resMap.getResources()) {
|
for (final StringResource res : resMap.getResources()) {
|
||||||
if (!defaultResMap.contains(res.mName)) {
|
if (!defaultResMap.contains(res.mName)) {
|
||||||
|
@ -166,7 +170,8 @@ public class MoreKeysResources {
|
||||||
+ " doesn't have default resource");
|
+ " doesn't have default resource");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dumpTextsInternal(out, resMap, defaultResMap);
|
final int outputArraySize = dumpTextsInternal(out, resMap, defaultResMap);
|
||||||
|
resMap.setOutputArraySize(outputArraySize);
|
||||||
out.format(" };\n\n");
|
out.format(" };\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,13 +181,15 @@ public class MoreKeysResources {
|
||||||
allLanguages.addAll(mResourcesMap.keySet());
|
allLanguages.addAll(mResourcesMap.keySet());
|
||||||
Collections.sort(allLanguages);
|
Collections.sort(allLanguages);
|
||||||
for (final String language : allLanguages) {
|
for (final String language : allLanguages) {
|
||||||
|
final StringResourceMap resMap = mResourcesMap.get(language);
|
||||||
final Locale locale = LocaleUtils.constructLocaleFromString(language);
|
final Locale locale = LocaleUtils.constructLocaleFromString(language);
|
||||||
// If we use a different key, dump the original as comment for now.
|
|
||||||
final String languageKeyToDump = locale.getCountry().isEmpty()
|
final String languageKeyToDump = locale.getCountry().isEmpty()
|
||||||
? String.format("\"%s\"", language)
|
? String.format("\"%s\"", language)
|
||||||
: String.format("\"%s\" /* \"%s\" */", locale.getLanguage(), language);
|
: String.format("\"%s\"", locale.getLanguage());
|
||||||
out.format(" %s, " + ARRAY_NAME_FOR_LANGUAGE + ", /* %s */\n",
|
out.format(" %s, %-15s /* %3d/%3d %s */\n",
|
||||||
languageKeyToDump, language, getLanguageDisplayName(language));
|
languageKeyToDump, getArrayNameForLanguage(language) + ",",
|
||||||
|
resMap.getResources().size(), resMap.getOutputArraySize(),
|
||||||
|
getLanguageDisplayName(language));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,10 +201,11 @@ public class MoreKeysResources {
|
||||||
return locale.getDisplayName(Locale.ENGLISH);
|
return locale.getDisplayName(Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dumpTextsInternal(final PrintStream out, final StringResourceMap resMap,
|
private static int dumpTextsInternal(final PrintStream out, final StringResourceMap resMap,
|
||||||
final StringResourceMap defaultResMap) {
|
final StringResourceMap defaultResMap) {
|
||||||
final ArrayInitializerFormatter formatter =
|
final ArrayInitializerFormatter formatter =
|
||||||
new ArrayInitializerFormatter(out, 100, " ");
|
new ArrayInitializerFormatter(out, 100, " ");
|
||||||
|
int outputArraySize = 0;
|
||||||
boolean successiveNull = false;
|
boolean successiveNull = false;
|
||||||
for (final StringResource defaultRes : defaultResMap.getResources()) {
|
for (final StringResource defaultRes : defaultResMap.getResources()) {
|
||||||
if (resMap.contains(defaultRes.mName)) {
|
if (resMap.contains(defaultRes.mName)) {
|
||||||
|
@ -212,6 +220,7 @@ public class MoreKeysResources {
|
||||||
formatter.outElement(String.format("\"%s\",", escaped));
|
formatter.outElement(String.format("\"%s\",", escaped));
|
||||||
}
|
}
|
||||||
successiveNull = false;
|
successiveNull = false;
|
||||||
|
outputArraySize = formatter.getCurrentIndex();
|
||||||
} else {
|
} else {
|
||||||
formatter.outElement("null,");
|
formatter.outElement("null,");
|
||||||
successiveNull = true;
|
successiveNull = true;
|
||||||
|
@ -220,6 +229,7 @@ public class MoreKeysResources {
|
||||||
if (!successiveNull) {
|
if (!successiveNull) {
|
||||||
formatter.flush();
|
formatter.flush();
|
||||||
}
|
}
|
||||||
|
return outputArraySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String addPrefix(final String prefix, final String lines) {
|
private static String addPrefix(final String prefix, final String lines) {
|
||||||
|
|
|
@ -39,6 +39,12 @@ public class StringResourceMap {
|
||||||
// Name to string resource map.
|
// Name to string resource map.
|
||||||
private final Map<String, StringResource> mResourcesMap;
|
private final Map<String, StringResource> mResourcesMap;
|
||||||
|
|
||||||
|
// The length of String[] that is created from this {@link StringResourceMap}. The length is
|
||||||
|
// calculated in {@link MoreKeysResources#dumpTexts(OutputStream)} and recorded by
|
||||||
|
// {@link #setOutputArraySize(int)}. The recorded length is used as a part of comment by
|
||||||
|
// {@link MoreKeysResources#dumpLanguageMap(OutputStream)} via {@link #getOutputArraySize()}.
|
||||||
|
private int mOutputArraySize;
|
||||||
|
|
||||||
public StringResourceMap(final InputStream is) {
|
public StringResourceMap(final InputStream is) {
|
||||||
final StringResourceHandler handler = new StringResourceHandler();
|
final StringResourceHandler handler = new StringResourceHandler();
|
||||||
final SAXParserFactory factory = SAXParserFactory.newInstance();
|
final SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
|
@ -77,6 +83,14 @@ public class StringResourceMap {
|
||||||
return mResourcesMap.get(name);
|
return mResourcesMap.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOutputArraySize(final int arraySize) {
|
||||||
|
mOutputArraySize = arraySize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOutputArraySize() {
|
||||||
|
return mOutputArraySize;
|
||||||
|
}
|
||||||
|
|
||||||
static class StringResourceHandler extends DefaultHandler2 {
|
static class StringResourceHandler extends DefaultHandler2 {
|
||||||
private static final String TAG_RESOURCES = "resources";
|
private static final String TAG_RESOURCES = "resources";
|
||||||
private static final String TAG_STRING = "string";
|
private static final String TAG_STRING = "string";
|
||||||
|
|
Loading…
Reference in New Issue