1 /* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
2 * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
3
4 #include "country.hh"
5 #include "folding.hh"
6 #include <QtCore>
7 #include "wstring_qt.hh"
8
9 namespace Country {
10
11 namespace
12 {
13 struct Database: public QMap< QString, QString >
14 {
instanceCountry::__anon3811c4790111::Database15 static Database const & instance()
16 { static Database db; return db; }
17
18 private:
19
20 Database();
21
addCountryCountry::__anon3811c4790111::Database22 void addCountry( QString const & country, QString const & code )
23 {
24 (*this)[ gd::toQString( Folding::apply( gd::toWString( country ) ) ) ] = code.toLower();
25 }
26 };
27
Database()28 Database::Database()
29 {
30 addCountry( "Afghanistan", "AF" );
31 addCountry( "Aland Islands", "AX" );
32 addCountry( "Albania", "AL" );
33 addCountry( "Algeria", "DZ" );
34 addCountry( "American Samoa", "AS" );
35 addCountry( "Andorra", "AD" );
36 addCountry( "Angola", "AO" );
37 addCountry( "Anguilla", "AI" );
38 addCountry( "Antarctica", "AQ" );
39 addCountry( "Antigua and Barbuda", "AG" );
40 addCountry( "Argentina", "AR" );
41 addCountry( "Armenia", "AM" );
42 addCountry( "Aruba", "AW" );
43 addCountry( "Australia", "AU" );
44 addCountry( "Austria", "AT" );
45 addCountry( "Azerbaijan", "AZ" );
46 addCountry( "Bahamas", "BS" );
47 addCountry( "Bahrain", "BH" );
48 addCountry( "Bangladesh", "BD" );
49 addCountry( "Barbados", "BB" );
50 addCountry( "Belarus", "BY" );
51 addCountry( "Belgium", "BE" );
52 addCountry( "Belize", "BZ" );
53 addCountry( "Benin", "BJ" );
54 addCountry( "Bermuda", "BM" );
55 addCountry( "Bhutan", "BT" );
56 addCountry( "Bolivia, Plurinational State of", "BO" );
57 addCountry( "Bolivia", "BO" );
58 addCountry( "Bosnia and Herzegovina", "BA" );
59 addCountry( "Botswana", "BW" );
60 addCountry( "Bouvet Island", "BV" );
61 addCountry( "Brazil", "BR" );
62 addCountry( "British Indian Ocean Territory", "IO" );
63 addCountry( "Brunei Darussalam", "BN" );
64 addCountry( "Bulgaria", "BG" );
65 addCountry( "Burkina Faso", "BF" );
66 addCountry( "Burundi", "BI" );
67 addCountry( "Cambodia", "KH" );
68 addCountry( "Cameroon", "CM" );
69 addCountry( "Canada", "CA" );
70 addCountry( "Cape Verde", "CV" );
71 addCountry( "Cayman Islands", "KY" );
72 addCountry( "Central African Republic", "CF" );
73 addCountry( "Chad", "TD" );
74 addCountry( "Chile", "CL" );
75 addCountry( "China", "CN" );
76 addCountry( "Christmas Island", "CX" );
77 addCountry( "Cocos (Keeling) Islands", "CC" );
78 addCountry( "Colombia", "CO" );
79 addCountry( "Comoros", "KM" );
80 addCountry( "Congo", "CG" );
81 addCountry( "Congo, the Democratic Republic of the", "CD" );
82 addCountry( "Cook Islands", "CK" );
83 addCountry( "Costa Rica", "CR" );
84 addCountry( "Cote d'Ivoire", "CI" );
85 addCountry( "Croatia", "HR" );
86 addCountry( "Cuba", "CU" );
87 addCountry( "Cyprus", "CY" );
88 addCountry( "Czech Republic", "CZ" );
89 addCountry( "Denmark", "DK" );
90 addCountry( "Djibouti", "DJ" );
91 addCountry( "Dominica", "DM" );
92 addCountry( "Dominican Republic", "DO" );
93 addCountry( "Ecuador", "EC" );
94 addCountry( "Egypt", "EG" );
95 addCountry( "El Salvador", "SV" );
96 addCountry( "Equatorial Guinea", "GQ" );
97 addCountry( "Eritrea", "ER" );
98 addCountry( "Estonia", "EE" );
99 addCountry( "Ethiopia", "ET" );
100 addCountry( "Falkland Islands (Malvinas)", "FK" );
101 addCountry( "Faroe Islands", "FO" );
102 addCountry( "Fiji", "FJ" );
103 addCountry( "Finland", "FI" );
104 addCountry( "France", "FR" );
105 addCountry( "French Guiana", "GF" );
106 addCountry( "French Polynesia", "PF" );
107 addCountry( "French Southern Territories", "TF" );
108 addCountry( "Gabon", "GA" );
109 addCountry( "Gambia", "GM" );
110 addCountry( "Georgia", "GE" );
111 addCountry( "Germany", "DE" );
112 addCountry( "Ghana", "GH" );
113 addCountry( "Gibraltar", "GI" );
114 addCountry( "Greece", "GR" );
115 addCountry( "Greenland", "GL" );
116 addCountry( "Grenada", "GD" );
117 addCountry( "Guadeloupe", "GP" );
118 addCountry( "Guam", "GU" );
119 addCountry( "Guatemala", "GT" );
120 addCountry( "Guernsey", "GG" );
121 addCountry( "Guinea", "GN" );
122 addCountry( "Guinea-Bissau", "GW" );
123 addCountry( "Guyana", "GY" );
124 addCountry( "Haiti", "HT" );
125 addCountry( "Heard Island and McDonald Islands", "HM" );
126 addCountry( "Holy See (Vatican City State)", "VA" );
127 addCountry( "Honduras", "HN" );
128 addCountry( "Hong Kong", "HK" );
129 addCountry( "Hungary", "HU" );
130 addCountry( "Iceland", "IS" );
131 addCountry( "India", "IN" );
132 addCountry( "Indonesia", "ID" );
133 addCountry( "Iran, Islamic Republic of", "IR" );
134 addCountry( "Iran", "IR" );
135 addCountry( "Iraq", "IQ" );
136 addCountry( "Ireland", "IE" );
137 addCountry( "Isle of Man", "IM" );
138 addCountry( "Israel", "IL" );
139 addCountry( "Italy", "IT" );
140 addCountry( "Jamaica", "JM" );
141 addCountry( "Japan", "JP" );
142 addCountry( "Jersey", "JE" );
143 addCountry( "Jordan", "JO" );
144 addCountry( "Kazakhstan", "KZ" );
145 addCountry( "Kenya", "KE" );
146 addCountry( "Kiribati", "KI" );
147 addCountry( "Korea, Democratic People's Republic of", "KP" );
148 addCountry( "Korea, Republic of", "KR" );
149 addCountry( "Korea", "KR" );
150 addCountry( "Kuwait", "KW" );
151 addCountry( "Kyrgyzstan", "KG" );
152 addCountry( "Lao People's Democratic Republic", "LA" );
153 addCountry( "Latvia", "LV" );
154 addCountry( "Lebanon", "LB" );
155 addCountry( "Lesotho", "LS" );
156 addCountry( "Liberia", "LR" );
157 addCountry( "Libyan Arab Jamahiriya", "LY" );
158 addCountry( "Liechtenstein", "LI" );
159 addCountry( "Lithuania", "LT" );
160 addCountry( "Luxembourg", "LU" );
161 addCountry( "Macao", "MO" );
162 addCountry( "Macedonia, the former Yugoslav Republic of", "MK" );
163 addCountry( "Macedonia", "MK" );
164 addCountry( "Madagascar", "MG" );
165 addCountry( "Malawi", "MW" );
166 addCountry( "Malaysia", "MY" );
167 addCountry( "Maldives", "MV" );
168 addCountry( "Mali", "ML" );
169 addCountry( "Malta", "MT" );
170 addCountry( "Marshall Islands", "MH" );
171 addCountry( "Martinique", "MQ" );
172 addCountry( "Mauritania", "MR" );
173 addCountry( "Mauritius", "MU" );
174 addCountry( "Mayotte", "YT" );
175 addCountry( "Mexico", "MX" );
176 addCountry( "Micronesia, Federated States of", "FM" );
177 addCountry( "Micronesia", "FM" );
178 addCountry( "Moldova, Republic of", "MD" );
179 addCountry( "Moldova", "MD" );
180 addCountry( "Monaco", "MC" );
181 addCountry( "Mongolia", "MN" );
182 addCountry( "Montenegro", "ME" );
183 addCountry( "Montserrat", "MS" );
184 addCountry( "Morocco", "MA" );
185 addCountry( "Mozambique", "MZ" );
186 addCountry( "Myanmar", "MM" );
187 addCountry( "Namibia", "NA" );
188 addCountry( "Nauru", "NR" );
189 addCountry( "Nepal", "NP" );
190 addCountry( "Netherlands", "NL" );
191 addCountry( "Netherlands Antilles", "AN" );
192 addCountry( "New Caledonia", "NC" );
193 addCountry( "New Zealand", "NZ" );
194 addCountry( "Nicaragua", "NI" );
195 addCountry( "Niger", "NE" );
196 addCountry( "Nigeria", "NG" );
197 addCountry( "Niue", "NU" );
198 addCountry( "Norfolk Island", "NF" );
199 addCountry( "Northern Mariana Islands", "MP" );
200 addCountry( "Norway", "NO" );
201 addCountry( "Oman", "OM" );
202 addCountry( "Pakistan", "PK" );
203 addCountry( "Palau", "PW" );
204 addCountry( "Palestinian Territory, Occupied", "PS" );
205 addCountry( "Panama", "PA" );
206 addCountry( "Papua New Guinea", "PG" );
207 addCountry( "Paraguay", "PY" );
208 addCountry( "Peru", "PE" );
209 addCountry( "Philippines", "PH" );
210 addCountry( "Pitcairn", "PN" );
211 addCountry( "Poland", "PL" );
212 addCountry( "Portugal", "PT" );
213 addCountry( "Puerto Rico", "PR" );
214 addCountry( "Qatar", "QA" );
215 addCountry( "Reunion", "RE" );
216 addCountry( "Romania", "RO" );
217 addCountry( "Russian Federation", "RU" );
218 addCountry( "Russia", "RU" );
219 addCountry( "Rwanda", "RW" );
220 addCountry( "Saint Barthélemy", "BL" );
221 addCountry( "Saint Helena, Ascension and Tristan da Cunha", "SH" );
222 addCountry( "Saint Kitts and Nevis", "KN" );
223 addCountry( "Saint Lucia", "LC" );
224 addCountry( "Saint Martin (French part)", "MF" );
225 addCountry( "Saint Pierre and Miquelon", "PM" );
226 addCountry( "Saint Vincent and the Grenadines", "VC" );
227 addCountry( "Samoa", "WS" );
228 addCountry( "San Marino", "SM" );
229 addCountry( "Sao Tome and Principe", "ST" );
230 addCountry( "Saudi Arabia", "SA" );
231 addCountry( "Senegal", "SN" );
232 addCountry( "Serbia", "RS" );
233 addCountry( "Seychelles", "SC" );
234 addCountry( "Sierra Leone", "SL" );
235 addCountry( "Singapore", "SG" );
236 addCountry( "Slovakia", "SK" );
237 addCountry( "Slovenia", "SI" );
238 addCountry( "Solomon Islands", "SB" );
239 addCountry( "Somalia", "SO" );
240 addCountry( "South Africa", "ZA" );
241 addCountry( "South Georgia and the South Sandwich Islands", "GS" );
242 addCountry( "Spain", "ES" );
243 addCountry( "Sri Lanka", "LK" );
244 addCountry( "Sudan", "SD" );
245 addCountry( "Suriname", "SR" );
246 addCountry( "Svalbard and Jan Mayen", "SJ" );
247 addCountry( "Swaziland", "SZ" );
248 addCountry( "Sweden", "SE" );
249 addCountry( "Switzerland", "CH" );
250 addCountry( "Syrian Arab Republic", "SY" );
251 addCountry( "Taiwan, Province of China", "TW" );
252 addCountry( "Tajikistan", "TJ" );
253 addCountry( "Tanzania, United Republic of", "TZ" );
254 addCountry( "Tanzania", "TZ" );
255 addCountry( "Thailand", "TH" );
256 addCountry( "Timor-Leste", "TL" );
257 addCountry( "Togo", "TG" );
258 addCountry( "Tokelau", "TK" );
259 addCountry( "Tonga", "TO" );
260 addCountry( "Trinidad and Tobago", "TT" );
261 addCountry( "Tunisia", "TN" );
262 addCountry( "Turkey", "TR" );
263 addCountry( "Turkmenistan", "TM" );
264 addCountry( "Turks and Caicos Islands", "TC" );
265 addCountry( "Tuvalu", "TV" );
266 addCountry( "Uganda", "UG" );
267 addCountry( "Ukraine", "UA" );
268 addCountry( "United Arab Emirates", "AE" );
269 addCountry( "United Kingdom", "GB" );
270 addCountry( "United States", "US" );
271 addCountry( "United States Minor Outlying Islands", "UM" );
272 addCountry( "Uruguay", "UY" );
273 addCountry( "Uzbekistan", "UZ" );
274 addCountry( "Vanuatu", "VU" );
275 addCountry( "Venezuela, Bolivarian Republic of", "VE" );
276 addCountry( "Venezuela", "VE" );
277 addCountry( "Viet Nam", "VN" );
278 addCountry( "Virgin Islands, British", "VG" );
279 addCountry( "Virgin Islands, U.S.", "VI" );
280 addCountry( "Wallis and Futuna", "WF" );
281 addCountry( "Western Sahara", "EH" );
282 addCountry( "Yemen", "YE" );
283 addCountry( "Zambia", "ZM" );
284 addCountry( "Zimbabwe", "ZW" );
285 }
286 }
287
englishNametoIso2(QString const & name)288 QString englishNametoIso2( QString const & name )
289 {
290 Database::const_iterator i = Database::instance().find( gd::toQString( Folding::apply( gd::toWString( name ) ) ) );
291
292 if ( i == Database::instance().end() )
293 return QString();
294 else
295 return i.value();
296 }
297
298 }
299