|
| 1 | +package com.insready.drupalcloud; |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * Drupal uses RFC 4646 as the language tags standards, {@link https |
| 6 | + * ://www.drupal.org/node/923304#comment-3496864} while Android uses ISO 639-1 |
| 7 | + * and ISO 3166-1 as the standard {@link http |
| 8 | + * ://developer.android.com/reference/java/util/Locale.html} Therefore, there |
| 9 | + * exists a need for such mapping. |
| 10 | + */ |
| 11 | +public final class LanguageMapping { |
| 12 | + |
| 13 | + public final static String[] ANDROIDLOCALES = { "en_CA", "fr_CA", "zh_CN", |
| 14 | + "zh", "en", "fr_FR", "fr", "de", "de_DE", "it", "it_IT", "ja_JP", |
| 15 | + "ja", "ko_KR", "ko", "zh_CN", "zh_TW", "en_GB", "en_US" }; |
| 16 | + |
| 17 | + /** |
| 18 | + * DrupalLocales try to match AndroidLocales |
| 19 | + */ |
| 20 | + public final static String[] DRUPALLOCALES = { "en", "fr", "zh-hans", |
| 21 | + "zh-hans", "en", "fr", "fr", "de", "de", "it", "it", "ja", "ja", |
| 22 | + "ko", "zh-hans", "zh-hant", "en-gb", "en" }; |
| 23 | + |
| 24 | + public static int findAndroidLocaleIndex(String locale_code) { |
| 25 | + int size = ANDROIDLOCALES.length; |
| 26 | + for (int i = 0; i < size; i++) { |
| 27 | + if (ANDROIDLOCALES[i].equals(locale_code)) |
| 28 | + return i; |
| 29 | + } |
| 30 | + return -1; |
| 31 | + } |
| 32 | +} |
0 commit comments