Commit 77b7b359 authored by David 'Digit' Turner's avatar David 'Digit' Turner Committed by Commit Bot

Android: Fix resource extraction from splits for Hebrew and others.

This CL fixes a bug in the logic used to locate locale .pak files
inside bundle splits. The reason for the bug is that bundletool
wants to use deprecated language names (i.e. 'iw' instead of 'he')
to store asset files.

As an example, for Hebrew, Chrome was looking at:

  assets/locales#lang_he/he.pak

While the file was really stored under:

  assets/locales#lang_iw/he.pak

The CL fixes the issue for Hebrew, Yiddish and Indonesian and
Filipino.

BUG=902915
R=benmason@chromium.org, tiborg@chromium.org, yfriedman@chromium.org, twellington@chromium.org

Change-Id: I420158c30ba33c6203495af9453877722271e104
Reviewed-on: https://chromium-review.googlesource.com/c/1327203
Commit-Queue: David Turner <digit@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606866}
parent d7bfd5bb
......@@ -111,6 +111,33 @@ public class LocalizationUtils {
return uiLocale;
}
/**
* Return the asset split language associated with a given Chromium language.
*
* This matches the directory used to store language-based assets in bundle APK splits.
* E.g. for Hebrew, known as 'he' by Chromium, this method should return 'iw' because
* the .pak file will be stored as /assets/locales#lang_iw/he.pak within the split.
*
* @param language Chromium specific language name.
* @return Matching Android specific language name.
*/
public static String getSplitLanguageForAndroid(String language) {
// IMPORTANT: Keep in sync with the mapping found in:
// build/android/gyp/util/resource_utils.py
switch (language) {
case "he":
return "iw"; // Hebrew
case "yi":
return "ji"; // Yiddish
case "id":
return "in"; // Indonesian
case "fil":
return "tl"; // Filipino
default:
return language;
}
}
/**
* Return one default locale-specific PAK file name associated with a given language.
*
......
......@@ -180,7 +180,8 @@ public class ResourceExtractor {
//
AssetManager assetManager = ContextUtils.getApplicationAssets();
String localesSrcDir;
String langSpecificPath = COMPRESSED_LOCALES_DIR + "#lang_" + uiLanguage;
String androidSplitLanguage = LocalizationUtils.getSplitLanguageForAndroid(uiLanguage);
String langSpecificPath = COMPRESSED_LOCALES_DIR + "#lang_" + androidSplitLanguage;
String defaultLocalePakName =
LocalizationUtils.getDefaultCompressedPakLocaleForLanguage(uiLanguage) + ".pak";
......
......@@ -32,6 +32,17 @@ public class LocalizationUtilsTest {
assertEquals("zh-CN", LocalizationUtils.getDefaultCompressedPakLocaleForLanguage("zh"));
}
@Test
@SmallTest
public void testGetSplitLanguageForAndroid() {
assertEquals("en", LocalizationUtils.getSplitLanguageForAndroid("en"));
assertEquals("es", LocalizationUtils.getSplitLanguageForAndroid("es"));
assertEquals("fr", LocalizationUtils.getSplitLanguageForAndroid("fr"));
assertEquals("iw", LocalizationUtils.getSplitLanguageForAndroid("he"));
assertEquals("ji", LocalizationUtils.getSplitLanguageForAndroid("yi"));
assertEquals("tl", LocalizationUtils.getSplitLanguageForAndroid("fil"));
}
@Test
@SmallTest
public void testChromiumLocaleMatchesLanguage() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment