FreeRDP
locale.c
1 
22 #include <freerdp/config.h>
23 
24 #if defined(__APPLE__)
25 #include <CoreFoundation/CFString.h>
26 #include <CoreFoundation/CFLocale.h>
27 #endif
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 
33 #include <winpr/crt.h>
34 #include <winpr/assert.h>
35 #include <winpr/environment.h>
36 
37 #include "liblocale.h"
38 
39 #include <freerdp/locale/locale.h>
40 
41 /*
42  * Refer to MSDN article "Locale Identifier Constants and Strings":
43  * http://msdn.microsoft.com/en-us/library/ms776260.aspx
44  */
45 
46 static const SYSTEM_LOCALE SYSTEM_LOCALE_TABLE[] = {
47  { "af", "ZA", AFRIKAANS }, /* Afrikaans (South Africa) */
48  { "sq", "AL", ALBANIAN }, /* Albanian (Albania) */
49  { "gsw", "FR", ALSATIAN }, /* Windows Vista and later: Alsatian (France) */
50  { "am", "ET", AMHARIC }, /* Windows Vista and later: Amharic (Ethiopia) */
51  { "ar", "DZ", ARABIC_ALGERIA }, /* Arabic (Algeria) */
52  { "ar", "BH", ARABIC_BAHRAIN }, /* Arabic (Bahrain) */
53  { "ar", "EG", ARABIC_EGYPT }, /* Arabic (Egypt) */
54  { "ar", "IQ", ARABIC_IRAQ }, /* Arabic (Iraq) */
55  { "ar", "JO", ARABIC_JORDAN }, /* Arabic (Jordan) */
56  { "ar", "KW", ARABIC_KUWAIT }, /* Arabic (Kuwait) */
57  { "ar", "LB", ARABIC_LEBANON }, /* Arabic (Lebanon) */
58  { "ar", "LY", ARABIC_LIBYA }, /* Arabic (Libya) */
59  { "ar", "MA", ARABIC_MOROCCO }, /* Arabic (Morocco) */
60  { "ar", "OM", ARABIC_OMAN }, /* Arabic (Oman) */
61  { "ar", "QA", ARABIC_QATAR }, /* Arabic (Qatar) */
62  { "ar", "SA", ARABIC_SAUDI_ARABIA }, /* Arabic (Saudi Arabia) */
63  { "ar", "SY", ARABIC_SYRIA }, /* Arabic (Syria) */
64  { "ar", "TN", ARABIC_TUNISIA }, /* Arabic (Tunisia) */
65  { "ar", "AE", ARABIC_UAE }, /* Arabic (U.A.E.) */
66  { "ar", "YE", ARABIC_YEMEN }, /* Arabic (Yemen) */
67  { "az", "AZ", AZERI_LATIN }, /* Azeri (Latin) */
68  { "az", "Cyrl_AZ", AZERI_CYRILLIC }, /* Azeri (Cyrillic) */
69  { "hy", "AM", ARMENIAN }, /* Windows 2000 and later: Armenian (Armenia) */
70  { "as", "IN", ASSAMESE }, /* Windows Vista and later: Assamese (India) */
71  { "ba", "RU", BASHKIR }, /* Windows Vista and later: Bashkir (Russia) */
72  { "eu", "ES", BASQUE }, /* Basque (Basque) */
73  { "be", "BY", BELARUSIAN }, /* Belarusian (Belarus) */
74  { "bn", "IN", BENGALI_INDIA }, /* Windows XP SP2 and later: Bengali (India) */
75  { "br", "FR", BRETON }, /* Breton (France) */
76  { "bs", "BA", BOSNIAN_LATIN }, /* Bosnian (Latin) */
77  { "bg", "BG", BULGARIAN }, /* Bulgarian (Bulgaria) */
78  { "ca", "ES", CATALAN }, /* Catalan (Catalan) */
79  { "zh", "HK", CHINESE_HONG_KONG }, /* Chinese (Hong Kong SAR, PRC) */
80  { "zh", "MO", CHINESE_MACAU }, /* Windows 98/Me, Windows XP and later: Chinese (Macao SAR) */
81  { "zh", "CN", CHINESE_PRC }, /* Chinese (PRC) */
82  { "zh", "SG", CHINESE_SINGAPORE }, /* Chinese (Singapore) */
83  { "zh", "TW", CHINESE_TAIWAN }, /* Chinese (Taiwan) */
84  { "hr", "BA", CROATIAN_BOSNIA_HERZEGOVINA }, /* Windows XP SP2 and later: Croatian (Bosnia and
85  Herzegovina, Latin) */
86  { "hr", "HR", CROATIAN }, /* Croatian (Croatia) */
87  { "cs", "CZ", CZECH }, /* Czech (Czech Republic) */
88  { "da", "DK", DANISH }, /* Danish (Denmark) */
89  { "prs", "AF", DARI }, /* Windows XP and later: Dari (Afghanistan) */
90  { "dv", "MV", DIVEHI }, /* Windows XP and later: Divehi (Maldives) */
91  { "nl", "BE", DUTCH_BELGIAN }, /* Dutch (Belgium) */
92  { "nl", "NL", DUTCH_STANDARD }, /* Dutch (Netherlands) */
93  { "en", "AU", ENGLISH_AUSTRALIAN }, /* English (Australia) */
94  { "en", "BZ", ENGLISH_BELIZE }, /* English (Belize) */
95  { "en", "CA", ENGLISH_CANADIAN }, /* English (Canada) */
96  { "en", "CB", ENGLISH_CARIBBEAN }, /* English (Carribean) */
97  { "en", "IN", ENGLISH_INDIA }, /* Windows Vista and later: English (India) */
98  { "en", "IE", ENGLISH_IRELAND }, /* English (Ireland) */
99  { "en", "JM", ENGLISH_JAMAICA }, /* English (Jamaica) */
100  { "en", "MY", ENGLISH_MALAYSIA }, /* Windows Vista and later: English (Malaysia) */
101  { "en", "NZ", ENGLISH_NEW_ZEALAND }, /* English (New Zealand) */
102  { "en", "PH",
103  ENGLISH_PHILIPPINES }, /* Windows 98/Me, Windows 2000 and later: English (Philippines) */
104  { "en", "SG", ENGLISH_SINGAPORE }, /* Windows Vista and later: English (Singapore) */
105  { "en", "ZA", ENGLISH_SOUTH_AFRICA }, /* English (South Africa) */
106  { "en", "TT", ENGLISH_TRINIDAD }, /* English (Trinidad and Tobago) */
107  { "en", "GB", ENGLISH_UNITED_KINGDOM }, /* English (United Kingdom) */
108  { "en", "US", ENGLISH_UNITED_STATES }, /* English (United States) */
109  { "en", "ZW",
110  ENGLISH_ZIMBABWE }, /* Windows 98/Me, Windows 2000 and later: English (Zimbabwe) */
111  { "et", "EE", ESTONIAN }, /* Estonian (Estonia) */
112  { "fo", "FO", FAEROESE }, /* Faroese (Faroe Islands) */
113  { "fil", "PH", FILIPINO }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
114  Filipino (Philippines) */
115  { "fi", "FI", FINNISH }, /* Finnish (Finland) */
116  { "fr", "BE", FRENCH_BELGIAN }, /* French (Belgium) */
117  { "fr", "CA", FRENCH_CANADIAN }, /* French (Canada) */
118  { "fr", "FR", FRENCH_STANDARD }, /* French (France) */
119  { "fr", "LU", FRENCH_LUXEMBOURG }, /* French (Luxembourg) */
120  { "fr", "MC", FRENCH_MONACO }, /* French (Monaco) */
121  { "fr", "CH", FRENCH_SWISS }, /* French (Switzerland) */
122  { "fy", "NL", FRISIAN }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
123  Frisian (Netherlands) */
124  { "gl", "ES", GALICIAN }, /* Windows XP and later: Galician (Spain) */
125  { "ka", "GE", GEORGIAN }, /* Windows 2000 and later: Georgian (Georgia) */
126  { "de", "AT", GERMAN_AUSTRIAN }, /* German (Austria) */
127  { "de", "DE", GERMAN_STANDARD }, /* German (Germany) */
128  { "de", "LI", GERMAN_LIECHTENSTEIN }, /* German (Liechtenstein) */
129  { "de", "LU", GERMAN_LUXEMBOURG }, /* German (Luxembourg) */
130  { "de", "CH", GERMAN_SWISS }, /* German (Switzerland) */
131  { "el", "GR", GREEK }, /* Greek (Greece) */
132  { "kl", "GL", GREENLANDIC }, /* Windows Vista and later: Greenlandic (Greenland) */
133  { "gu", "IN", GUJARATI }, /* Windows XP and later: Gujarati (India) */
134  { "he", "IL", HEBREW }, /* Hebrew (Israel) */
135  { "hi", "IN", HINDI }, /* Windows 2000 and later: Hindi (India) */
136  { "hu", "HU", HUNGARIAN }, /* Hungarian (Hungary) */
137  { "is", "IS", ICELANDIC }, /* Icelandic (Iceland) */
138  { "ig", "NG", IGBO }, /* Igbo (Nigeria) */
139  { "id", "ID", INDONESIAN }, /* Indonesian (Indonesia) */
140  { "ga", "IE", IRISH }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
141  Irish (Ireland) */
142  { "it", "IT", ITALIAN_STANDARD }, /* Italian (Italy) */
143  { "it", "CH", ITALIAN_SWISS }, /* Italian (Switzerland) */
144  { "ja", "JP", JAPANESE }, /* Japanese (Japan) */
145  { "kn", "IN", KANNADA }, /* Windows XP and later: Kannada (India) */
146  { "kk", "KZ", KAZAKH }, /* Windows 2000 and later: Kazakh (Kazakhstan) */
147  { "kh", "KH", KHMER }, /* Windows Vista and later: Khmer (Cambodia) */
148  { "qut", "GT", KICHE }, /* Windows Vista and later: K'iche (Guatemala) */
149  { "rw", "RW", KINYARWANDA }, /* Windows Vista and later: Kinyarwanda (Rwanda) */
150  { "kok", "IN", KONKANI }, /* Windows 2000 and later: Konkani (India) */
151  { "ko", "KR", KOREAN }, /* Korean (Korea) */
152  { "ky", "KG", KYRGYZ }, /* Windows XP and later: Kyrgyz (Kyrgyzstan) */
153  { "lo", "LA", LAO }, /* Windows Vista and later: Lao (Lao PDR) */
154  { "lv", "LV", LATVIAN }, /* Latvian (Latvia) */
155  { "lt", "LT", LITHUANIAN }, /* Lithuanian (Lithuania) */
156  { "dsb", "DE", LOWER_SORBIAN }, /* Windows Vista and later: Lower Sorbian (Germany) */
157  { "lb", "LU", LUXEMBOURGISH }, /* Windows XP SP2 and later (downloadable); Windows Vista and
158  later: Luxembourgish (Luxembourg) */
159  { "mk", "MK", MACEDONIAN }, /* Windows 2000 and later: Macedonian (Macedonia, FYROM) */
160  { "ms", "BN", MALAY_BRUNEI_DARUSSALAM }, /* Windows 2000 and later: Malay (Brunei Darussalam) */
161  { "ms", "MY", MALAY_MALAYSIA }, /* Windows 2000 and later: Malay (Malaysia) */
162  { "ml", "IN", MALAYALAM }, /* Windows XP SP2 and later: Malayalam (India) */
163  { "mt", "MT", MALTESE }, /* Windows XP SP2 and later: Maltese (Malta) */
164  { "mi", "NZ", MAORI }, /* Windows XP SP2 and later: Maori (New Zealand) */
165  { "arn", "CL", MAPUDUNGUN }, /* Windows XP SP2 and later (downloadable); Windows Vista and
166  later: Mapudungun (Chile) */
167  { "mr", "IN", MARATHI }, /* Windows 2000 and later: Marathi (India) */
168  { "moh", "CA", MOHAWK }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
169  Mohawk (Canada) */
170  { "mn", "MN", MONGOLIAN }, /* Mongolian */
171  { "ne", "NP", NEPALI }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
172  Nepali (Nepal) */
173  { "nb", "NO", NORWEGIAN_BOKMAL }, /* Norwegian (Bokmal, Norway) */
174  { "nn", "NO", NORWEGIAN_NYNORSK }, /* Norwegian (Nynorsk, Norway) */
175  { "oc", "FR", OCCITAN }, /* Occitan (France) */
176  { "or", "IN", ORIYA }, /* Oriya (India) */
177  { "ps", "AF", PASHTO }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
178  Pashto (Afghanistan) */
179  { "fa", "IR", FARSI }, /* Persian (Iran) */
180  { "pl", "PL", POLISH }, /* Polish (Poland) */
181  { "pt", "BR", PORTUGUESE_BRAZILIAN }, /* Portuguese (Brazil) */
182  { "pt", "PT", PORTUGUESE_STANDARD }, /* Portuguese (Portugal) */
183  { "pa", "IN", PUNJABI }, /* Windows XP and later: Punjabi (India) */
184  { "quz", "BO", QUECHUA_BOLIVIA }, /* Windows XP SP2 and later: Quechua (Bolivia) */
185  { "quz", "EC", QUECHUA_ECUADOR }, /* Windows XP SP2 and later: Quechua (Ecuador) */
186  { "quz", "PE", QUECHUA_PERU }, /* Windows XP SP2 and later: Quechua (Peru) */
187  { "ro", "RO", ROMANIAN }, /* Romanian (Romania) */
188  { "rm", "CH", ROMANSH }, /* Windows XP SP2 and later (downloadable); Windows Vista and later:
189  Romansh (Switzerland) */
190  { "ru", "RU", RUSSIAN }, /* Russian (Russia) */
191  { "smn", "FI", SAMI_INARI }, /* Windows XP SP2 and later: Sami (Inari, Finland) */
192  { "smj", "NO", SAMI_LULE_NORWAY }, /* Windows XP SP2 and later: Sami (Lule, Norway) */
193  { "smj", "SE", SAMI_LULE_SWEDEN }, /* Windows XP SP2 and later: Sami (Lule, Sweden) */
194  { "se", "FI", SAMI_NORTHERN_FINLAND }, /* Windows XP SP2 and later: Sami (Northern, Finland) */
195  { "se", "NO", SAMI_NORTHERN_NORWAY }, /* Windows XP SP2 and later: Sami (Northern, Norway) */
196  { "se", "SE", SAMI_NORTHERN_SWEDEN }, /* Windows XP SP2 and later: Sami (Northern, Sweden) */
197  { "sms", "FI", SAMI_SKOLT }, /* Windows XP SP2 and later: Sami (Skolt, Finland) */
198  { "sma", "NO", SAMI_SOUTHERN_NORWAY }, /* Windows XP SP2 and later: Sami (Southern, Norway) */
199  { "sma", "SE", SAMI_SOUTHERN_SWEDEN }, /* Windows XP SP2 and later: Sami (Southern, Sweden) */
200  { "sa", "IN", SANSKRIT }, /* Windows 2000 and later: Sanskrit (India) */
201  { "sr", "SP", SERBIAN_LATIN }, /* Serbian (Latin) */
202  { "sr", "SIH",
203  SERBIAN_LATIN_BOSNIA_HERZEGOVINA }, /* Serbian (Latin) (Bosnia and Herzegovina) */
204  { "sr", "Cyrl_SP", SERBIAN_CYRILLIC }, /* Serbian (Cyrillic) */
205  { "sr", "Cyrl_SIH",
206  SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA }, /* Serbian (Cyrillic) (Bosnia and Herzegovina) */
207  { "ns", "ZA", SESOTHO_SA_LEBOA }, /* Windows XP SP2 and later: Sesotho sa Leboa/Northern Sotho
208  (South Africa) */
209  { "tn", "ZA", TSWANA }, /* Windows XP SP2 and later: Setswana/Tswana (South Africa) */
210  { "si", "LK", SINHALA }, /* Windows Vista and later: Sinhala (Sri Lanka) */
211  { "sk", "SK", SLOVAK }, /* Slovak (Slovakia) */
212  { "sl", "SI", SLOVENIAN }, /* Slovenian (Slovenia) */
213  { "es", "AR", SPANISH_ARGENTINA }, /* Spanish (Argentina) */
214  { "es", "BO", SPANISH_BOLIVIA }, /* Spanish (Bolivia) */
215  { "es", "CL", SPANISH_CHILE }, /* Spanish (Chile) */
216  { "es", "CO", SPANISH_COLOMBIA }, /* Spanish (Colombia) */
217  { "es", "CR", SPANISH_COSTA_RICA }, /* Spanish (Costa Rica) */
218  { "es", "DO", SPANISH_DOMINICAN_REPUBLIC }, /* Spanish (Dominican Republic) */
219  { "es", "EC", SPANISH_ECUADOR }, /* Spanish (Ecuador) */
220  { "es", "SV", SPANISH_EL_SALVADOR }, /* Spanish (El Salvador) */
221  { "es", "GT", SPANISH_GUATEMALA }, /* Spanish (Guatemala) */
222  { "es", "HN", SPANISH_HONDURAS }, /* Spanish (Honduras) */
223  { "es", "MX", SPANISH_MEXICAN }, /* Spanish (Mexico) */
224  { "es", "NI", SPANISH_NICARAGUA }, /* Spanish (Nicaragua) */
225  { "es", "PA", SPANISH_PANAMA }, /* Spanish (Panama) */
226  { "es", "PY", SPANISH_PARAGUAY }, /* Spanish (Paraguay) */
227  { "es", "PE", SPANISH_PERU }, /* Spanish (Peru) */
228  { "es", "PR", SPANISH_PUERTO_RICO }, /* Spanish (Puerto Rico) */
229  { "es", "ES", SPANISH_MODERN_SORT }, /* Spanish (Spain) */
230  { "es", "ES", SPANISH_TRADITIONAL_SORT }, /* Spanish (Spain, Traditional Sort) */
231  { "es", "US", SPANISH_UNITED_STATES }, /* Windows Vista and later: Spanish (United States) */
232  { "es", "UY", SPANISH_URUGUAY }, /* Spanish (Uruguay) */
233  { "es", "VE", SPANISH_VENEZUELA }, /* Spanish (Venezuela) */
234  { "sw", "KE", SWAHILI }, /* Windows 2000 and later: Swahili (Kenya) */
235  { "sv", "FI", SWEDISH_FINLAND }, /* Swedish (Finland) */
236  { "sv", "SE", SWEDISH }, /* Swedish (Sweden) */
237  { "syr", "SY", SYRIAC }, /* Windows XP and later: Syriac (Syria) */
238  { "ta", "IN", TAMIL }, /* Windows 2000 and later: Tamil (India) */
239  { "tt", "RU", TATAR }, /* Windows XP and later: Tatar (Russia) */
240  { "te", "IN", TELUGU }, /* Windows XP and later: Telugu (India) */
241  { "th", "TH", THAI }, /* Thai (Thailand) */
242  { "bo", "BT", TIBETAN_BHUTAN }, /* Windows Vista and later: Tibetan (Bhutan) */
243  { "bo", "CN", TIBETAN_PRC }, /* Windows Vista and later: Tibetan (PRC) */
244  { "tr", "TR", TURKISH }, /* Turkish (Turkey) */
245  { "tk", "TM", TURKMEN }, /* Windows Vista and later: Turkmen (Turkmenistan) */
246  { "ug", "CN", UIGHUR }, /* Windows Vista and later: Uighur (PRC) */
247  { "uk", "UA", UKRAINIAN }, /* Ukrainian (Ukraine) */
248  { "wen", "DE", UPPER_SORBIAN }, /* Windows Vista and later: Upper Sorbian (Germany) */
249  { "tr", "IN", URDU_INDIA }, /* Urdu (India) */
250  { "ur", "PK", URDU }, /* Windows 98/Me, Windows 2000 and later: Urdu (Pakistan) */
251  { "uz", "UZ", UZBEK_LATIN }, /* Uzbek (Latin) */
252  { "uz", "Cyrl_UZ", UZBEK_CYRILLIC }, /* Uzbek (Cyrillic) */
253  { "vi", "VN", VIETNAMESE }, /* Windows 98/Me, Windows NT 4.0 and later: Vietnamese (Vietnam) */
254  { "cy", "GB", WELSH }, /* Windows XP SP2 and later: Welsh (United Kingdom) */
255  { "wo", "SN", WOLOF }, /* Windows Vista and later: Wolof (Senegal) */
256  { "xh", "ZA", XHOSA }, /* Windows XP SP2 and later: Xhosa/isiXhosa (South Africa) */
257  { "sah", "RU", YAKUT }, /* Windows Vista and later: Yakut (Russia) */
258  { "ii", "CN", YI }, /* Windows Vista and later: Yi (PRC) */
259  { "yo", "NG", YORUBA }, /* Windows Vista and later: Yoruba (Nigeria) */
260  { "zu", "ZA", ZULU } /* Windows XP SP2 and later: Zulu/isiZulu (South Africa) */
261 };
262 
263 typedef struct
264 {
265  DWORD localeId;
266  const char* name;
267 } LOCALE_NAME;
268 
269 static const LOCALE_NAME LOCALE_NAME_TABLE[] = {
270  { AFRIKAANS, "AFRIKAANS" },
271  { ALBANIAN, "ALBANIAN" },
272  { ALSATIAN, "ALSATIAN" },
273  { AMHARIC, "AMHARIC" },
274  { ARABIC_SAUDI_ARABIA, "ARABIC_SAUDI_ARABIA" },
275  { ARABIC_IRAQ, "ARABIC_IRAQ" },
276  { ARABIC_EGYPT, "ARABIC_EGYPT" },
277  { ARABIC_LIBYA, "ARABIC_LIBYA" },
278  { ARABIC_ALGERIA, "ARABIC_ALGERIA" },
279  { ARABIC_MOROCCO, "ARABIC_MOROCCO" },
280  { ARABIC_TUNISIA, "ARABIC_TUNISIA" },
281  { ARABIC_OMAN, "ARABIC_OMAN" },
282  { ARABIC_YEMEN, "ARABIC_YEMEN" },
283  { ARABIC_SYRIA, "ARABIC_SYRIA" },
284  { ARABIC_JORDAN, "ARABIC_JORDAN" },
285  { ARABIC_LEBANON, "ARABIC_LEBANON" },
286  { ARABIC_KUWAIT, "ARABIC_KUWAIT" },
287  { ARABIC_UAE, "ARABIC_UAE" },
288  { ARABIC_BAHRAIN, "ARABIC_BAHRAIN" },
289  { ARABIC_QATAR, "ARABIC_QATAR" },
290  { ARMENIAN, "ARMENIAN" },
291  { ASSAMESE, "ASSAMESE" },
292  { AZERI_LATIN, "AZERI_LATIN" },
293  { AZERI_CYRILLIC, "AZERI_CYRILLIC" },
294  { BASHKIR, "BASHKIR" },
295  { BASQUE, "BASQUE" },
296  { BELARUSIAN, "BELARUSIAN" },
297  { BENGALI_INDIA, "BENGALI_INDIA" },
298  { BOSNIAN_LATIN, "BOSNIAN_LATIN" },
299  { BRETON, "BRETON" },
300  { BULGARIAN, "BULGARIAN" },
301  { CATALAN, "CATALAN" },
302  { CHINESE_TAIWAN, "CHINESE_TAIWAN" },
303  { CHINESE_PRC, "CHINESE_PRC" },
304  { CHINESE_HONG_KONG, "CHINESE_HONG_KONG" },
305  { CHINESE_SINGAPORE, "CHINESE_SINGAPORE" },
306  { CHINESE_MACAU, "CHINESE_MACAU" },
307  { CROATIAN, "CROATIAN" },
308  { CROATIAN_BOSNIA_HERZEGOVINA, "CROATIAN_BOSNIA_HERZEGOVINA" },
309  { CZECH, "CZECH" },
310  { DANISH, "DANISH" },
311  { DARI, "DARI" },
312  { DIVEHI, "DIVEHI" },
313  { DUTCH_STANDARD, "DUTCH_STANDARD" },
314  { DUTCH_BELGIAN, "DUTCH_BELGIAN" },
315  { ENGLISH_UNITED_STATES, "ENGLISH_UNITED_STATES" },
316  { ENGLISH_UNITED_KINGDOM, "ENGLISH_UNITED_KINGDOM" },
317  { ENGLISH_AUSTRALIAN, "ENGLISH_AUSTRALIAN" },
318  { ENGLISH_CANADIAN, "ENGLISH_CANADIAN" },
319  { ENGLISH_NEW_ZEALAND, "ENGLISH_NEW_ZEALAND" },
320  { ENGLISH_INDIA, "ENGLISH_INDIA" },
321  { ENGLISH_IRELAND, "ENGLISH_IRELAND" },
322  { ENGLISH_MALAYSIA, "ENGLISH_MALAYSIA" },
323  { ENGLISH_SOUTH_AFRICA, "ENGLISH_SOUTH_AFRICA" },
324  { ENGLISH_JAMAICA, "ENGLISH_JAMAICA" },
325  { ENGLISH_CARIBBEAN, "ENGLISH_CARIBBEAN" },
326  { ENGLISH_BELIZE, "ENGLISH_BELIZE" },
327  { ENGLISH_TRINIDAD, "ENGLISH_TRINIDAD" },
328  { ENGLISH_ZIMBABWE, "ENGLISH_ZIMBABWE" },
329  { ENGLISH_PHILIPPINES, "ENGLISH_PHILIPPINES" },
330  { ENGLISH_SINGAPORE, "ENGLISH_SINGAPORE" },
331  { ESTONIAN, "ESTONIAN" },
332  { FAEROESE, "FAEROESE" },
333  { FARSI, "FARSI" },
334  { FILIPINO, "FILIPINO" },
335  { FINNISH, "FINNISH" },
336  { FRENCH_STANDARD, "FRENCH_STANDARD" },
337  { FRENCH_BELGIAN, "FRENCH_BELGIAN" },
338  { FRENCH_CANADIAN, "FRENCH_CANADIAN" },
339  { FRENCH_SWISS, "FRENCH_SWISS" },
340  { FRENCH_LUXEMBOURG, "FRENCH_LUXEMBOURG" },
341  { FRENCH_MONACO, "FRENCH_MONACO" },
342  { FRISIAN, "FRISIAN" },
343  { GEORGIAN, "GEORGIAN" },
344  { GALICIAN, "GALICIAN" },
345  { GERMAN_STANDARD, "GERMAN_STANDARD" },
346  { GERMAN_SWISS, "GERMAN_SWISS" },
347  { GERMAN_AUSTRIAN, "GERMAN_AUSTRIAN" },
348  { GERMAN_LUXEMBOURG, "GERMAN_LUXEMBOURG" },
349  { GERMAN_LIECHTENSTEIN, "GERMAN_LIECHTENSTEIN" },
350  { GREEK, "GREEK" },
351  { GREENLANDIC, "GREENLANDIC" },
352  { GUJARATI, "GUJARATI" },
353  { HEBREW, "HEBREW" },
354  { HINDI, "HINDI" },
355  { HUNGARIAN, "HUNGARIAN" },
356  { ICELANDIC, "ICELANDIC" },
357  { IGBO, "IGBO" },
358  { INDONESIAN, "INDONESIAN" },
359  { IRISH, "IRISH" },
360  { ITALIAN_STANDARD, "ITALIAN_STANDARD" },
361  { ITALIAN_SWISS, "ITALIAN_SWISS" },
362  { JAPANESE, "JAPANESE" },
363  { KANNADA, "KANNADA" },
364  { KAZAKH, "KAZAKH" },
365  { KHMER, "KHMER" },
366  { KICHE, "KICHE" },
367  { KINYARWANDA, "KINYARWANDA" },
368  { KONKANI, "KONKANI" },
369  { KOREAN, "KOREAN" },
370  { KYRGYZ, "KYRGYZ" },
371  { LAO, "LAO" },
372  { LATVIAN, "LATVIAN" },
373  { LITHUANIAN, "LITHUANIAN" },
374  { LOWER_SORBIAN, "LOWER_SORBIAN" },
375  { LUXEMBOURGISH, "LUXEMBOURGISH" },
376  { MACEDONIAN, "MACEDONIAN" },
377  { MALAY_MALAYSIA, "MALAY_MALAYSIA" },
378  { MALAY_BRUNEI_DARUSSALAM, "MALAY_BRUNEI_DARUSSALAM" },
379  { MALAYALAM, "MALAYALAM" },
380  { MALTESE, "MALTESE" },
381  { MAPUDUNGUN, "MAPUDUNGUN" },
382  { MAORI, "MAORI" },
383  { MARATHI, "MARATHI" },
384  { MOHAWK, "MOHAWK" },
385  { MONGOLIAN, "MONGOLIAN" },
386  { NEPALI, "NEPALI" },
387  { NORWEGIAN_BOKMAL, "NORWEGIAN_BOKMAL" },
388  { NORWEGIAN_NYNORSK, "NORWEGIAN_NYNORSK" },
389  { OCCITAN, "OCCITAN" },
390  { ORIYA, "ORIYA" },
391  { PASHTO, "PASHTO" },
392  { POLISH, "POLISH" },
393  { PORTUGUESE_BRAZILIAN, "PORTUGUESE_BRAZILIAN" },
394  { PORTUGUESE_STANDARD, "PORTUGUESE_STANDARD" },
395  { PUNJABI, "PUNJABI" },
396  { QUECHUA_BOLIVIA, "QUECHUA_BOLIVIA" },
397  { QUECHUA_ECUADOR, "QUECHUA_ECUADOR" },
398  { QUECHUA_PERU, "QUECHUA_PERU" },
399  { ROMANIAN, "ROMANIAN" },
400  { ROMANSH, "ROMANSH" },
401  { RUSSIAN, "RUSSIAN" },
402  { SAMI_INARI, "SAMI_INARI" },
403  { SAMI_LULE_NORWAY, "SAMI_LULE_NORWAY" },
404  { SAMI_LULE_SWEDEN, "SAMI_LULE_SWEDEN" },
405  { SAMI_NORTHERN_FINLAND, "SAMI_NORTHERN_FINLAND" },
406  { SAMI_NORTHERN_NORWAY, "SAMI_NORTHERN_NORWAY" },
407  { SAMI_NORTHERN_SWEDEN, "SAMI_NORTHERN_SWEDEN" },
408  { SAMI_SKOLT, "SAMI_SKOLT" },
409  { SAMI_SOUTHERN_NORWAY, "SAMI_SOUTHERN_NORWAY" },
410  { SAMI_SOUTHERN_SWEDEN, "SAMI_SOUTHERN_SWEDEN" },
411  { SANSKRIT, "SANSKRIT" },
412  { SERBIAN_LATIN, "SERBIAN_LATIN" },
413  { SERBIAN_LATIN_BOSNIA_HERZEGOVINA, "SERBIAN_LATIN_BOSNIA_HERZEGOVINA" },
414  { SERBIAN_CYRILLIC, "SERBIAN_CYRILLIC" },
415  { SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, "SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA" },
416  { SESOTHO_SA_LEBOA, "SESOTHO_SA_LEBOA" },
417  { SINHALA, "SINHALA" },
418  { SLOVAK, "SLOVAK" },
419  { SLOVENIAN, "SLOVENIAN" },
420  { SPANISH_TRADITIONAL_SORT, "SPANISH_TRADITIONAL_SORT" },
421  { SPANISH_MEXICAN, "SPANISH_MEXICAN" },
422  { SPANISH_MODERN_SORT, "SPANISH_MODERN_SORT" },
423  { SPANISH_GUATEMALA, "SPANISH_GUATEMALA" },
424  { SPANISH_COSTA_RICA, "SPANISH_COSTA_RICA" },
425  { SPANISH_PANAMA, "SPANISH_PANAMA" },
426  { SPANISH_DOMINICAN_REPUBLIC, "SPANISH_DOMINICAN_REPUBLIC" },
427  { SPANISH_VENEZUELA, "SPANISH_VENEZUELA" },
428  { SPANISH_COLOMBIA, "SPANISH_COLOMBIA" },
429  { SPANISH_PERU, "SPANISH_PERU" },
430  { SPANISH_ARGENTINA, "SPANISH_ARGENTINA" },
431  { SPANISH_ECUADOR, "SPANISH_ECUADOR" },
432  { SPANISH_CHILE, "SPANISH_CHILE" },
433  { SPANISH_UNITED_STATES, "SPANISH_UNITED_STATES" },
434  { SPANISH_URUGUAY, "SPANISH_URUGUAY" },
435  { SPANISH_PARAGUAY, "SPANISH_PARAGUAY" },
436  { SPANISH_BOLIVIA, "SPANISH_BOLIVIA" },
437  { SPANISH_EL_SALVADOR, "SPANISH_EL_SALVADOR" },
438  { SPANISH_HONDURAS, "SPANISH_HONDURAS" },
439  { SPANISH_NICARAGUA, "SPANISH_NICARAGUA" },
440  { SPANISH_PUERTO_RICO, "SPANISH_PUERTO_RICO" },
441  { SWAHILI, "SWAHILI" },
442  { SWEDISH, "SWEDISH" },
443  { SWEDISH_FINLAND, "SWEDISH_FINLAND" },
444  { SYRIAC, "SYRIAC" },
445  { TAMIL, "TAMIL" },
446  { TATAR, "TATAR" },
447  { TELUGU, "TELUGU" },
448  { THAI, "THAI" },
449  { TIBETAN_BHUTAN, "TIBETAN_BHUTAN" },
450  { TIBETAN_PRC, "TIBETAN_PRC" },
451  { TSWANA, "TSWANA" },
452  { UKRAINIAN, "UKRAINIAN" },
453  { TURKISH, "TURKISH" },
454  { TURKMEN, "TURKMEN" },
455  { UIGHUR, "UIGHUR" },
456  { UPPER_SORBIAN, "UPPER_SORBIAN" },
457  { URDU, "URDU" },
458  { URDU_INDIA, "URDU_INDIA" },
459  { UZBEK_LATIN, "UZBEK_LATIN" },
460  { UZBEK_CYRILLIC, "UZBEK_CYRILLIC" },
461  { VIETNAMESE, "VIETNAMESE" },
462  { WELSH, "WELSH" },
463  { WOLOF, "WOLOF" },
464  { XHOSA, "XHOSA" },
465  { YAKUT, "YAKUT" },
466  { YI, "YI" },
467  { YORUBA, "YORUBA" },
468  { ZULU, "ZULU" }
469 };
470 
471 typedef struct
472 {
473  DWORD locale; /* Locale ID */
474  DWORD keyboardLayouts[5]; /* array of associated keyboard layouts */
475 } LOCALE_KEYBOARD_LAYOUTS;
476 
477 /* TODO: Use KBD_* defines instead of hardcoded values */
478 
479 static const LOCALE_KEYBOARD_LAYOUTS LOCALE_KEYBOARD_LAYOUTS_TABLE[] = {
480  { AFRIKAANS, { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
481  { ALBANIAN, { 0x0000041c, 0x00000409, 0x0, 0x0, 0x0 } },
482  { ARABIC_SAUDI_ARABIA, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
483  { ARABIC_IRAQ, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
484  { ARABIC_EGYPT, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
485  { ARABIC_LIBYA, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
486  { ARABIC_ALGERIA, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
487  { ARABIC_MOROCCO, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
488  { ARABIC_TUNISIA, { 0x0000040c, 0x00020401, 0x0, 0x0, 0x0 } },
489  { ARABIC_OMAN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
490  { ARABIC_YEMEN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
491  { ARABIC_SYRIA, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
492  { ARABIC_JORDAN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
493  { ARABIC_LEBANON, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
494  { ARABIC_KUWAIT, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
495  { ARABIC_UAE, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
496  { ARABIC_BAHRAIN, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
497  { ARABIC_QATAR, { 0x00000409, 0x00000401, 0x0, 0x0, 0x0 } },
498  { ARMENIAN, { 0x0000042b, 0x00000409, 0x00000419, 0x0, 0x0 } },
499  { AZERI_LATIN, { 0x0000042c, 0x0000082c, 0x00000419, 0x0, 0x0 } },
500  { AZERI_CYRILLIC, { 0x0000082c, 0x0000042c, 0x00000419, 0x0, 0x0 } },
501  { BASQUE, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
502  { BELARUSIAN, { 0x00000423, 0x00000409, 0x00000419, 0x0, 0x0 } },
503  { BENGALI_INDIA, { 0x00000445, 0x00000409, 0x0, 0x0, 0x0 } },
504  { BOSNIAN_LATIN, { 0x0000141A, 0x00000409, 0x0, 0x0, 0x0 } },
505  { BULGARIAN, { 0x00000402, 0x00000409, 0x0, 0x0, 0x0 } },
506  { CATALAN, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
507  { CHINESE_TAIWAN, { 0x00000404, 0xe0080404, 0xE0010404, 0x0, 0x0 } },
508  { CHINESE_PRC, { 0x00000804, 0xe00e0804, 0xe0010804, 0xe0030804, 0xe0040804 } },
509  { CHINESE_HONG_KONG, { 0x00000409, 0xe0080404, 0x0, 0x0, 0x0 } },
510  { CHINESE_SINGAPORE, { 0x00000409, 0xe00e0804, 0xe0010804, 0xe0030804, 0xe0040804 } },
511  { CHINESE_MACAU, { 0x00000409, 0xe00e0804, 0xe0020404, 0xe0080404 } },
512  { CROATIAN, { 0x0000041a, 0x00000409, 0x0, 0x0, 0x0 } },
513  { CROATIAN_BOSNIA_HERZEGOVINA, { 0x0000041a, 0x00000409, 0x0, 0x0, 0x0 } },
514  { CZECH, { 0x00000405, 0x00000409, 0x0, 0x0, 0x0 } },
515  { DANISH, { 0x00000406, 0x00000409, 0x0, 0x0, 0x0 } },
516  { DIVEHI, { 0x00000409, 0x00000465, 0x0, 0x0, 0x0 } },
517  { DUTCH_STANDARD, { 0x00020409, 0x00000413, 0x00000409, 0x0, 0x0 } },
518  { DUTCH_BELGIAN, { 0x00000813, 0x00000409, 0x0, 0x0, 0x0 } },
519  { ENGLISH_UNITED_STATES, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
520  { ENGLISH_UNITED_KINGDOM, { 0x00000809, 0x0, 0x0, 0x0, 0x0 } },
521  { ENGLISH_AUSTRALIAN, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
522  { ENGLISH_CANADIAN, { 0x00000409, 0x00011009, 0x00001009, 0x0, 0x0 } },
523  { ENGLISH_NEW_ZEALAND, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
524  { ENGLISH_IRELAND, { 0x00001809, 0x00011809, 0x0, 0x0, 0x0 } },
525  { ENGLISH_SOUTH_AFRICA, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
526  { ENGLISH_JAMAICA, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
527  { ENGLISH_CARIBBEAN, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
528  { ENGLISH_BELIZE, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
529  { ENGLISH_TRINIDAD, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
530  { ENGLISH_ZIMBABWE, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
531  { ENGLISH_PHILIPPINES, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
532  { ESTONIAN, { 0x00000425, 0x0, 0x0, 0x0, 0x0 } },
533  { FAEROESE, { 0x00000406, 0x00000409, 0x0, 0x0, 0x0 } },
534  { FARSI, { 0x00000409, 0x00000429, 0x00000401, 0x0, 0x0 } },
535  { FINNISH, { 0x0000040b, 0x00000409, 0x0, 0x0, 0x0 } },
536  { FRENCH_STANDARD, { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
537  { FRENCH_BELGIAN, { 0x0000080c, 0x00000409, 0x0, 0x0, 0x0 } },
538  { FRENCH_CANADIAN, { 0x00000C0C, 0x00011009, 0x00000409, 0x0, 0x0 } },
539  { FRENCH_SWISS, { 0x0000100c, 0x00000409, 0x0, 0x0, 0x0 } },
540  { FRENCH_LUXEMBOURG, { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
541  { FRENCH_MONACO, { 0x0000040c, 0x00000409, 0x0, 0x0, 0x0 } },
542  { GEORGIAN, { 0x00000437, 0x00000409, 0x00000419, 0x0, 0x0 } },
543  { GALICIAN, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
544  { GERMAN_STANDARD, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
545  { GERMAN_SWISS, { 0x00000807, 0x00000409, 0x0, 0x0, 0x0 } },
546  { GERMAN_AUSTRIAN, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
547  { GERMAN_LUXEMBOURG, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
548  { GERMAN_LIECHTENSTEIN, { 0x00000407, 0x00000409, 0x0, 0x0, 0x0 } },
549  { GREEK, { 0x00000408, 0x00000409, 0x0, 0x0, 0x0 } },
550  { GUJARATI, { 0x00000409, 0x00000447, 0x00010439, 0x0, 0x0 } },
551  { HEBREW, { 0x00000409, 0x0000040d, 0x0, 0x0, 0x0 } },
552  { HINDI, { 0x00000409, 0x00010439, 0x00000439, 0x0, 0x0 } },
553  { HUNGARIAN, { 0x0000040e, 0x00000409, 0x0, 0x0, 0x0 } },
554  { ICELANDIC, { 0x0000040f, 0x00000409, 0x0, 0x0, 0x0 } },
555  { INDONESIAN, { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
556  { ITALIAN_STANDARD, { 0x00000410, 0x00000409, 0x0, 0x0, 0x0 } },
557  { ITALIAN_SWISS, { 0x00000410, 0x00000409, 0x0, 0x0, 0x0 } },
558  { JAPANESE, { 0xe0010411, 0x0, 0x0, 0x0, 0x0 } },
559  { KANNADA, { 0x00000409, 0x0000044b, 0x00010439, 0x0, 0x0 } },
560  { KAZAKH, { 0x0000043f, 0x00000409, 0x00000419, 0x0, 0x0 } },
561  { KONKANI, { 0x00000409, 0x00000439, 0x0, 0x0, 0x0 } },
562  { KOREAN, { 0xE0010412, 0x0, 0x0, 0x0, 0x0 } },
563  { KYRGYZ, { 0x00000440, 0x00000409, 0x0, 0x0, 0x0 } },
564  { LATVIAN, { 0x00010426, 0x0, 0x0, 0x0, 0x0 } },
565  { LITHUANIAN, { 0x00010427, 0x0, 0x0, 0x0, 0x0 } },
566  { MACEDONIAN, { 0x0000042f, 0x00000409, 0x0, 0x0, 0x0 } },
567  { MALAY_MALAYSIA, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
568  { MALAY_BRUNEI_DARUSSALAM, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
569  { MALAYALAM, { 0x00000409, 0x0000044c, 0x0, 0x0, 0x0 } },
570  { MALTESE, { 0x00000409, 0x0000043a, 0x0, 0x0, 0x0 } },
571  { MAORI, { 0x00000409, 0x00000481, 0x0, 0x0, 0x0 } },
572  { MARATHI, { 0x00000409, 0x0000044e, 0x00000439, 0x0, 0x0 } },
573  { MONGOLIAN, { 0x00000450, 0x00000409, 0x0, 0x0, 0x0 } },
574  { NORWEGIAN_BOKMAL, { 0x00000414, 0x00000409, 0x0, 0x0, 0x0 } },
575  { NORWEGIAN_NYNORSK, { 0x00000414, 0x00000409, 0x0, 0x0, 0x0 } },
576  { POLISH, { 0x00010415, 0x00000415, 0x00000409, 0x0, 0x0 } },
577  { PORTUGUESE_BRAZILIAN, { 0x00000416, 0x00000409, 0x0, 0x0, 0x0 } },
578  { PORTUGUESE_STANDARD, { 0x00000816, 0x00000409, 0x0, 0x0, 0x0 } },
579  { PUNJABI, { 0x00000409, 0x00000446, 0x00010439, 0x0, 0x0 } },
580  { QUECHUA_BOLIVIA, { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
581  { QUECHUA_ECUADOR, { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
582  { QUECHUA_PERU, { 0x00000409, 0x0000080A, 0x0, 0x0, 0x0 } },
583  { ROMANIAN, { 0x00000418, 0x00000409, 0x0, 0x0, 0x0 } },
584  { RUSSIAN, { 0x00000419, 0x00000409, 0x0, 0x0, 0x0 } },
585  { SAMI_INARI, { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
586  { SAMI_LULE_NORWAY, { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
587  { SAMI_LULE_SWEDEN, { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
588  { SAMI_NORTHERN_FINLAND, { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
589  { SAMI_NORTHERN_NORWAY, { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
590  { SAMI_NORTHERN_SWEDEN, { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
591  { SAMI_SKOLT, { 0x0001083b, 0x00000409, 0x0, 0x0, 0x0 } },
592  { SAMI_SOUTHERN_NORWAY, { 0x0000043b, 0x00000409, 0x0, 0x0, 0x0 } },
593  { SAMI_SOUTHERN_SWEDEN, { 0x0000083b, 0x00000409, 0x0, 0x0, 0x0 } },
594  { SANSKRIT, { 0x00000409, 0x00000439, 0x0, 0x0, 0x0 } },
595  { SERBIAN_LATIN, { 0x0000081a, 0x00000409, 0x0, 0x0, 0x0 } },
596  { SERBIAN_LATIN_BOSNIA_HERZEGOVINA, { 0x0000081a, 0x00000409, 0x0, 0x0, 0x0 } },
597  { SERBIAN_CYRILLIC, { 0x00000c1a, 0x00000409, 0x0, 0x0, 0x0 } },
598  { SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA, { 0x00000c1a, 0x00000409, 0x0, 0x0, 0x0 } },
599  { SLOVAK, { 0x0000041b, 0x00000409, 0x0, 0x0, 0x0 } },
600  { SLOVENIAN, { 0x00000424, 0x00000409, 0x0, 0x0, 0x0 } },
601  { SPANISH_TRADITIONAL_SORT, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
602  { SPANISH_MEXICAN, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
603  { SPANISH_MODERN_SORT, { 0x0000040a, 0x00000409, 0x0, 0x0, 0x0 } },
604  { SPANISH_GUATEMALA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
605  { SPANISH_COSTA_RICA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
606  { SPANISH_PANAMA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
607  { SPANISH_DOMINICAN_REPUBLIC, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
608  { SPANISH_VENEZUELA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
609  { SPANISH_COLOMBIA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
610  { SPANISH_PERU, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
611  { SPANISH_ARGENTINA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
612  { SPANISH_ECUADOR, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
613  { SPANISH_CHILE, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
614  { SPANISH_URUGUAY, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
615  { SPANISH_PARAGUAY, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
616  { SPANISH_BOLIVIA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
617  { SPANISH_EL_SALVADOR, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
618  { SPANISH_HONDURAS, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
619  { SPANISH_NICARAGUA, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
620  { SPANISH_PUERTO_RICO, { 0x0000080a, 0x00000409, 0x0, 0x0, 0x0 } },
621  { SWAHILI, { 0x00000409, 0x0, 0x0, 0x0, 0x0 } },
622  { SWEDISH, { 0x0000041d, 0x00000409, 0x0, 0x0, 0x0 } },
623  { SWEDISH_FINLAND, { 0x0000041d, 0x00000409, 0x0, 0x0, 0x0 } },
624  { SYRIAC, { 0x00000409, 0x0000045a, 0x0, 0x0, 0x0 } },
625  { TAMIL, { 0x00000409, 0x00000449, 0x0, 0x0, 0x0 } },
626  { TATAR, { 0x00000444, 0x00000409, 0x00000419, 0x0, 0x0 } },
627  { TELUGU, { 0x00000409, 0x0000044a, 0x00010439, 0x0, 0x0 } },
628  { THAI, { 0x00000409, 0x0000041e, 0x0, 0x0, 0x0 } },
629  { TSWANA, { 0x00000409, 0x0000041f, 0x0, 0x0, 0x0 } },
630  { UKRAINIAN, { 0x00000422, 0x00000409, 0x0, 0x0, 0x0 } },
631  { TURKISH, { 0x0000041f, 0x0000041f, 0x0, 0x0, 0x0 } },
632  { UKRAINIAN, { 0x00000422, 0x00000409, 0x0, 0x0, 0x0 } },
633  { URDU, { 0x00000401, 0x00000409, 0x0, 0x0, 0x0 } },
634  { UZBEK_LATIN, { 0x00000409, 0x00000843, 0x00000419, 0x0, 0x0 } },
635  { UZBEK_CYRILLIC, { 0x00000843, 0x00000409, 0x00000419, 0x0, 0x0 } },
636  { VIETNAMESE, { 0x00000409, 0x0000042a, 0x0, 0x0, 0x0 } },
637  { WELSH, { 0x00000452, 0x00000809, 0x0, 0x0, 0x0 } },
638  { XHOSA, { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
639 };
640 
641 static BOOL freerdp_get_system_language_and_country_codes(char* language, size_t languageLen,
642  char* country, size_t countryLen)
643 {
644  WINPR_ASSERT(language);
645  WINPR_ASSERT(languageLen > 0);
646  WINPR_ASSERT(country);
647  WINPR_ASSERT(countryLen);
648 
649 #if defined(__APPLE__)
650  {
651  CFStringRef langRef, countryRef;
652  CFLocaleRef localeRef = CFLocaleCopyCurrent();
653  if (!localeRef)
654  return FALSE;
655 
656  langRef = (CFStringRef)CFLocaleGetValue(localeRef, kCFLocaleLanguageCode);
657  countryRef = (CFStringRef)CFLocaleGetValue(localeRef, kCFLocaleCountryCode);
658  if (!langRef || !countryRef)
659  {
660  CFRelease(localeRef);
661  return FALSE;
662  }
663 
664  if (!CFStringGetCString(langRef, language, languageLen, kCFStringEncodingUTF8) ||
665  !CFStringGetCString(countryRef, country, countryLen, kCFStringEncodingUTF8))
666  {
667  CFRelease(localeRef);
668  return FALSE;
669  }
670 
671  CFRelease(localeRef);
672  return TRUE;
673  }
674 #else
675  {
676  size_t dot = 0;
677  DWORD nSize = 0;
678  size_t underscore = 0;
679  char* env_lang = NULL;
680  LPCSTR lang = "LANG";
681  /* LANG = <language>_<country>.<encoding> */
682  nSize = GetEnvironmentVariableA(lang, NULL, 0);
683 
684  if (!nSize)
685  return FALSE; /* LANG environment variable was not set */
686 
687  env_lang = (char*)malloc(nSize);
688 
689  if (!env_lang)
690  return FALSE;
691 
692  if (GetEnvironmentVariableA(lang, env_lang, nSize) !=
693  nSize - 1) /* Get locale from environment variable LANG */
694  {
695  free(env_lang);
696  return FALSE;
697  }
698 
699  underscore = strcspn(env_lang, "_");
700 
701  if (underscore > 3)
702  {
703  free(env_lang);
704  return FALSE; /* The language name should not be more than 3 letters long */
705  }
706  else
707  {
708  /* Get language code */
709  size_t len = MIN(languageLen - 1u, underscore);
710  strncpy(language, env_lang, len);
711  language[len] = '\0';
712  }
713 
714  dot = strcspn(env_lang, ".");
715 
716  /* Get country code */
717  if (dot > underscore)
718  {
719  size_t len = MIN(countryLen - 1, dot - underscore - 1);
720  strncpy(country, &env_lang[underscore + 1], len);
721  country[len] = '\0';
722  }
723  else
724  {
725  free(env_lang);
726  return FALSE; /* Invalid locale */
727  }
728 
729  free(env_lang);
730  return TRUE;
731  }
732 #endif
733 }
734 
735 static const SYSTEM_LOCALE* freerdp_detect_system_locale(void)
736 {
737  char language[LOCALE_LANGUAGE_LEN] = { 0 };
738  char country[LOCALE_COUNTRY_LEN] = { 0 };
739  const SYSTEM_LOCALE* locale = NULL;
740 
741  freerdp_get_system_language_and_country_codes(language, ARRAYSIZE(language), country,
742  ARRAYSIZE(country));
743 
744  for (size_t i = 0; i < ARRAYSIZE(SYSTEM_LOCALE_TABLE); i++)
745  {
746  const SYSTEM_LOCALE* current = &SYSTEM_LOCALE_TABLE[i];
747 
748  if ((strcmp(language, current->language) == 0) && (strcmp(country, current->country) == 0))
749  {
750  locale = current;
751  break;
752  }
753  }
754 
755  return locale;
756 }
757 
758 DWORD freerdp_get_system_locale_id(void)
759 {
760  const SYSTEM_LOCALE* locale = NULL;
761  locale = freerdp_detect_system_locale();
762 
763  if (locale != NULL)
764  return locale->code;
765 
766  return 0;
767 }
768 
769 static const SYSTEM_LOCALE* get_locale_from_str(const char* name)
770 {
771  for (size_t i = 0; i < ARRAYSIZE(SYSTEM_LOCALE_TABLE); i++)
772  {
773  char buffer[LOCALE_LANGUAGE_LEN + LOCALE_COUNTRY_LEN + 2] = { 0 };
774  const SYSTEM_LOCALE* current = &SYSTEM_LOCALE_TABLE[i];
775 
776  (void)_snprintf(buffer, sizeof(buffer), "%s_%s", current->language, current->country);
777  /* full match, e.g. en_US */
778  if ((strcmp(name, buffer) == 0))
779  return current;
780  /* simple language only match e.g. 'en' */
781  else if ((strcmp(name, current->language) == 0))
782  return current;
783  }
784  return NULL;
785 }
786 
787 static INT64 get_layout_from_locale(const SYSTEM_LOCALE* locale)
788 {
789  for (size_t i = 0; i < ARRAYSIZE(LOCALE_KEYBOARD_LAYOUTS_TABLE); i++)
790  {
791  const LOCALE_KEYBOARD_LAYOUTS* current = &LOCALE_KEYBOARD_LAYOUTS_TABLE[i];
792  WINPR_ASSERT(current);
793 
794  if (current->locale == locale->code)
795  {
796  /* Locale found in list of default keyboard layouts */
797  for (size_t j = 0; j < 5; j++)
798  {
799  if (current->keyboardLayouts[j] == ENGLISH_UNITED_STATES)
800  {
801  continue; /* Skip, try to get a more localized keyboard layout */
802  }
803  else if (current->keyboardLayouts[j] == 0)
804  {
805  /*
806  * If we skip the ENGLISH_UNITED_STATES keyboard layout but there are no
807  * other possible keyboard layout for the locale, we end up here with k > 1
808  */
809 
810  if (j >= 1)
811  return ENGLISH_UNITED_STATES;
812 
813  /* No more keyboard layouts */
814  break;
815  }
816  else
817  return current->keyboardLayouts[j];
818  }
819  }
820  }
821  return -1;
822 }
823 
824 const char* freerdp_get_system_locale_name_from_id(DWORD localeId)
825 {
826  for (size_t index = 0; index < ARRAYSIZE(LOCALE_NAME_TABLE); index++)
827  {
828  const LOCALE_NAME* current = &LOCALE_NAME_TABLE[index];
829 
830  if (localeId == current->localeId)
831  return current->name;
832  }
833 
834  return NULL;
835 }
836 
837 INT64 freerdp_get_locale_id_from_string(const char* locale)
838 {
839  const SYSTEM_LOCALE* loc = get_locale_from_str(locale);
840  if (!loc)
841  return -1;
842  return loc->code;
843 }
844 
845 int freerdp_detect_keyboard_layout_from_system_locale(DWORD* keyboardLayoutId)
846 {
847  char language[LOCALE_LANGUAGE_LEN] = { 0 };
848  char country[LOCALE_COUNTRY_LEN] = { 0 };
849 
850  freerdp_get_system_language_and_country_codes(language, ARRAYSIZE(language), country,
851  ARRAYSIZE(country));
852 
853  if ((strcmp(language, "C") == 0) || (strcmp(language, "POSIX") == 0))
854  {
855  *keyboardLayoutId = ENGLISH_UNITED_STATES; /* U.S. Keyboard Layout */
856  return 0;
857  }
858 
859  const SYSTEM_LOCALE* locale = freerdp_detect_system_locale();
860 
861  if (!locale)
862  return -1;
863 
864  DEBUG_KBD("Found locale : %s_%s", locale->language, locale->country);
865  INT64 rc = get_layout_from_locale(locale);
866  if (rc < 0)
867  return -1; /* Could not detect the current keyboard layout from locale */
868  *keyboardLayoutId = (DWORD)rc;
869  return 0;
870 }
871 
872 const SYSTEM_LOCALE* freerdp_get_system_locale_list(size_t* count)
873 {
874  WINPR_ASSERT(count);
875  *count = ARRAYSIZE(SYSTEM_LOCALE_TABLE);
876  return SYSTEM_LOCALE_TABLE;
877 }
878 
879 DWORD freerdp_get_keyboard_default_layout_for_locale(DWORD locale)
880 {
881  for (size_t x = 0; x < ARRAYSIZE(LOCALE_KEYBOARD_LAYOUTS_TABLE); x++)
882  {
883  const LOCALE_KEYBOARD_LAYOUTS* cur = &LOCALE_KEYBOARD_LAYOUTS_TABLE[x];
884  if (cur->locale == locale)
885  return cur->keyboardLayouts[0];
886  }
887  return 0;
888 }
A SYSTEM_LOCALE holding details about a locale.
Definition: locale.h:254