Chromium Code Reviews| Index: base/android/java/src/org/chromium/base/LocaleUtils.java |
| diff --git a/base/android/java/src/org/chromium/base/LocaleUtils.java b/base/android/java/src/org/chromium/base/LocaleUtils.java |
| index 31e5c4294beafcc99f3d48eed1675e93cd7dd720..3cf04318dac8154ee56efd16bc9fc6e500c4da10 100644 |
| --- a/base/android/java/src/org/chromium/base/LocaleUtils.java |
| +++ b/base/android/java/src/org/chromium/base/LocaleUtils.java |
| @@ -6,9 +6,12 @@ package org.chromium.base; |
| import android.annotation.TargetApi; |
| import android.os.Build; |
| +import android.os.LocaleList; |
| +import android.text.TextUtils; |
| import org.chromium.base.annotations.CalledByNative; |
| +import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.HashMap; |
| import java.util.Locale; |
| @@ -119,6 +122,8 @@ public class LocaleUtils { |
| /** |
| * This function creates Locale object from xx-XX style string where xx is language code |
| * and XX is a country code. |
| + * This works for API is lower than 24. For API is 24 and above, LocaleList.toLanguageTags |
|
ksk1
2016/11/08 09:47:13
s/LocaleList.toLanguageTags/LocaleList.forLanguage
Yirui Huang
2016/11/08 10:39:31
Done.
|
| + * can be used. |
| * @return the locale that best represents the language tag. |
| */ |
| public static Locale forLanguageTag(String languageTag) { |
| @@ -135,7 +140,7 @@ public class LocaleUtils { |
| * @return a well-formed IETF BCP 47 language tag with language and country code that |
| * represents this locale. |
| */ |
| - public static String toLanguageTagCompat(Locale locale) { |
| + public static String toLanguageTag(Locale locale) { |
| String language = getUpdatedLanguageForChromium(locale.getLanguage()); |
| String country = locale.getCountry(); |
| if (language.equals("no") && country.equals("NO") && locale.getVariant().equals("NY")) { |
| @@ -153,36 +158,47 @@ public class LocaleUtils { |
| * Locale.toLanguageTag(), it does a special conversion from deprecated language code to updated |
| * one, but it is only usable for Android N or after. |
| * @return a well-formed IETF BCP 47 language tag with language and country code that |
| - * represents this locale. |
| + * represents this locale list. |
| */ |
| - public static String toLanguageTag(Locale locale) { |
| - // TODO(yirui): use '>= N' once SDK is updated to include the version code |
| - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { |
| - locale = getUpdatedLocaleForChromium(locale); |
| - return locale.toLanguageTag(); |
| + @TargetApi(Build.VERSION_CODES.N) |
| + public static String toLanguageTags(LocaleList localeList) { |
| + ArrayList<String> newLocaleList = new ArrayList<>(); |
| + Locale locale; |
|
ksk1
2016/11/08 09:38:02
How about:
for (Locale locale : localeList) {
Loc
ksk1
2016/11/08 09:47:13
for (int i = 0; i < localeList.size(); i++) is bet
Yirui Huang
2016/11/08 10:39:31
Done.
Yirui Huang
2016/11/08 10:39:31
Done.
|
| + for (int i = 0; i < localeList.size(); i++) { |
| + locale = getUpdatedLocaleForChromium(localeList.get(i)); |
| + newLocaleList.add(toLanguageTag(locale)); |
|
ksk1
2016/11/08 09:38:02
Now locale.toLanguageTag is not used. Is it intent
Yirui Huang
2016/11/08 10:39:31
Done. The comment below is the explanation for not
|
| } |
| - return toLanguageTagCompat(locale); |
| + return TextUtils.join(",", newLocaleList); |
| } |
| /** |
| * @return a well-formed IETF BCP 47 language tag with language and country code that |
| - * represents a default locale. |
| + * represents a default locale or a default localelist. |
| */ |
| @CalledByNative |
| public static String getDefaultLocaleString() { |
| - Locale locale = Locale.getDefault(); |
| - return toLanguageTag(locale); |
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| + return toLanguageTags(LocaleList.getDefault()); |
| + } |
| + return toLanguageTag(Locale.getDefault()); |
| } |
| /** |
| - * @return The default country code set during install. |
| + * @return The default country code set during install. If the default is a LocaleList, return |
| + * the country code of the first locale. |
| */ |
| @CalledByNative |
| private static String getDefaultCountryCode() { |
| CommandLine commandLine = CommandLine.getInstance(); |
| + Locale locale; |
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| + locale = LocaleList.getDefault().get(0); |
| + } else { |
| + locale = Locale.getDefault(); |
| + } |
| return commandLine.hasSwitch(BaseSwitches.DEFAULT_COUNTRY_CODE_AT_INSTALL) |
|
Seigo Nonaka
2016/11/08 09:31:11
How about checking the commandline before resolvin
Yirui Huang
2016/11/08 10:39:31
Done.
|
| ? commandLine.getSwitchValue(BaseSwitches.DEFAULT_COUNTRY_CODE_AT_INSTALL) |
| - : Locale.getDefault().getCountry(); |
| + : locale.getCountry(); |
| } |
| } |