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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..17af127670683498c41c2070ad69ef5851e0801a |
| --- /dev/null |
| +++ b/base/android/java/src/org/chromium/base/LocaleUtils.java |
| @@ -0,0 +1,36 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.base; |
| + |
| +import java.util.Locale; |
| + |
| +/** |
| + * This class provides the locale related methods. |
| + */ |
| +public abstract class LocaleUtils { |
| + |
| + /** |
| + * @return the default locale, translating Android deprecated |
| + * language codes into the modern ones used by Chromium. |
| + */ |
| + public static String getDefaultLocale() { |
|
Ted C
2014/09/09 17:51:00
Why did you need to move this from LocalizationUti
vivekg
2014/09/09 18:01:30
The reason I moved this is due to its usage in Res
Ted C
2014/09/09 18:36:19
Ah ha...I missed the ui part of the package. That
vivekg
2014/09/09 18:46:32
Sure, I will put a TODO there and mostly will make
|
| + Locale locale = Locale.getDefault(); |
| + String language = locale.getLanguage(); |
| + String country = locale.getCountry(); |
| + |
| + // Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the |
| + // updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino. |
| + // So apply a mapping. |
| + // See http://developer.android.com/reference/java/util/Locale.html |
| + if ("iw".equals(language)) { |
| + language = "he"; |
| + } else if ("in".equals(language)) { |
| + language = "id"; |
| + } else if ("tl".equals(language)) { |
| + language = "fil"; |
| + } |
| + return country.isEmpty() ? language : language + "-" + country; |
| + } |
| +} |