OLD | NEW |
(Empty) | |
| 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 public static String getDefaultLocale() { |
| 24 Locale locale = Locale.getDefault(); |
| 25 String language = locale.getLanguage(); |
| 26 String country = locale.getCountry(); |
| 27 |
| 28 // Android uses deprecated lanuages codes for Hebrew and Indonesian but
Chromium uses the |
| 29 // updated codes. Also, Android uses "tl" while Chromium uses "fil" for
Tagalog/Filipino. |
| 30 // So apply a mapping. |
| 31 // See http://developer.android.com/reference/java/util/Locale.html |
| 32 if ("iw".equals(language)) { |
| 33 language = "he"; |
| 34 } else if ("in".equals(language)) { |
| 35 language = "id"; |
| 36 } else if ("tl".equals(language)) { |
| 37 language = "fil"; |
| 38 } |
| 39 return country.isEmpty() ? language : language + "-" + country; |
| 40 } |
| 41 } |
OLD | NEW |