1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.http;
24
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.Map;
28
29 /***
30 * Country names and their locale strings.
31 *
32 * TODO test this class
33 * TODO use this class
34 *
35 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
36 */
37 public final class DominoLocaleCode {
38
39 /*** Map from country names to locale strings. */
40 private static final Map LOCALE_CODES_MAP = new HashMap();
41
42 private final String fCountry;
43
44 private final String fLocaleString;
45
46 /***
47 * Constructor.
48 *
49 * @param country the country name
50 * @param localeString the locale string
51 */
52 public DominoLocaleCode(final String country, final String localeString) {
53 fCountry = country;
54 fLocaleString = localeString;
55 }
56
57 /***
58 * For a given country name returns the corresponsing locale string.
59 *
60 * @param country country name
61 * @return locale string
62 */
63 public static DominoLocaleCode get(final String country) {
64 return (DominoLocaleCode) LOCALE_CODES_MAP.get(country);
65 }
66
67 /***
68 * Returns the first found locale code for a given search string.
69 *
70 * <p>The search string is simply a partial string of a time zone name.</p>
71 *
72 * @param searchString search string of a locale code
73 * @return the locale code or <code>null</code> if not found
74 */
75 public static DominoLocaleCode searchLocaleCode(final String searchString) {
76 if (searchString == null) {
77 return null;
78 }
79 Iterator iterator = LOCALE_CODES_MAP.values().iterator();
80 while (iterator.hasNext()) {
81 DominoLocaleCode localeCode = (DominoLocaleCode) iterator.next();
82 if (localeCode.getCountry().indexOf(searchString) >= 0) {
83 return localeCode;
84 }
85 }
86 return null;
87 }
88
89 /***
90 * @return Returns the country.
91 */
92 public String getCountry() {
93 return fCountry;
94 }
95
96 /***
97 * @return Returns the localeString.
98 */
99 public String getLocaleString() {
100 return fLocaleString;
101 }
102
103 static {
104 addLocaleCode(new DominoLocaleCode("Afrikaans", "af"));
105 addLocaleCode(new DominoLocaleCode("Afrikaans(South Africa)", "af-ZA"));
106 addLocaleCode(new DominoLocaleCode("Albanian", "sq"));
107 addLocaleCode(new DominoLocaleCode("Arabic", "ar"));
108 addLocaleCode(new DominoLocaleCode("Arabic(Algeria)", "ar-DZ"));
109 addLocaleCode(new DominoLocaleCode("Arabic(Bahrain)", "ar-BH"));
110 addLocaleCode(new DominoLocaleCode("Arabic(Egypt)", "ar-EG"));
111 addLocaleCode(new DominoLocaleCode("Arabic(Jordan)", "ar-JO"));
112 addLocaleCode(new DominoLocaleCode("Arabic(Kuwait)", "ar-KW"));
113 addLocaleCode(new DominoLocaleCode("Arabic(Lebanon)", "ar-LB"));
114 addLocaleCode(new DominoLocaleCode("Arabic(Morocco)", "ar-MA"));
115 addLocaleCode(new DominoLocaleCode("Arabic(Oman)", "ar-OM"));
116 addLocaleCode(new DominoLocaleCode("Arabic(Qatar)", "ar-QA"));
117 addLocaleCode(new DominoLocaleCode("Arabic(Saudi Arabia)", "ar-SA"));
118 addLocaleCode(new DominoLocaleCode("Arabic(Tunisia)", "ar-TN"));
119 addLocaleCode(new DominoLocaleCode("Arabic(United Arab Emirates)", "ar-AE"));
120 addLocaleCode(new DominoLocaleCode("Arabic(Yemen)", "ar-YE"));
121 addLocaleCode(new DominoLocaleCode("Bulgarian", "bg"));
122 addLocaleCode(new DominoLocaleCode("Byelorussian", "be"));
123 addLocaleCode(new DominoLocaleCode("Catalan", "ca"));
124 addLocaleCode(new DominoLocaleCode("Chinese", "zh"));
125 addLocaleCode(new DominoLocaleCode("Chinese(China)", "zh-CN"));
126 addLocaleCode(new DominoLocaleCode("Chinese(Hong Kong)", "zh-HK"));
127 addLocaleCode(new DominoLocaleCode("Chinese(Macau)", "zh-MO"));
128 addLocaleCode(new DominoLocaleCode("Chinese(Taiwan)", "zh-TW"));
129 addLocaleCode(new DominoLocaleCode("Chinese(Singapore)", "zh-SG"));
130 addLocaleCode(new DominoLocaleCode("Croatian", "hr"));
131 addLocaleCode(new DominoLocaleCode("Czech", "cs"));
132 addLocaleCode(new DominoLocaleCode("Danish", "da"));
133 addLocaleCode(new DominoLocaleCode("Dutch", "nl"));
134 addLocaleCode(new DominoLocaleCode("Dutch(Belgium)", "nl-BE"));
135 addLocaleCode(new DominoLocaleCode("Dutch(Netherlands)", "nl-NL"));
136 addLocaleCode(new DominoLocaleCode("English", "en"));
137 addLocaleCode(new DominoLocaleCode("English(Australia)", "en-AU"));
138 addLocaleCode(new DominoLocaleCode("English(Canada)", "en-CA"));
139 addLocaleCode(new DominoLocaleCode("English(Hong Kong)", "en-HK"));
140 addLocaleCode(new DominoLocaleCode("English(Ireland)", "en-IE"));
141 addLocaleCode(new DominoLocaleCode("English(India)", "en-IN"));
142 addLocaleCode(new DominoLocaleCode("English(Jamaica)", "en-JM"));
143 addLocaleCode(new DominoLocaleCode("English(New Zealand)", "en-NZ"));
144 addLocaleCode(new DominoLocaleCode("English(Philippines)", "en-PH"));
145 addLocaleCode(new DominoLocaleCode("English(Singapore)", "en-SG"));
146 addLocaleCode(new DominoLocaleCode("English(South Africa)", "en-ZA"));
147 addLocaleCode(new DominoLocaleCode("English(United Kingdom)", "en-GB"));
148 addLocaleCode(new DominoLocaleCode("English(United States)", "en-US"));
149 addLocaleCode(new DominoLocaleCode("Estonian", "et"));
150 addLocaleCode(new DominoLocaleCode("Finnish", "fi"));
151 addLocaleCode(new DominoLocaleCode("French", "fr"));
152 addLocaleCode(new DominoLocaleCode("French(Belgium)", "fr-BE"));
153 addLocaleCode(new DominoLocaleCode("French(Canada)", "fr-CA"));
154 addLocaleCode(new DominoLocaleCode("French(France)", "fr-FR"));
155 addLocaleCode(new DominoLocaleCode("French(Luxembourg)", "fr-LU"));
156 addLocaleCode(new DominoLocaleCode("French(Switzerland)", "fr-CH"));
157 addLocaleCode(new DominoLocaleCode("German", "de"));
158 addLocaleCode(new DominoLocaleCode("German(Austria)", "de-AT"));
159 addLocaleCode(new DominoLocaleCode("German(Germany)", "de-DE"));
160 addLocaleCode(new DominoLocaleCode("German(Liechtenstein)", "de-LI"));
161 addLocaleCode(new DominoLocaleCode("German(Luxembourg)", "de-LU"));
162 addLocaleCode(new DominoLocaleCode("German(Switzerland)", "de-CH"));
163 addLocaleCode(new DominoLocaleCode("Greek", "el"));
164 addLocaleCode(new DominoLocaleCode("Gujarati", "gu"));
165 addLocaleCode(new DominoLocaleCode("Hebrew", "he"));
166 addLocaleCode(new DominoLocaleCode("Hindi", "hi"));
167 addLocaleCode(new DominoLocaleCode("Hungarian", "hu"));
168 addLocaleCode(new DominoLocaleCode("Icelandic", "is"));
169 addLocaleCode(new DominoLocaleCode("Indonesian", "id"));
170 addLocaleCode(new DominoLocaleCode("Italian", "it"));
171 addLocaleCode(new DominoLocaleCode("Italian(Italy)", "it-IT"));
172 addLocaleCode(new DominoLocaleCode("Italian(Switzerland)", "it-CH"));
173 addLocaleCode(new DominoLocaleCode("Japanese", "ja"));
174 addLocaleCode(new DominoLocaleCode("Konkani", "x-KOK"));
175 addLocaleCode(new DominoLocaleCode("Korean", "ko"));
176 addLocaleCode(new DominoLocaleCode("Latvian", "lv"));
177 addLocaleCode(new DominoLocaleCode("Lithuanian", "lt"));
178 addLocaleCode(new DominoLocaleCode("Macedonian(FYROM)", "mk"));
179 addLocaleCode(new DominoLocaleCode("Malay", "ms"));
180 addLocaleCode(new DominoLocaleCode("Marathi", "mr"));
181 addLocaleCode(new DominoLocaleCode("Norwegian", "no"));
182 addLocaleCode(new DominoLocaleCode("Norwegian(Norway)", "no-NO"));
183 addLocaleCode(new DominoLocaleCode("Norwegian(Nynorsk)", "ny-NO"));
184 addLocaleCode(new DominoLocaleCode("Polish", "pl"));
185 addLocaleCode(new DominoLocaleCode("Portuguese", "pt"));
186 addLocaleCode(new DominoLocaleCode("Portuguese(Brazil)", "pt-BR"));
187 addLocaleCode(new DominoLocaleCode("Portuguese(Portugal)", "pt-PT"));
188 addLocaleCode(new DominoLocaleCode("Romanian", "ro"));
189 addLocaleCode(new DominoLocaleCode("Romanian(Moldavia)", "ro-MD"));
190 addLocaleCode(new DominoLocaleCode("Romanian(Romania)", "ro-RO"));
191 addLocaleCode(new DominoLocaleCode("Russian", "ru"));
192 addLocaleCode(new DominoLocaleCode("Serbian", "sr"));
193 addLocaleCode(new DominoLocaleCode("Slovak", "sk"));
194 addLocaleCode(new DominoLocaleCode("Slovenian", "sl"));
195 addLocaleCode(new DominoLocaleCode("Spanish", "es"));
196 addLocaleCode(new DominoLocaleCode("Spanish(Argentina)", "es-AR"));
197 addLocaleCode(new DominoLocaleCode("Spanish(Bolivia)", "es-BO"));
198 addLocaleCode(new DominoLocaleCode("Spanish(Chile)", "es-CL"));
199 addLocaleCode(new DominoLocaleCode("Spanish(Colombia)", "es-CO"));
200 addLocaleCode(new DominoLocaleCode("Spanish(Costa Rica)", "es-CR"));
201 addLocaleCode(new DominoLocaleCode("Spanish(Dominican Republic)", "es-DO"));
202 addLocaleCode(new DominoLocaleCode("Spanish(Ecuador)", "es-EC"));
203 addLocaleCode(new DominoLocaleCode("Spanish(El Salvador)", "es-SV"));
204 addLocaleCode(new DominoLocaleCode("Spanish(Guatemala)", "es-GT"));
205 addLocaleCode(new DominoLocaleCode("Spanish(Honduras)", "es-HN"));
206 addLocaleCode(new DominoLocaleCode("Spanish(Mexico)", "es-MX"));
207 addLocaleCode(new DominoLocaleCode("Spanish(Nicaragua)", "es-NI"));
208 addLocaleCode(new DominoLocaleCode("Spanish(Panama)", "es-PA"));
209 addLocaleCode(new DominoLocaleCode("Spanish(Paraguay)", "es-PY"));
210 addLocaleCode(new DominoLocaleCode("Spanish(Peru)", "es-PE"));
211 addLocaleCode(new DominoLocaleCode("Spanish(Puerto Rico)", "es-PR"));
212 addLocaleCode(new DominoLocaleCode("Spanish(Spain)", "es-ES"));
213 addLocaleCode(new DominoLocaleCode("Spanish(United States)", "es-US"));
214 addLocaleCode(new DominoLocaleCode("Spanish(Uruguay)", "es-UY"));
215 addLocaleCode(new DominoLocaleCode("Spanish(Venezuela)", "es-VE"));
216 addLocaleCode(new DominoLocaleCode("Swedish", "sv"));
217 addLocaleCode(new DominoLocaleCode("Tamil", "ta"));
218 addLocaleCode(new DominoLocaleCode("Telugu", "te"));
219 addLocaleCode(new DominoLocaleCode("Thai", "th"));
220 addLocaleCode(new DominoLocaleCode("Turkish", "tr"));
221 addLocaleCode(new DominoLocaleCode("Ukrainian", "uk"));
222 addLocaleCode(new DominoLocaleCode("Vietnamese", "vi"));
223 addLocaleCode(new DominoLocaleCode("Arabic(Syria)", "ar-SY"));
224 addLocaleCode(new DominoLocaleCode("Kazakh", "kk"));
225 addLocaleCode(new DominoLocaleCode("Norwegian Bokmal", "nb"));
226 addLocaleCode(new DominoLocaleCode("Norwegian Nynorsk", "nn"));
227 }
228
229 private static void addLocaleCode(final DominoLocaleCode code) {
230 LOCALE_CODES_MAP.put(code.getCountry(), code.getLocaleString());
231 }
232 }