4f97d3a25c74e8a9bb4c29b936ee9abcf942639c
[platform/framework/web/crosswalk.git] / src / base / android / java / src / org / chromium / base / LocaleUtils.java
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.base;
6
7 import java.util.Locale;
8
9 /**
10  * This class provides the locale related methods.
11  */
12 public class LocaleUtils {
13     /**
14      * Guards this class from being instantiated.
15      */
16     private LocaleUtils() {
17     }
18
19     /**
20      * @return the default locale, translating Android deprecated
21      * language codes into the modern ones used by Chromium.
22      */
23     @CalledByNative
24     public static String getDefaultLocale() {
25         Locale locale = Locale.getDefault();
26         String language = locale.getLanguage();
27         String country = locale.getCountry();
28
29         // Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the
30         // updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino.
31         // So apply a mapping.
32         // See http://developer.android.com/reference/java/util/Locale.html
33         if ("iw".equals(language)) {
34             language = "he";
35         } else if ("in".equals(language)) {
36             language = "id";
37         } else if ("tl".equals(language)) {
38             language = "fil";
39         }
40         return country.isEmpty() ? language : language + "-" + country;
41     }
42
43     /**
44      * Get the default country code set during install.
45      * @return country code.
46      */
47     @CalledByNative
48     private static String getDefaultCountryCode() {
49         CommandLine commandLine = CommandLine.getInstance();
50         return commandLine.hasSwitch(BaseSwitches.DEFAULT_COUNTRY_CODE_AT_INSTALL) ?
51                 commandLine.getSwitchValue(BaseSwitches.DEFAULT_COUNTRY_CODE_AT_INSTALL) :
52                 Locale.getDefault().getCountry();
53     }
54
55 }