Fix aapt2 pseudo-translating donottranslate* files
Bug: 126423638
Test: After building android doing this in the 'out' folder:
Test:
Test: ./soong/host/linux-x86/bin/aapt d --values resources \
Test: ./target/product/sailfish/system/product/priv-app/SystemUIGoogle/SystemUIGoogle.apk \
Test: | less
Test:
Test: search for `system_ui_aod_date_pattern` in the output, found this:
Test: (string8) "[éééḾḾḾð one two]"
Test: (string8) "<U+200F><U+202E>eeeMMMd<U+202C><U+200F>"
Test: (the en-XA and ar-XB pseudo-translated versions of the string)
Test:
Test: After the fix and rebuild the dump only finds the original English string ("eeeMMMd")
Test: Also flashed the image, switched to en-XA, and left the phone around for more than 24 hours.
Change-Id: I2fb7c5b5ee7d3d3200410593346682ed16559056
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 2ec1ab3..9b81369f 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -143,6 +143,8 @@
const ResourcePathData& path_data, io::IFile* file, IArchiveWriter* writer,
const std::string& output_path) {
TRACE_CALL();
+ // Filenames starting with "donottranslate" are not localizable
+ bool translatable_file = path_data.name.find("donottranslate") != 0;
ResourceTable table;
{
auto fin = file->OpenInputStream();
@@ -157,9 +159,7 @@
ResourceParserOptions parser_options;
parser_options.error_on_positional_arguments = !options.legacy_mode;
-
- // If the filename includes donottranslate, then the default translatable is false.
- parser_options.translatable = path_data.name.find("donottranslate") == std::string::npos;
+ parser_options.translatable = translatable_file;
// If visibility was forced, we need to use it when creating a new resource and also error if
// we try to parse the <public>, <public-group>, <java-symbol> or <symbol> tags.
@@ -172,7 +172,7 @@
}
}
- if (options.pseudolocalize) {
+ if (options.pseudolocalize && translatable_file) {
// Generate pseudo-localized strings (en-XA and ar-XB).
// These are created as weak symbols, and are only generated from default
// configuration