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.
5 package org.chromium.base;
7 import java.util.Locale;
10 * This class provides the locale related methods.
12 public class LocaleUtils {
14 * Guards this class from being instantiated.
16 private LocaleUtils() {
20 * @return the default locale, translating Android deprecated
21 * language codes into the modern ones used by Chromium.
24 public static String getDefaultLocale() {
25 Locale locale = Locale.getDefault();
26 String language = locale.getLanguage();
27 String country = locale.getCountry();
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)) {
35 } else if ("in".equals(language)) {
37 } else if ("tl".equals(language)) {
40 return country.isEmpty() ? language : language + "-" + country;
44 * Get the default country code set during install.
45 * @return country code.
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();