]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/main/classes/core/src/com/ibm/icu/impl/LocaleIDs.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / main / classes / core / src / com / ibm / icu / impl / LocaleIDs.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2009, International Business Machines Corporation and         *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.impl;
8
9 import java.util.MissingResourceException;
10
11 import com.ibm.icu.util.ULocale;
12
13
14 /**
15  * Utilities for mapping between old and new language, country, and other
16  * locale ID related names.
17  */
18 public class LocaleIDs {
19
20     /**
21      * Returns a list of all 2-letter country codes defined in ISO 3166.
22      * Can be used to create Locales.
23      * @stable ICU 3.0
24      */
25     public static String[] getISOCountries() {
26         initCountryTables();
27         return _countries.clone();
28     }
29
30     /**
31      * Returns a list of all 2-letter language codes defined in ISO 639.
32      * Can be used to create Locales.
33      * [NOTE:  ISO 639 is not a stable standard-- some languages' codes have changed.
34      * The list this function returns includes both the new and the old codes for the
35      * languages whose codes have changed.]
36      * @stable ICU 3.0
37      */
38     public static String[] getISOLanguages() {
39         initLanguageTables();
40         return _languages.clone();
41     }
42
43     /**
44      * Returns a three-letter abbreviation for the provided country.  If the provided
45      * country is empty, returns the empty string.  Otherwise, returns
46      * an uppercase ISO 3166 3-letter country code.
47      * @exception MissingResourceException Throws MissingResourceException if the
48      * three-letter country abbreviation is not available for this locale.
49      * @stable ICU 3.0
50      */
51     public static String getISO3Country(String country){
52         initCountryTables();
53
54         int offset = findIndex(_countries, country);
55         if(offset>=0){
56             return _countries3[offset];
57         }else{
58             offset = findIndex(_obsoleteCountries, country);
59             if(offset>=0){
60                 return _obsoleteCountries3[offset];
61             }
62         }
63         return "";
64     }
65     /**
66      * Returns a three-letter abbreviation for the language.  If language is
67      * empty, returns the empty string.  Otherwise, returns
68      * a lowercase ISO 639-2/T language code.
69      * The ISO 639-2 language codes can be found on-line at
70      *   <a href="ftp://dkuug.dk/i18n/iso-639-2.txt"><code>ftp://dkuug.dk/i18n/iso-639-2.txt</code></a>
71      * @exception MissingResourceException Throws MissingResourceException if the
72      * three-letter language abbreviation is not available for this locale.
73      * @stable ICU 3.0
74      */
75     public static String getISO3Language(String language) {
76         initLanguageTables();
77
78         int offset = findIndex(_languages, language);
79         if(offset>=0){
80             return _languages3[offset];
81         } else {
82             offset = findIndex(_obsoleteLanguages, language);
83             if (offset >= 0) {
84                 return _obsoleteLanguages3[offset];
85             }
86         }
87         return "";
88     }
89
90     public static String threeToTwoLetterLanguage(String lang) {
91         initLanguageTables();
92
93         /* convert 3 character code to 2 character code if possible *CWB*/
94         int offset = findIndex(_languages3, lang);
95         if (offset >= 0) {
96             return _languages[offset];
97         }
98
99         offset = findIndex(_obsoleteLanguages3, lang);
100         if (offset >= 0) {
101             return _obsoleteLanguages[offset];
102         }
103
104         return null;
105     }
106
107     public static String threeToTwoLetterRegion(String region) {
108         initCountryTables();
109
110         /* convert 3 character code to 2 character code if possible *CWB*/
111         int offset = findIndex(_countries3, region);
112         if (offset >= 0) {
113             return _countries[offset];
114         }
115
116         offset = findIndex(_obsoleteCountries3, region);
117         if (offset >= 0) {
118             return _obsoleteCountries[offset];
119         }
120
121         return null;
122     }
123
124     /**
125      * linear search of the string array. the arrays are unfortunately ordered by the
126      * two-letter target code, not the three-letter search code, which seems backwards.
127      */
128     private static int findIndex(String[] array, String target){
129         for (int i = 0; i < array.length; i++) {
130             if (target.equals(array[i])) {
131                 return i;
132             }
133         }
134         return -1;
135     }
136
137
138     /**
139      * Tables used in normalizing portions of the id.
140      */
141     /* tables updated per http://lcweb.loc.gov/standards/iso639-2/
142        to include the revisions up to 2001/7/27 *CWB*/
143     /* The 3 character codes are the terminology codes like RFC 3066.
144        This is compatible with prior ICU codes */
145     /* "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in
146        the table but now at the end of the table because
147        3 character codes are duplicates.  This avoids bad searches
148        going from 3 to 2 character codes.*/
149     /* The range qaa-qtz is reserved for local use. */
150
151     private static String[] _languages;
152     private static String[] _replacementLanguages;
153     private static String[] _obsoleteLanguages;
154     private static String[] _languages3;
155     private static String[] _obsoleteLanguages3;
156
157     // Avoid initializing languages tables unless we have to.
158     private static void initLanguageTables() {
159         if (_languages == null) {
160
161             /* This list MUST be in sorted order, and MUST contain the two-letter codes
162                if one exists otherwise use the three letter code */
163             String[] tempLanguages = {
164                 "aa",  "ab",  "ace", "ach", "ada", "ady", "ae",  "af",  "afa",
165                 "afh", "ak",  "akk", "ale", "alg", "am",  "an",  "ang", "apa",
166                 "ar",  "arc", "arn", "arp", "art", "arw", "as",  "ast",
167                 "ath", "aus", "av",  "awa", "ay",  "az",  "ba",  "bad",
168                 "bai", "bal", "ban", "bas", "bat", "be",  "bej",
169                 "bem", "ber", "bg",  "bh",  "bho", "bi",  "bik", "bin",
170                 "bla", "bm",  "bn",  "bnt", "bo",  "br",  "bra", "bs",
171                 "btk", "bua", "bug", "byn", "ca",  "cad", "cai", "car", "cau",
172                 "ce",  "ceb", "cel", "ch",  "chb", "chg", "chk", "chm",
173                 "chn", "cho", "chp", "chr", "chy", "cmc", "co",  "cop",
174                 "cpe", "cpf", "cpp", "cr",  "crh", "crp", "cs",  "csb", "cu",  "cus",
175                 "cv",  "cy",  "da",  "dak", "dar", "day", "de",  "del", "den",
176                 "dgr", "din", "doi", "dra", "dsb", "dua", "dum", "dv",  "dyu",
177                 "dz",  "ee",  "efi", "egy", "eka", "el",  "elx", "en",
178                 "enm", "eo",  "es",  "et",  "eu",  "ewo", "fa",
179                 "fan", "fat", "ff",  "fi",  "fiu", "fj",  "fo",  "fon",
180                 "fr",  "frm", "fro", "fur", "fy",  "ga",  "gaa", "gay",
181                 "gba", "gd",  "gem", "gez", "gil", "gl",  "gmh", "gn",
182                 "goh", "gon", "gor", "got", "grb", "grc", "gu",  "gv",
183                 "gwi", "ha",  "hai", "haw", "he",  "hi",  "hil", "him",
184                 "hit", "hmn", "ho",  "hr",  "hsb", "ht",  "hu",  "hup", "hy",  "hz",
185                 "ia",  "iba", "id",  "ie",  "ig",  "ii",  "ijo", "ik",
186                 "ilo", "inc", "ine", "inh", "io",  "ira", "iro", "is",  "it",
187                 "iu",  "ja",  "jbo", "jpr", "jrb", "jv",  "ka",  "kaa", "kab",
188                 "kac", "kam", "kar", "kaw", "kbd", "kg",  "kha", "khi",
189                 "kho", "ki",  "kj",  "kk",  "kl",  "km",  "kmb", "kn",
190                 "ko",  "kok", "kos", "kpe", "kr",  "krc", "kro", "kru", "ks",
191                 "ku",  "kum", "kut", "kv",  "kw",  "ky",  "la",  "lad",
192                 "lah", "lam", "lb",  "lez", "lg",  "li",  "ln",  "lo",  "lol",
193                 "loz", "lt",  "lu",  "lua", "lui", "lun", "luo", "lus",
194                 "lv",  "mad", "mag", "mai", "mak", "man", "map", "mas",
195                 "mdf", "mdr", "men", "mg",  "mga", "mh",  "mi",  "mic", "min",
196                 "mis", "mk",  "mkh", "ml",  "mn",  "mnc", "mni", "mno",
197                 "mo",  "moh", "mos", "mr",  "ms",  "mt",  "mul", "mun",
198                 "mus", "mwr", "my",  "myn", "myv", "na",  "nah", "nai", "nap",
199                 "nb",  "nd",  "nds", "ne",  "new", "ng",  "nia", "nic",
200                 "niu", "nl",  "nn",  "no",  "nog", "non", "nr",  "nso", "nub",
201                 "nv",  "nwc", "ny",  "nym", "nyn", "nyo", "nzi", "oc",  "oj",
202                 "om",  "or",  "os",  "osa", "ota", "oto", "pa",  "paa",
203                 "pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn",
204                 "pi",  "pl",  "pon", "pra", "pro", "ps",  "pt",  "qu",
205                 "raj", "rap", "rar", "rm",  "rn",  "ro",  "roa", "rom",
206                 "ru",  "rup", "rw",  "sa",  "sad", "sah", "sai", "sal", "sam",
207                 "sas", "sat", "sc",  "sco", "sd",  "se",  "sel", "sem",
208                 "sg",  "sga", "sgn", "shn", "si",  "sid", "sio", "sit",
209                 "sk",  "sl",  "sla", "sm",  "sma", "smi", "smj", "smn",
210                 "sms", "sn",  "snk", "so",  "sog", "son", "sq",  "sr",
211                 "srr", "ss",  "ssa", "st",  "su",  "suk", "sus", "sux",
212                 "sv",  "sw",  "syr", "ta",  "tai", "te",  "tem", "ter",
213                 "tet", "tg",  "th",  "ti",  "tig", "tiv", "tk",  "tkl",
214                 "tl",  "tlh", "tli", "tmh", "tn",  "to",  "tog", "tpi", "tr",
215                 "ts",  "tsi", "tt",  "tum", "tup", "tut", "tvl", "tw",
216                 "ty",  "tyv", "udm", "ug",  "uga", "uk",  "umb", "und", "ur",
217                 "uz",  "vai", "ve",  "vi",  "vo",  "vot", "wa",  "wak",
218                 "wal", "war", "was", "wen", "wo",  "xal", "xh",  "yao", "yap",
219                 "yi",  "yo",  "ypk", "za",  "zap", "zen", "zh",  "znd",
220                 "zu",  "zun",
221             };
222
223             String[] tempReplacementLanguages = {
224                 "id", "he", "yi", "jv", "sr", "nb",/* replacement language codes */
225             };
226
227             String[] tempObsoleteLanguages = {
228                 "in", "iw", "ji", "jw", "sh", "no",    /* obsolete language codes */
229             };
230
231             /* This list MUST contain a three-letter code for every two-letter code in the
232                list above, and they MUST ne in the same order (i.e., the same language must
233                be in the same place in both lists)! */
234             String[] tempLanguages3 = {
235                 /*"aa",  "ab",  "ace", "ach", "ada", "ady", "ae",  "af",  "afa",    */
236                 "aar", "abk", "ace", "ach", "ada", "ady", "ave", "afr", "afa",
237                 /*"afh", "ak",  "akk", "ale", "alg", "am",  "an",  "ang", "apa",    */
238                 "afh", "aka", "akk", "ale", "alg", "amh", "arg", "ang", "apa",
239                 /*"ar",  "arc", "arn", "arp", "art", "arw", "as",  "ast",    */
240                 "ara", "arc", "arn", "arp", "art", "arw", "asm", "ast",
241                 /*"ath", "aus", "av",  "awa", "ay",  "az",  "ba",  "bad",    */
242                 "ath", "aus", "ava", "awa", "aym", "aze", "bak", "bad",
243                 /*"bai", "bal", "ban", "bas", "bat", "be",  "bej",    */
244                 "bai", "bal", "ban", "bas", "bat", "bel", "bej",
245                 /*"bem", "ber", "bg",  "bh",  "bho", "bi",  "bik", "bin",    */
246                 "bem", "ber", "bul", "bih", "bho", "bis", "bik", "bin",
247                 /*"bla", "bm",  "bn",  "bnt", "bo",  "br",  "bra", "bs",     */
248                 "bla", "bam",  "ben", "bnt", "bod", "bre", "bra", "bos",
249                 /*"btk", "bua", "bug", "byn", "ca",  "cad", "cai", "car", "cau",    */
250                 "btk", "bua", "bug", "byn", "cat", "cad", "cai", "car", "cau",
251                 /*"ce",  "ceb", "cel", "ch",  "chb", "chg", "chk", "chm",    */
252                 "che", "ceb", "cel", "cha", "chb", "chg", "chk", "chm",
253                 /*"chn", "cho", "chp", "chr", "chy", "cmc", "co",  "cop",    */
254                 "chn", "cho", "chp", "chr", "chy", "cmc", "cos", "cop",
255                 /*"cpe", "cpf", "cpp", "cr",  "crh", "crp", "cs",  "csb", "cu",  "cus",    */
256                 "cpe", "cpf", "cpp", "cre", "crh", "crp", "ces", "csb", "chu", "cus",
257                 /*"cv",  "cy",  "da",  "dak", "dar", "day", "de",  "del", "den",    */
258                 "chv", "cym", "dan", "dak", "dar", "day", "deu", "del", "den",
259                 /*"dgr", "din", "doi", "dra", "dsb", "dua", "dum", "dv",  "dyu",    */
260                 "dgr", "din", "doi", "dra", "dsb", "dua", "dum", "div", "dyu",
261                 /*"dz",  "ee",  "efi", "egy", "eka", "el",  "elx", "en",     */
262                 "dzo", "ewe", "efi", "egy", "eka", "ell", "elx", "eng",
263                 /*"enm", "eo",  "es",  "et",  "eu",  "ewo", "fa",     */
264                 "enm", "epo", "spa", "est", "eus", "ewo", "fas",
265                 /*"fan", "fat", "ff",  "fi",  "fiu", "fj",  "fo",  "fon",    */
266                 "fan", "fat", "ful", "fin", "fiu", "fij", "fao", "fon",
267                 /*"fr",  "frm", "fro", "fur", "fy",  "ga",  "gaa", "gay",    */
268                 "fra", "frm", "fro", "fur", "fry", "gle", "gaa", "gay",
269                 /*"gba", "gd",  "gem", "gez", "gil", "gl",  "gmh", "gn",     */
270                 "gba", "gla", "gem", "gez", "gil", "glg", "gmh", "grn",
271                 /*"goh", "gon", "gor", "got", "grb", "grc", "gu",  "gv",     */
272                 "goh", "gon", "gor", "got", "grb", "grc", "guj", "glv",
273                 /*"gwi", "ha",  "hai", "haw", "he",  "hi",  "hil", "him",    */
274                 "gwi", "hau", "hai", "haw", "heb", "hin", "hil", "him",
275                 /*"hit", "hmn", "ho",  "hr",  "hsb", "ht",  "hu",  "hup", "hy",  "hz",     */
276                 "hit", "hmn", "hmo", "hrv", "hsb", "hat", "hun", "hup", "hye", "her",
277                 /*"ia",  "iba", "id",  "ie",  "ig",  "ii",  "ijo", "ik",     */
278                 "ina", "iba", "ind", "ile", "ibo", "iii", "ijo", "ipk",
279                 /*"ilo", "inc", "ine", "inh", "io",  "ira", "iro", "is",  "it",      */
280                 "ilo", "inc", "ine", "inh", "ido", "ira", "iro", "isl", "ita",
281                 /*"iu",  "ja",  "jbo", "jpr", "jrb", "jv",  "ka",  "kaa", "kab",   */
282                 "iku", "jpn", "jbo", "jpr", "jrb", "jaw", "kat", "kaa", "kab",
283                 /*"kac", "kam", "kar", "kaw", "kbd", "kg",  "kha", "khi",    */
284                 "kac", "kam", "kar", "kaw", "kbd", "kon", "kha", "khi",
285                 /*"kho", "ki",  "kj",  "kk",  "kl",  "km",  "kmb", "kn",     */
286                 "kho", "kik", "kua", "kaz", "kal", "khm", "kmb", "kan",
287                 /*"ko",  "kok", "kos", "kpe", "kr",  "krc", "kro", "kru", "ks",     */
288                 "kor", "kok", "kos", "kpe", "kau", "krc", "kro", "kru", "kas",
289                 /*"ku",  "kum", "kut", "kv",  "kw",  "ky",  "la",  "lad",    */
290                 "kur", "kum", "kut", "kom", "cor", "kir", "lat", "lad",
291                 /*"lah", "lam", "lb",  "lez", "lg",  "li",  "ln",  "lo",  "lol",    */
292                 "lah", "lam", "ltz", "lez", "lug", "lim", "lin", "lao", "lol",
293                 /*"loz", "lt",  "lu",  "lua", "lui", "lun", "luo", "lus",    */
294                 "loz", "lit", "lub", "lua", "lui", "lun", "luo", "lus",
295                 /*"lv",  "mad", "mag", "mai", "mak", "man", "map", "mas",    */
296                 "lav", "mad", "mag", "mai", "mak", "man", "map", "mas",
297                 /*"mdf", "mdr", "men", "mg",  "mga", "mh",  "mi",  "mic", "min",    */
298                 "mdf", "mdr", "men", "mlg", "mga", "mah", "mri", "mic", "min",
299                 /*"mis", "mk",  "mkh", "ml",  "mn",  "mnc", "mni", "mno",    */
300                 "mis", "mkd", "mkh", "mal", "mon", "mnc", "mni", "mno",
301                 /*"mo",  "moh", "mos", "mr",  "ms",  "mt",  "mul", "mun",    */
302                 "mol", "moh", "mos", "mar", "msa", "mlt", "mul", "mun",
303                 /*"mus", "mwr", "my",  "myn", "myv", "na",  "nah", "nai", "nap",    */
304                 "mus", "mwr", "mya", "myn", "myv", "nau", "nah", "nai", "nap",
305                 /*"nb",  "nd",  "nds", "ne",  "new", "ng",  "nia", "nic",    */
306                 "nob", "nde", "nds", "nep", "new", "ndo", "nia", "nic",
307                 /*"niu", "nl",  "nn",  "no",  "nog", "non", "nr",  "nso", "nub",    */
308                 "niu", "nld", "nno", "nor", "nog", "non", "nbl", "nso", "nub",
309                 /*"nv",  "nwc", "ny",  "nym", "nyn", "nyo", "nzi", "oc",  "oj",     */
310                 "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", "oci", "oji",
311                 /*"om",  "or",  "os",  "osa", "ota", "oto", "pa",  "paa",    */
312                 "orm", "ori", "oss", "osa", "ota", "oto", "pan", "paa",
313                 /*"pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn",    */
314                 "pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn",
315                 /*"pi",  "pl",  "pon", "pra", "pro", "ps",  "pt",  "qu",     */
316                 "pli", "pol", "pon", "pra", "pro", "pus", "por", "que",
317                 /*"raj", "rap", "rar", "rm",  "rn",  "ro",  "roa", "rom",    */
318                 "raj", "rap", "rar", "roh", "run", "ron", "roa", "rom",
319                 /*"ru",  "rup", "rw",  "sa",  "sad", "sah", "sai", "sal", "sam",    */
320                 "rus", "rup", "kin", "san", "sad", "sah", "sai", "sal", "sam",
321                 /*"sas", "sat", "sc",  "sco", "sd",  "se",  "sel", "sem",    */
322                 "sas", "sat", "srd", "sco", "snd", "sme", "sel", "sem",
323                 /*"sg",  "sga", "sgn", "shn", "si",  "sid", "sio", "sit",    */
324                 "sag", "sga", "sgn", "shn", "sin", "sid", "sio", "sit",
325                 /*"sk",  "sl",  "sla", "sm",  "sma", "smi", "smj", "smn",    */
326                 "slk", "slv", "sla", "smo", "sma", "smi", "smj", "smn",
327                 /*"sms", "sn",  "snk", "so",  "sog", "son", "sq",  "sr",     */
328                 "sms", "sna", "snk", "som", "sog", "son", "sqi", "srp",
329                 /*"srr", "ss",  "ssa", "st",  "su",  "suk", "sus", "sux",    */
330                 "srr", "ssw", "ssa", "sot", "sun", "suk", "sus", "sux",
331                 /*"sv",  "sw",  "syr", "ta",  "tai", "te",  "tem", "ter",    */
332                 "swe", "swa", "syr", "tam", "tai", "tel", "tem", "ter",
333                 /*"tet", "tg",  "th",  "ti",  "tig", "tiv", "tk",  "tkl",    */
334                 "tet", "tgk", "tha", "tir", "tig", "tiv", "tuk", "tkl",
335                 /*"tl",  "tlh", "tli", "tmh", "tn",  "to",  "tog", "tpi", "tr",     */
336                 "tgl", "tlh", "tli", "tmh", "tsn", "ton", "tog", "tpi", "tur",
337                 /*"ts",  "tsi", "tt",  "tum", "tup", "tut", "tvl", "tw",     */
338                 "tso", "tsi", "tat", "tum", "tup", "tut", "tvl", "twi",
339                 /*"ty",  "tyv", "udm", "ug",  "uga", "uk",  "umb", "und", "ur",     */
340                 "tah", "tyv", "udm", "uig", "uga", "ukr", "umb", "und", "urd",
341                 /*"uz",  "vai", "ve",  "vi",  "vo",  "vot", "wa",  "wak",    */
342                 "uzb", "vai", "ven", "vie", "vol", "vot", "wln", "wak",
343                 /*"wal", "war", "was", "wen", "wo",  "xal", "xh",  "yao", "yap",    */
344                 "wal", "war", "was", "wen", "wol", "xal", "xho", "yao", "yap",
345                 /*"yi",  "yo",  "ypk", "za",  "zap", "zen", "zh",  "znd",    */
346                 "yid", "yor", "ypk", "zha", "zap", "zen", "zho", "znd",
347                 /*"zu",  "zun",                                              */
348                 "zul", "zun",
349             };
350
351             String[] tempObsoleteLanguages3 = {
352                 /* "in",  "iw",  "ji",  "jw",  "sh", */
353                 "ind", "heb", "yid", "jaw", "srp",
354             };
355
356             synchronized (ULocale.class) {
357                 if (_languages == null) {
358                     _languages = tempLanguages;
359                     _replacementLanguages = tempReplacementLanguages;
360                     _obsoleteLanguages = tempObsoleteLanguages;
361                     _languages3 = tempLanguages3;
362                     _obsoleteLanguages3 = tempObsoleteLanguages3;
363                 }
364             }
365         }
366     }
367
368     private static String[] _countries;
369     private static String[] _deprecatedCountries;
370     private static String[] _replacementCountries;
371     private static String[] _obsoleteCountries;
372     private static String[] _countries3;
373     private static String[] _obsoleteCountries3;
374
375     // Avoid initializing country tables unless we have to.
376     private static void initCountryTables() {
377         if (_countries == null) {
378             /* ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per
379                http://www.evertype.com/standards/iso3166/iso3166-1-en.html
380                added new codes keeping the old ones for compatibility
381                updated to include 1999/12/03 revisions *CWB*/
382
383             /* RO(ROM) is now RO(ROU) according to
384                http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html
385             */
386
387             /* This list MUST be in sorted order, and MUST contain only two-letter codes! */
388             String[] tempCountries = {
389                 "AD",  "AE",  "AF",  "AG",  "AI",  "AL",  "AM",  "AN",
390                 "AO",  "AQ",  "AR",  "AS",  "AT",  "AU",  "AW",  "AX",  "AZ",
391                 "BA",  "BB",  "BD",  "BE",  "BF",  "BG",  "BH",  "BI",
392                 "BJ",  "BL",  "BM",  "BN",  "BO",  "BR",  "BS",  "BT",  "BV",
393                 "BW",  "BY",  "BZ",  "CA",  "CC",  "CD",  "CF",  "CG",
394                 "CH",  "CI",  "CK",  "CL",  "CM",  "CN",  "CO",  "CR",
395                 "CU",  "CV",  "CX",  "CY",  "CZ",  "DE",  "DJ",  "DK",
396                 "DM",  "DO",  "DZ",  "EC",  "EE",  "EG",  "EH",  "ER",
397                 "ES",  "ET",  "FI",  "FJ",  "FK",  "FM",  "FO",  "FR",
398                 "GA",  "GB",  "GD",  "GE",  "GF",  "GG",  "GH",  "GI",  "GL",
399                 "GM",  "GN",  "GP",  "GQ",  "GR",  "GS",  "GT",  "GU",
400                 "GW",  "GY",  "HK",  "HM",  "HN",  "HR",  "HT",  "HU",
401                 "ID",  "IE",  "IL",  "IM",  "IN",  "IO",  "IQ",  "IR",  "IS",
402                 "IT",  "JE",  "JM",  "JO",  "JP",  "KE",  "KG",  "KH",  "KI",
403                 "KM",  "KN",  "KP",  "KR",  "KW",  "KY",  "KZ",  "LA",
404                 "LB",  "LC",  "LI",  "LK",  "LR",  "LS",  "LT",  "LU",
405                 "LV",  "LY",  "MA",  "MC",  "MD",  "ME",  "MF",  "MG",  "MH",  "MK",
406                 "ML",  "MM",  "MN",  "MO",  "MP",  "MQ",  "MR",  "MS",
407                 "MT",  "MU",  "MV",  "MW",  "MX",  "MY",  "MZ",  "NA",
408                 "NC",  "NE",  "NF",  "NG",  "NI",  "NL",  "NO",  "NP",
409                 "NR",  "NU",  "NZ",  "OM",  "PA",  "PE",  "PF",  "PG",
410                 "PH",  "PK",  "PL",  "PM",  "PN",  "PR",  "PS",  "PT",
411                 "PW",  "PY",  "QA",  "RE",  "RO",  "RS",  "RU",  "RW",  "SA",
412                 "SB",  "SC",  "SD",  "SE",  "SG",  "SH",  "SI",  "SJ",
413                 "SK",  "SL",  "SM",  "SN",  "SO",  "SR",  "ST",  "SV",
414                 "SY",  "SZ",  "TC",  "TD",  "TF",  "TG",  "TH",  "TJ",
415                 "TK",  "TL",  "TM",  "TN",  "TO",  "TR",  "TT",  "TV",
416                 "TW",  "TZ",  "UA",  "UG",  "UM",  "US",  "UY",  "UZ",
417                 "VA",  "VC",  "VE",  "VG",  "VI",  "VN",  "VU",  "WF",
418                 "WS",  "YE",  "YT",  "ZA",  "ZM",  "ZW",
419             };
420
421             /* this table is used for 3 letter codes */
422             String[] tempObsoleteCountries = {
423                 "FX",  "CS",  "RO",  "TP",  "YU",  "ZR",  /* obsolete country codes */
424             };
425
426             String[] tempDeprecatedCountries = {
427                "BU", "CS", "DY", "FX", "HV", "NH", "RH", "TP", "YU", "ZR" /* deprecated country list */
428             };
429             String[] tempReplacementCountries = {
430            /*  "BU", "CS", "DY", "FX", "HV", "NH", "RH", "TP", "YU", "ZR" */
431                "MM", "RS", "BJ", "FR", "BF", "VU", "ZW", "TL", "RS", "CD",   /* replacement country codes */
432             };
433
434             /* This list MUST contain a three-letter code for every two-letter code in
435                the above list, and they MUST be listed in the same order! */
436             String[] tempCountries3 = {
437                 /*  "AD",  "AE",  "AF",  "AG",  "AI",  "AL",  "AM",  "AN",     */
438                     "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", "ANT",
439                 /*  "AO",  "AQ",  "AR",  "AS",  "AT",  "AU",  "AW",  "AX",  "AZ",     */
440                     "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE",
441                 /*  "BA",  "BB",  "BD",  "BE",  "BF",  "BG",  "BH",  "BI",     */
442                     "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI",
443                 /*  "BJ",  "BL",  "BM",  "BN",  "BO",  "BR",  "BS",  "BT",  "BV",     */
444                     "BEN", "BLM", "BMU", "BRN", "BOL", "BRA", "BHS", "BTN", "BVT",
445                 /*  "BW",  "BY",  "BZ",  "CA",  "CC",  "CD",  "CF",  "CG",     */
446                     "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG",
447                 /*  "CH",  "CI",  "CK",  "CL",  "CM",  "CN",  "CO",  "CR",     */
448                     "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI",
449                 /*  "CU",  "CV",  "CX",  "CY",  "CZ",  "DE",  "DJ",  "DK",     */
450                     "CUB", "CPV", "CXR", "CYP", "CZE", "DEU", "DJI", "DNK",
451                 /*  "DM",  "DO",  "DZ",  "EC",  "EE",  "EG",  "EH",  "ER",     */
452                     "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", "ERI",
453                 /*  "ES",  "ET",  "FI",  "FJ",  "FK",  "FM",  "FO",  "FR",     */
454                     "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA",
455                 /*  "GA",  "GB",  "GD",  "GE",  "GF",  "GG",  "GH",  "GI",  "GL",     */
456                     "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL",
457                 /*  "GM",  "GN",  "GP",  "GQ",  "GR",  "GS",  "GT",  "GU",     */
458                     "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM",
459                 /*  "GW",  "GY",  "HK",  "HM",  "HN",  "HR",  "HT",  "HU",     */
460                     "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN",
461                 /*  "ID",  "IE",  "IL",  "IM",  "IN",  "IO",  "IQ",  "IR",  "IS" */
462                     "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL",
463                 /*  "IT",  "JE",  "JM",  "JO",  "JP",  "KE",  "KG",  "KH",  "KI",     */
464                     "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR",
465                 /*  "KM",  "KN",  "KP",  "KR",  "KW",  "KY",  "KZ",  "LA",     */
466                     "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO",
467                 /*  "LB",  "LC",  "LI",  "LK",  "LR",  "LS",  "LT",  "LU",     */
468                     "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX",
469                 /*  "LV",  "LY",  "MA",  "MC",  "MD",  "ME",  "MF",  "MG",  "MH",  "MK",     */
470                     "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD",
471                 /*  "ML",  "MM",  "MN",  "MO",  "MP",  "MQ",  "MR",  "MS",     */
472                     "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR",
473                 /*  "MT",  "MU",  "MV",  "MW",  "MX",  "MY",  "MZ",  "NA",     */
474                     "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM",
475                 /*  "NC",  "NE",  "NF",  "NG",  "NI",  "NL",  "NO",  "NP",     */
476                     "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL",
477                 /*  "NR",  "NU",  "NZ",  "OM",  "PA",  "PE",  "PF",  "PG",     */
478                     "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG",
479                 /*  "PH",  "PK",  "PL",  "PM",  "PN",  "PR",  "PS",  "PT",     */
480                     "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT",
481                 /*  "PW",  "PY",  "QA",  "RE",  "RO",  "RS",  "RU",  "RW",  "SA",     */
482                     "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU",
483                 /*  "SB",  "SC",  "SD",  "SE",  "SG",  "SH",  "SI",  "SJ",     */
484                     "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM",
485                 /*  "SK",  "SL",  "SM",  "SN",  "SO",  "SR",  "ST",  "SV",     */
486                     "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "STP", "SLV",
487                 /*  "SY",  "SZ",  "TC",  "TD",  "TF",  "TG",  "TH",  "TJ",     */
488                     "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK",
489                 /*  "TK",  "TL",  "TM",  "TN",  "TO",  "TR",  "TT",  "TV",     */
490                     "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV",
491                 /*  "TW",  "TZ",  "UA",  "UG",  "UM",  "US",  "UY",  "UZ",     */
492                     "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB",
493                 /*  "VA",  "VC",  "VE",  "VG",  "VI",  "VN",  "VU",  "WF",     */
494                     "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF",
495                 /*  "WS",  "YE",  "YT",  "ZA",  "ZM",  "ZW"          */
496                     "WSM", "YEM", "MYT", "ZAF", "ZMB", "ZWE",
497             };
498
499             String[] tempObsoleteCountries3 = {
500                 /*"FX",  "CS",  "RO",  "TP",  "YU",  "ZR",   */
501                 "FXX", "SCG", "ROM", "TMP", "YUG", "ZAR",
502             };
503
504             synchronized (ULocale.class) {
505                 if (_countries == null) {
506                     _countries = tempCountries;
507                     _deprecatedCountries = tempDeprecatedCountries;
508                     _replacementCountries = tempReplacementCountries;
509                     _obsoleteCountries = tempObsoleteCountries;
510                     _countries3 = tempCountries3;
511                     _obsoleteCountries3 = tempObsoleteCountries3;
512                 }
513             }
514         }
515     }
516
517     public static String getCurrentCountryID(String oldID){
518         initCountryTables();
519         int offset = findIndex(_deprecatedCountries, oldID);
520         if (offset >= 0) {
521             return _replacementCountries[offset];
522         }
523         return oldID;
524     }
525
526     public static String getCurrentLanguageID(String oldID){
527         initLanguageTables();
528         int offset = findIndex(_obsoleteLanguages, oldID);
529         if (offset >= 0) {
530             return _replacementLanguages[offset];
531         }
532         return oldID;
533     }
534
535
536 }