Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: ui/android/java/src/org/chromium/ui/base/ResourceBundle.java

Issue 2369683002: Revert of Move language pak files to assets. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/base/ResourceBundle.java
diff --git a/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java b/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java
index f5907c673b4adac61c9254d8b0e4709dbc16b4a5..adbf8afac277330364f11daeafffa525c5224d7e 100644
--- a/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java
+++ b/ui/android/java/src/org/chromium/ui/base/ResourceBundle.java
@@ -4,14 +4,17 @@
package org.chromium.ui.base;
-import org.chromium.base.LocaleUtils;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+
+import org.chromium.base.ResourceExtractor;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.SuppressFBWarnings;
import java.io.File;
-import java.util.ArrayList;
import java.util.Locale;
/**
@@ -20,31 +23,54 @@
*/
@JNINamespace("ui")
public class ResourceBundle {
- private static final String ASSET_DIR = "assets";
- private static final String FALLBACK_LOCALE = "en-US";
- private static String[] sActiveLocaleResources;
+ private static ResourceExtractor.ResourceEntry[] sActiveLocaleResources;
/**
- * Initializes the list of locale packs for the active locale that are present within the apk.
+ * Applies the reverse mapping done by locale_pak_resources.py.
+ */
+ private static String toChromeLocaleName(String srcFileName) {
+ srcFileName = srcFileName.replace(".lpak", ".pak");
+ String[] parts = srcFileName.split("_");
+ if (parts.length > 1) {
+ int dotIdx = parts[1].indexOf('.');
+ return parts[0] + "-" + parts[1].substring(0, dotIdx).toUpperCase(Locale.ENGLISH)
+ + parts[1].substring(dotIdx);
+ }
+ return srcFileName;
+ }
+
+ /**
+ * Initializes the list of locale packs for the active locale that are
+ * present within the apk.
*
- * @param localePakFiles An array of pak filenames.
+ * @param context Any context
+ * @param localePaksResId Resource ID locale_paks (generated by
+ * locale_pak_resources.py)
*/
@SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC") // Not thread-safe.
- public static void initializeLocalePaks(String[] localePakFiles) {
+ public static void initializeLocalePaks(Context context, int localePaksResId) {
ThreadUtils.assertOnUiThread();
assert sActiveLocaleResources == null;
- String language = LocaleUtils.getLanguage(Locale.getDefault());
- ArrayList<String> activeLocalePakFiles = new ArrayList<String>(localePakFiles.length);
- for (String pakFileName : localePakFiles) {
- if (pakFileName.startsWith(language) || pakFileName.startsWith(FALLBACK_LOCALE)) {
- activeLocalePakFiles.add(pakFileName);
+ Resources resources = context.getResources();
+ TypedArray resIds = resources.obtainTypedArray(localePaksResId);
+ try {
+ int len = resIds.length();
+ sActiveLocaleResources = new ResourceExtractor.ResourceEntry[len];
+ for (int i = 0; i < len; ++i) {
+ int resId = resIds.getResourceId(i, 0);
+ String resPath = resources.getString(resId);
+ String srcBaseName = new File(resPath).getName();
+ String dstBaseName = toChromeLocaleName(srcBaseName);
+ sActiveLocaleResources[i] = new ResourceExtractor.ResourceEntry(resId, resPath,
+ dstBaseName);
}
+ } finally {
+ resIds.recycle();
}
- sActiveLocaleResources = activeLocalePakFiles.toArray(new String[0]);
}
- @SuppressFBWarnings("MS_EXPOSE_REP") // Don't modify the list.
- public static String[] getActiveLocaleResources() {
+ @SuppressFBWarnings("MS_EXPOSE_REP") // Don't modify the array.
+ public static ResourceExtractor.ResourceEntry[] getActiveLocaleResources() {
return sActiveLocaleResources;
}
@@ -54,9 +80,9 @@
return null;
}
String fileName = locale + ".pak";
- for (String resName : sActiveLocaleResources) {
- if (fileName.equals(resName)) {
- return new File(ASSET_DIR, resName).toString();
+ for (ResourceExtractor.ResourceEntry entry : sActiveLocaleResources) {
+ if (fileName.equals(entry.extractedFileName)) {
+ return entry.pathWithinApk;
}
}
return null;
« no previous file with comments | « chrome/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698