From a96ede25798b4fe58e52801967bdd8c994d0839f Mon Sep 17 00:00:00 2001 From: Chirayu Desai Date: Sun, 5 May 2013 19:35:45 +0530 Subject: aapt: add check for untranslatable "string-array"s Change-Id: Id884af0505c0bcdfa20b400fcdd54f699f8ef38f Signed-off-by: Chirayu Desai --- tools/aapt/ResourceTable.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index 889883a..fb0299e 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -1467,6 +1467,11 @@ status_t compileResourceFile(Bundle* bundle, } } } else if (strcmp16(block.getElementName(&len), string_array16.string()) == 0) { + // Note the existence and locale of every string array we process + char rawLocale[RESTABLE_MAX_LOCALE_LEN]; + curParams.getBcp47Locale(rawLocale); + String8 locale(rawLocale); + String16 name; // Check whether these strings need valid formats. // (simplified form of what string16 does above) bool isTranslatable = false; @@ -1477,7 +1482,9 @@ status_t compileResourceFile(Bundle* bundle, for (size_t i = 0; i < n; i++) { size_t length; const char16_t* attr = block.getAttributeName(i, &length); - if (strcmp16(attr, formatted16.string()) == 0) { + if (strcmp16(attr, name16.string()) == 0) { + name.setTo(block.getAttributeStringValue(i, &length)); + } else if (strcmp16(attr, formatted16.string()) == 0) { const char16_t* value = block.getAttributeStringValue(i, &length); if (strcmp16(value, false16.string()) == 0) { curIsFormatted = false; @@ -1486,6 +1493,15 @@ status_t compileResourceFile(Bundle* bundle, const char16_t* value = block.getAttributeStringValue(i, &length); if (strcmp16(value, false16.string()) == 0) { isTranslatable = false; + // Untranslatable string arrays must only exist + // in the default [empty] locale + if (locale.size() > 0) { + SourcePos(in->getPrintableSource(), block.getLineNumber()).warning( + "string-array '%s' marked untranslatable but exists" + " in locale '%s'\n", String8(name).string(), + locale.string()); + // hasErrors = localHasErrors = true; + } } } } -- cgit v1.1