1*a8fa202aSchristos /* $NetBSD: localename.c,v 1.1.1.1 2016/01/10 21:36:18 christos Exp $ */
2*a8fa202aSchristos
3*a8fa202aSchristos /* Determine the current selected locale.
4*a8fa202aSchristos Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
5*a8fa202aSchristos
6*a8fa202aSchristos This program is free software; you can redistribute it and/or modify
7*a8fa202aSchristos it under the terms of the GNU General Public License as published by
8*a8fa202aSchristos the Free Software Foundation; either version 2, or (at your option)
9*a8fa202aSchristos any later version.
10*a8fa202aSchristos
11*a8fa202aSchristos This program is distributed in the hope that it will be useful,
12*a8fa202aSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
13*a8fa202aSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*a8fa202aSchristos GNU General Public License for more details.
15*a8fa202aSchristos
16*a8fa202aSchristos You should have received a copy of the GNU General Public License
17*a8fa202aSchristos along with this program; if not, write to the Free Software Foundation,
18*a8fa202aSchristos Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19*a8fa202aSchristos
20*a8fa202aSchristos /* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
21*a8fa202aSchristos /* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
22*a8fa202aSchristos
23*a8fa202aSchristos #ifdef HAVE_CONFIG_H
24*a8fa202aSchristos # include <config.h>
25*a8fa202aSchristos #endif
26*a8fa202aSchristos
27*a8fa202aSchristos #include <stdlib.h>
28*a8fa202aSchristos #include <locale.h>
29*a8fa202aSchristos
30*a8fa202aSchristos #if defined _WIN32 || defined __WIN32__
31*a8fa202aSchristos # undef WIN32 /* avoid warning on mingw32 */
32*a8fa202aSchristos # define WIN32
33*a8fa202aSchristos #endif
34*a8fa202aSchristos
35*a8fa202aSchristos #ifdef WIN32
36*a8fa202aSchristos # define WIN32_LEAN_AND_MEAN
37*a8fa202aSchristos # include <windows.h>
38*a8fa202aSchristos /* Mingw headers don't have latest language and sublanguage codes. */
39*a8fa202aSchristos # ifndef LANG_AFRIKAANS
40*a8fa202aSchristos # define LANG_AFRIKAANS 0x36
41*a8fa202aSchristos # endif
42*a8fa202aSchristos # ifndef LANG_ALBANIAN
43*a8fa202aSchristos # define LANG_ALBANIAN 0x1c
44*a8fa202aSchristos # endif
45*a8fa202aSchristos # ifndef LANG_ARABIC
46*a8fa202aSchristos # define LANG_ARABIC 0x01
47*a8fa202aSchristos # endif
48*a8fa202aSchristos # ifndef LANG_ARMENIAN
49*a8fa202aSchristos # define LANG_ARMENIAN 0x2b
50*a8fa202aSchristos # endif
51*a8fa202aSchristos # ifndef LANG_ASSAMESE
52*a8fa202aSchristos # define LANG_ASSAMESE 0x4d
53*a8fa202aSchristos # endif
54*a8fa202aSchristos # ifndef LANG_AZERI
55*a8fa202aSchristos # define LANG_AZERI 0x2c
56*a8fa202aSchristos # endif
57*a8fa202aSchristos # ifndef LANG_BASQUE
58*a8fa202aSchristos # define LANG_BASQUE 0x2d
59*a8fa202aSchristos # endif
60*a8fa202aSchristos # ifndef LANG_BELARUSIAN
61*a8fa202aSchristos # define LANG_BELARUSIAN 0x23
62*a8fa202aSchristos # endif
63*a8fa202aSchristos # ifndef LANG_BENGALI
64*a8fa202aSchristos # define LANG_BENGALI 0x45
65*a8fa202aSchristos # endif
66*a8fa202aSchristos # ifndef LANG_CATALAN
67*a8fa202aSchristos # define LANG_CATALAN 0x03
68*a8fa202aSchristos # endif
69*a8fa202aSchristos # ifndef LANG_ESTONIAN
70*a8fa202aSchristos # define LANG_ESTONIAN 0x25
71*a8fa202aSchristos # endif
72*a8fa202aSchristos # ifndef LANG_FAEROESE
73*a8fa202aSchristos # define LANG_FAEROESE 0x38
74*a8fa202aSchristos # endif
75*a8fa202aSchristos # ifndef LANG_FARSI
76*a8fa202aSchristos # define LANG_FARSI 0x29
77*a8fa202aSchristos # endif
78*a8fa202aSchristos # ifndef LANG_GEORGIAN
79*a8fa202aSchristos # define LANG_GEORGIAN 0x37
80*a8fa202aSchristos # endif
81*a8fa202aSchristos # ifndef LANG_GUJARATI
82*a8fa202aSchristos # define LANG_GUJARATI 0x47
83*a8fa202aSchristos # endif
84*a8fa202aSchristos # ifndef LANG_HEBREW
85*a8fa202aSchristos # define LANG_HEBREW 0x0d
86*a8fa202aSchristos # endif
87*a8fa202aSchristos # ifndef LANG_HINDI
88*a8fa202aSchristos # define LANG_HINDI 0x39
89*a8fa202aSchristos # endif
90*a8fa202aSchristos # ifndef LANG_INDONESIAN
91*a8fa202aSchristos # define LANG_INDONESIAN 0x21
92*a8fa202aSchristos # endif
93*a8fa202aSchristos # ifndef LANG_KANNADA
94*a8fa202aSchristos # define LANG_KANNADA 0x4b
95*a8fa202aSchristos # endif
96*a8fa202aSchristos # ifndef LANG_KASHMIRI
97*a8fa202aSchristos # define LANG_KASHMIRI 0x60
98*a8fa202aSchristos # endif
99*a8fa202aSchristos # ifndef LANG_KAZAK
100*a8fa202aSchristos # define LANG_KAZAK 0x3f
101*a8fa202aSchristos # endif
102*a8fa202aSchristos # ifndef LANG_KONKANI
103*a8fa202aSchristos # define LANG_KONKANI 0x57
104*a8fa202aSchristos # endif
105*a8fa202aSchristos # ifndef LANG_LATVIAN
106*a8fa202aSchristos # define LANG_LATVIAN 0x26
107*a8fa202aSchristos # endif
108*a8fa202aSchristos # ifndef LANG_LITHUANIAN
109*a8fa202aSchristos # define LANG_LITHUANIAN 0x27
110*a8fa202aSchristos # endif
111*a8fa202aSchristos # ifndef LANG_MACEDONIAN
112*a8fa202aSchristos # define LANG_MACEDONIAN 0x2f
113*a8fa202aSchristos # endif
114*a8fa202aSchristos # ifndef LANG_MALAY
115*a8fa202aSchristos # define LANG_MALAY 0x3e
116*a8fa202aSchristos # endif
117*a8fa202aSchristos # ifndef LANG_MALAYALAM
118*a8fa202aSchristos # define LANG_MALAYALAM 0x4c
119*a8fa202aSchristos # endif
120*a8fa202aSchristos # ifndef LANG_MANIPURI
121*a8fa202aSchristos # define LANG_MANIPURI 0x58
122*a8fa202aSchristos # endif
123*a8fa202aSchristos # ifndef LANG_MARATHI
124*a8fa202aSchristos # define LANG_MARATHI 0x4e
125*a8fa202aSchristos # endif
126*a8fa202aSchristos # ifndef LANG_NEPALI
127*a8fa202aSchristos # define LANG_NEPALI 0x61
128*a8fa202aSchristos # endif
129*a8fa202aSchristos # ifndef LANG_ORIYA
130*a8fa202aSchristos # define LANG_ORIYA 0x48
131*a8fa202aSchristos # endif
132*a8fa202aSchristos # ifndef LANG_PUNJABI
133*a8fa202aSchristos # define LANG_PUNJABI 0x46
134*a8fa202aSchristos # endif
135*a8fa202aSchristos # ifndef LANG_SANSKRIT
136*a8fa202aSchristos # define LANG_SANSKRIT 0x4f
137*a8fa202aSchristos # endif
138*a8fa202aSchristos # ifndef LANG_SERBIAN
139*a8fa202aSchristos # define LANG_SERBIAN 0x1a
140*a8fa202aSchristos # endif
141*a8fa202aSchristos # ifndef LANG_SINDHI
142*a8fa202aSchristos # define LANG_SINDHI 0x59
143*a8fa202aSchristos # endif
144*a8fa202aSchristos # ifndef LANG_SLOVAK
145*a8fa202aSchristos # define LANG_SLOVAK 0x1b
146*a8fa202aSchristos # endif
147*a8fa202aSchristos # ifndef LANG_SWAHILI
148*a8fa202aSchristos # define LANG_SWAHILI 0x41
149*a8fa202aSchristos # endif
150*a8fa202aSchristos # ifndef LANG_TAMIL
151*a8fa202aSchristos # define LANG_TAMIL 0x49
152*a8fa202aSchristos # endif
153*a8fa202aSchristos # ifndef LANG_TATAR
154*a8fa202aSchristos # define LANG_TATAR 0x44
155*a8fa202aSchristos # endif
156*a8fa202aSchristos # ifndef LANG_TELUGU
157*a8fa202aSchristos # define LANG_TELUGU 0x4a
158*a8fa202aSchristos # endif
159*a8fa202aSchristos # ifndef LANG_THAI
160*a8fa202aSchristos # define LANG_THAI 0x1e
161*a8fa202aSchristos # endif
162*a8fa202aSchristos # ifndef LANG_UKRAINIAN
163*a8fa202aSchristos # define LANG_UKRAINIAN 0x22
164*a8fa202aSchristos # endif
165*a8fa202aSchristos # ifndef LANG_URDU
166*a8fa202aSchristos # define LANG_URDU 0x20
167*a8fa202aSchristos # endif
168*a8fa202aSchristos # ifndef LANG_UZBEK
169*a8fa202aSchristos # define LANG_UZBEK 0x43
170*a8fa202aSchristos # endif
171*a8fa202aSchristos # ifndef LANG_VIETNAMESE
172*a8fa202aSchristos # define LANG_VIETNAMESE 0x2a
173*a8fa202aSchristos # endif
174*a8fa202aSchristos # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
175*a8fa202aSchristos # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
176*a8fa202aSchristos # endif
177*a8fa202aSchristos # ifndef SUBLANG_ARABIC_IRAQ
178*a8fa202aSchristos # define SUBLANG_ARABIC_IRAQ 0x02
179*a8fa202aSchristos # endif
180*a8fa202aSchristos # ifndef SUBLANG_ARABIC_EGYPT
181*a8fa202aSchristos # define SUBLANG_ARABIC_EGYPT 0x03
182*a8fa202aSchristos # endif
183*a8fa202aSchristos # ifndef SUBLANG_ARABIC_LIBYA
184*a8fa202aSchristos # define SUBLANG_ARABIC_LIBYA 0x04
185*a8fa202aSchristos # endif
186*a8fa202aSchristos # ifndef SUBLANG_ARABIC_ALGERIA
187*a8fa202aSchristos # define SUBLANG_ARABIC_ALGERIA 0x05
188*a8fa202aSchristos # endif
189*a8fa202aSchristos # ifndef SUBLANG_ARABIC_MOROCCO
190*a8fa202aSchristos # define SUBLANG_ARABIC_MOROCCO 0x06
191*a8fa202aSchristos # endif
192*a8fa202aSchristos # ifndef SUBLANG_ARABIC_TUNISIA
193*a8fa202aSchristos # define SUBLANG_ARABIC_TUNISIA 0x07
194*a8fa202aSchristos # endif
195*a8fa202aSchristos # ifndef SUBLANG_ARABIC_OMAN
196*a8fa202aSchristos # define SUBLANG_ARABIC_OMAN 0x08
197*a8fa202aSchristos # endif
198*a8fa202aSchristos # ifndef SUBLANG_ARABIC_YEMEN
199*a8fa202aSchristos # define SUBLANG_ARABIC_YEMEN 0x09
200*a8fa202aSchristos # endif
201*a8fa202aSchristos # ifndef SUBLANG_ARABIC_SYRIA
202*a8fa202aSchristos # define SUBLANG_ARABIC_SYRIA 0x0a
203*a8fa202aSchristos # endif
204*a8fa202aSchristos # ifndef SUBLANG_ARABIC_JORDAN
205*a8fa202aSchristos # define SUBLANG_ARABIC_JORDAN 0x0b
206*a8fa202aSchristos # endif
207*a8fa202aSchristos # ifndef SUBLANG_ARABIC_LEBANON
208*a8fa202aSchristos # define SUBLANG_ARABIC_LEBANON 0x0c
209*a8fa202aSchristos # endif
210*a8fa202aSchristos # ifndef SUBLANG_ARABIC_KUWAIT
211*a8fa202aSchristos # define SUBLANG_ARABIC_KUWAIT 0x0d
212*a8fa202aSchristos # endif
213*a8fa202aSchristos # ifndef SUBLANG_ARABIC_UAE
214*a8fa202aSchristos # define SUBLANG_ARABIC_UAE 0x0e
215*a8fa202aSchristos # endif
216*a8fa202aSchristos # ifndef SUBLANG_ARABIC_BAHRAIN
217*a8fa202aSchristos # define SUBLANG_ARABIC_BAHRAIN 0x0f
218*a8fa202aSchristos # endif
219*a8fa202aSchristos # ifndef SUBLANG_ARABIC_QATAR
220*a8fa202aSchristos # define SUBLANG_ARABIC_QATAR 0x10
221*a8fa202aSchristos # endif
222*a8fa202aSchristos # ifndef SUBLANG_AZERI_LATIN
223*a8fa202aSchristos # define SUBLANG_AZERI_LATIN 0x01
224*a8fa202aSchristos # endif
225*a8fa202aSchristos # ifndef SUBLANG_AZERI_CYRILLIC
226*a8fa202aSchristos # define SUBLANG_AZERI_CYRILLIC 0x02
227*a8fa202aSchristos # endif
228*a8fa202aSchristos # ifndef SUBLANG_CHINESE_MACAU
229*a8fa202aSchristos # define SUBLANG_CHINESE_MACAU 0x05
230*a8fa202aSchristos # endif
231*a8fa202aSchristos # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
232*a8fa202aSchristos # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
233*a8fa202aSchristos # endif
234*a8fa202aSchristos # ifndef SUBLANG_ENGLISH_JAMAICA
235*a8fa202aSchristos # define SUBLANG_ENGLISH_JAMAICA 0x08
236*a8fa202aSchristos # endif
237*a8fa202aSchristos # ifndef SUBLANG_ENGLISH_CARIBBEAN
238*a8fa202aSchristos # define SUBLANG_ENGLISH_CARIBBEAN 0x09
239*a8fa202aSchristos # endif
240*a8fa202aSchristos # ifndef SUBLANG_ENGLISH_BELIZE
241*a8fa202aSchristos # define SUBLANG_ENGLISH_BELIZE 0x0a
242*a8fa202aSchristos # endif
243*a8fa202aSchristos # ifndef SUBLANG_ENGLISH_TRINIDAD
244*a8fa202aSchristos # define SUBLANG_ENGLISH_TRINIDAD 0x0b
245*a8fa202aSchristos # endif
246*a8fa202aSchristos # ifndef SUBLANG_ENGLISH_ZIMBABWE
247*a8fa202aSchristos # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
248*a8fa202aSchristos # endif
249*a8fa202aSchristos # ifndef SUBLANG_ENGLISH_PHILIPPINES
250*a8fa202aSchristos # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
251*a8fa202aSchristos # endif
252*a8fa202aSchristos # ifndef SUBLANG_FRENCH_LUXEMBOURG
253*a8fa202aSchristos # define SUBLANG_FRENCH_LUXEMBOURG 0x05
254*a8fa202aSchristos # endif
255*a8fa202aSchristos # ifndef SUBLANG_FRENCH_MONACO
256*a8fa202aSchristos # define SUBLANG_FRENCH_MONACO 0x06
257*a8fa202aSchristos # endif
258*a8fa202aSchristos # ifndef SUBLANG_GERMAN_LUXEMBOURG
259*a8fa202aSchristos # define SUBLANG_GERMAN_LUXEMBOURG 0x04
260*a8fa202aSchristos # endif
261*a8fa202aSchristos # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
262*a8fa202aSchristos # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
263*a8fa202aSchristos # endif
264*a8fa202aSchristos # ifndef SUBLANG_KASHMIRI_INDIA
265*a8fa202aSchristos # define SUBLANG_KASHMIRI_INDIA 0x02
266*a8fa202aSchristos # endif
267*a8fa202aSchristos # ifndef SUBLANG_MALAY_MALAYSIA
268*a8fa202aSchristos # define SUBLANG_MALAY_MALAYSIA 0x01
269*a8fa202aSchristos # endif
270*a8fa202aSchristos # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
271*a8fa202aSchristos # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
272*a8fa202aSchristos # endif
273*a8fa202aSchristos # ifndef SUBLANG_NEPALI_INDIA
274*a8fa202aSchristos # define SUBLANG_NEPALI_INDIA 0x02
275*a8fa202aSchristos # endif
276*a8fa202aSchristos # ifndef SUBLANG_SERBIAN_LATIN
277*a8fa202aSchristos # define SUBLANG_SERBIAN_LATIN 0x02
278*a8fa202aSchristos # endif
279*a8fa202aSchristos # ifndef SUBLANG_SERBIAN_CYRILLIC
280*a8fa202aSchristos # define SUBLANG_SERBIAN_CYRILLIC 0x03
281*a8fa202aSchristos # endif
282*a8fa202aSchristos # ifndef SUBLANG_SPANISH_GUATEMALA
283*a8fa202aSchristos # define SUBLANG_SPANISH_GUATEMALA 0x04
284*a8fa202aSchristos # endif
285*a8fa202aSchristos # ifndef SUBLANG_SPANISH_COSTA_RICA
286*a8fa202aSchristos # define SUBLANG_SPANISH_COSTA_RICA 0x05
287*a8fa202aSchristos # endif
288*a8fa202aSchristos # ifndef SUBLANG_SPANISH_PANAMA
289*a8fa202aSchristos # define SUBLANG_SPANISH_PANAMA 0x06
290*a8fa202aSchristos # endif
291*a8fa202aSchristos # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
292*a8fa202aSchristos # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
293*a8fa202aSchristos # endif
294*a8fa202aSchristos # ifndef SUBLANG_SPANISH_VENEZUELA
295*a8fa202aSchristos # define SUBLANG_SPANISH_VENEZUELA 0x08
296*a8fa202aSchristos # endif
297*a8fa202aSchristos # ifndef SUBLANG_SPANISH_COLOMBIA
298*a8fa202aSchristos # define SUBLANG_SPANISH_COLOMBIA 0x09
299*a8fa202aSchristos # endif
300*a8fa202aSchristos # ifndef SUBLANG_SPANISH_PERU
301*a8fa202aSchristos # define SUBLANG_SPANISH_PERU 0x0a
302*a8fa202aSchristos # endif
303*a8fa202aSchristos # ifndef SUBLANG_SPANISH_ARGENTINA
304*a8fa202aSchristos # define SUBLANG_SPANISH_ARGENTINA 0x0b
305*a8fa202aSchristos # endif
306*a8fa202aSchristos # ifndef SUBLANG_SPANISH_ECUADOR
307*a8fa202aSchristos # define SUBLANG_SPANISH_ECUADOR 0x0c
308*a8fa202aSchristos # endif
309*a8fa202aSchristos # ifndef SUBLANG_SPANISH_CHILE
310*a8fa202aSchristos # define SUBLANG_SPANISH_CHILE 0x0d
311*a8fa202aSchristos # endif
312*a8fa202aSchristos # ifndef SUBLANG_SPANISH_URUGUAY
313*a8fa202aSchristos # define SUBLANG_SPANISH_URUGUAY 0x0e
314*a8fa202aSchristos # endif
315*a8fa202aSchristos # ifndef SUBLANG_SPANISH_PARAGUAY
316*a8fa202aSchristos # define SUBLANG_SPANISH_PARAGUAY 0x0f
317*a8fa202aSchristos # endif
318*a8fa202aSchristos # ifndef SUBLANG_SPANISH_BOLIVIA
319*a8fa202aSchristos # define SUBLANG_SPANISH_BOLIVIA 0x10
320*a8fa202aSchristos # endif
321*a8fa202aSchristos # ifndef SUBLANG_SPANISH_EL_SALVADOR
322*a8fa202aSchristos # define SUBLANG_SPANISH_EL_SALVADOR 0x11
323*a8fa202aSchristos # endif
324*a8fa202aSchristos # ifndef SUBLANG_SPANISH_HONDURAS
325*a8fa202aSchristos # define SUBLANG_SPANISH_HONDURAS 0x12
326*a8fa202aSchristos # endif
327*a8fa202aSchristos # ifndef SUBLANG_SPANISH_NICARAGUA
328*a8fa202aSchristos # define SUBLANG_SPANISH_NICARAGUA 0x13
329*a8fa202aSchristos # endif
330*a8fa202aSchristos # ifndef SUBLANG_SPANISH_PUERTO_RICO
331*a8fa202aSchristos # define SUBLANG_SPANISH_PUERTO_RICO 0x14
332*a8fa202aSchristos # endif
333*a8fa202aSchristos # ifndef SUBLANG_SWEDISH_FINLAND
334*a8fa202aSchristos # define SUBLANG_SWEDISH_FINLAND 0x02
335*a8fa202aSchristos # endif
336*a8fa202aSchristos # ifndef SUBLANG_URDU_PAKISTAN
337*a8fa202aSchristos # define SUBLANG_URDU_PAKISTAN 0x01
338*a8fa202aSchristos # endif
339*a8fa202aSchristos # ifndef SUBLANG_URDU_INDIA
340*a8fa202aSchristos # define SUBLANG_URDU_INDIA 0x02
341*a8fa202aSchristos # endif
342*a8fa202aSchristos # ifndef SUBLANG_UZBEK_LATIN
343*a8fa202aSchristos # define SUBLANG_UZBEK_LATIN 0x01
344*a8fa202aSchristos # endif
345*a8fa202aSchristos # ifndef SUBLANG_UZBEK_CYRILLIC
346*a8fa202aSchristos # define SUBLANG_UZBEK_CYRILLIC 0x02
347*a8fa202aSchristos # endif
348*a8fa202aSchristos #endif
349*a8fa202aSchristos
350*a8fa202aSchristos /* XPG3 defines the result of 'setlocale (category, NULL)' as:
351*a8fa202aSchristos "Directs 'setlocale()' to query 'category' and return the current
352*a8fa202aSchristos setting of 'local'."
353*a8fa202aSchristos However it does not specify the exact format. Neither do SUSV2 and
354*a8fa202aSchristos ISO C 99. So we can use this feature only on selected systems (e.g.
355*a8fa202aSchristos those using GNU C Library). */
356*a8fa202aSchristos #if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
357*a8fa202aSchristos # define HAVE_LOCALE_NULL
358*a8fa202aSchristos #endif
359*a8fa202aSchristos
360*a8fa202aSchristos /* Determine the current locale's name, and canonicalize it into XPG syntax
361*a8fa202aSchristos language[_territory[.codeset]][@modifier]
362*a8fa202aSchristos The codeset part in the result is not reliable; the locale_charset()
363*a8fa202aSchristos should be used for codeset information instead.
364*a8fa202aSchristos The result must not be freed; it is statically allocated. */
365*a8fa202aSchristos
366*a8fa202aSchristos const char *
_nl_locale_name(category,categoryname)367*a8fa202aSchristos _nl_locale_name (category, categoryname)
368*a8fa202aSchristos int category;
369*a8fa202aSchristos const char *categoryname;
370*a8fa202aSchristos {
371*a8fa202aSchristos const char *retval;
372*a8fa202aSchristos
373*a8fa202aSchristos #ifndef WIN32
374*a8fa202aSchristos
375*a8fa202aSchristos /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
376*a8fa202aSchristos On some systems this can be done by the 'setlocale' function itself. */
377*a8fa202aSchristos # if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
378*a8fa202aSchristos retval = setlocale (category, NULL);
379*a8fa202aSchristos # else
380*a8fa202aSchristos /* Setting of LC_ALL overwrites all other. */
381*a8fa202aSchristos retval = getenv ("LC_ALL");
382*a8fa202aSchristos if (retval == NULL || retval[0] == '\0')
383*a8fa202aSchristos {
384*a8fa202aSchristos /* Next comes the name of the desired category. */
385*a8fa202aSchristos retval = getenv (categoryname);
386*a8fa202aSchristos if (retval == NULL || retval[0] == '\0')
387*a8fa202aSchristos {
388*a8fa202aSchristos /* Last possibility is the LANG environment variable. */
389*a8fa202aSchristos retval = getenv ("LANG");
390*a8fa202aSchristos if (retval == NULL || retval[0] == '\0')
391*a8fa202aSchristos /* We use C as the default domain. POSIX says this is
392*a8fa202aSchristos implementation defined. */
393*a8fa202aSchristos retval = "C";
394*a8fa202aSchristos }
395*a8fa202aSchristos }
396*a8fa202aSchristos # endif
397*a8fa202aSchristos
398*a8fa202aSchristos return retval;
399*a8fa202aSchristos
400*a8fa202aSchristos #else /* WIN32 */
401*a8fa202aSchristos
402*a8fa202aSchristos /* Return an XPG style locale name language[_territory][@modifier].
403*a8fa202aSchristos Don't even bother determining the codeset; it's not useful in this
404*a8fa202aSchristos context, because message catalogs are not specific to a single
405*a8fa202aSchristos codeset. */
406*a8fa202aSchristos
407*a8fa202aSchristos LCID lcid;
408*a8fa202aSchristos LANGID langid;
409*a8fa202aSchristos int primary, sub;
410*a8fa202aSchristos
411*a8fa202aSchristos /* Let the user override the system settings through environment
412*a8fa202aSchristos variables, as on POSIX systems. */
413*a8fa202aSchristos retval = getenv ("LC_ALL");
414*a8fa202aSchristos if (retval != NULL && retval[0] != '\0')
415*a8fa202aSchristos return retval;
416*a8fa202aSchristos retval = getenv (categoryname);
417*a8fa202aSchristos if (retval != NULL && retval[0] != '\0')
418*a8fa202aSchristos return retval;
419*a8fa202aSchristos retval = getenv ("LANG");
420*a8fa202aSchristos if (retval != NULL && retval[0] != '\0')
421*a8fa202aSchristos return retval;
422*a8fa202aSchristos
423*a8fa202aSchristos /* Use native Win32 API locale ID. */
424*a8fa202aSchristos lcid = GetThreadLocale ();
425*a8fa202aSchristos
426*a8fa202aSchristos /* Strip off the sorting rules, keep only the language part. */
427*a8fa202aSchristos langid = LANGIDFROMLCID (lcid);
428*a8fa202aSchristos
429*a8fa202aSchristos /* Split into language and territory part. */
430*a8fa202aSchristos primary = PRIMARYLANGID (langid);
431*a8fa202aSchristos sub = SUBLANGID (langid);
432*a8fa202aSchristos switch (primary)
433*a8fa202aSchristos {
434*a8fa202aSchristos case LANG_AFRIKAANS: return "af_ZA";
435*a8fa202aSchristos case LANG_ALBANIAN: return "sq_AL";
436*a8fa202aSchristos case LANG_ARABIC:
437*a8fa202aSchristos switch (sub)
438*a8fa202aSchristos {
439*a8fa202aSchristos case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
440*a8fa202aSchristos case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
441*a8fa202aSchristos case SUBLANG_ARABIC_EGYPT: return "ar_EG";
442*a8fa202aSchristos case SUBLANG_ARABIC_LIBYA: return "ar_LY";
443*a8fa202aSchristos case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
444*a8fa202aSchristos case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
445*a8fa202aSchristos case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
446*a8fa202aSchristos case SUBLANG_ARABIC_OMAN: return "ar_OM";
447*a8fa202aSchristos case SUBLANG_ARABIC_YEMEN: return "ar_YE";
448*a8fa202aSchristos case SUBLANG_ARABIC_SYRIA: return "ar_SY";
449*a8fa202aSchristos case SUBLANG_ARABIC_JORDAN: return "ar_JO";
450*a8fa202aSchristos case SUBLANG_ARABIC_LEBANON: return "ar_LB";
451*a8fa202aSchristos case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
452*a8fa202aSchristos case SUBLANG_ARABIC_UAE: return "ar_AE";
453*a8fa202aSchristos case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
454*a8fa202aSchristos case SUBLANG_ARABIC_QATAR: return "ar_QA";
455*a8fa202aSchristos }
456*a8fa202aSchristos return "ar";
457*a8fa202aSchristos case LANG_ARMENIAN: return "hy_AM";
458*a8fa202aSchristos case LANG_ASSAMESE: return "as_IN";
459*a8fa202aSchristos case LANG_AZERI:
460*a8fa202aSchristos switch (sub)
461*a8fa202aSchristos {
462*a8fa202aSchristos /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
463*a8fa202aSchristos case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
464*a8fa202aSchristos case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
465*a8fa202aSchristos }
466*a8fa202aSchristos return "az";
467*a8fa202aSchristos case LANG_BASQUE:
468*a8fa202aSchristos return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
469*a8fa202aSchristos case LANG_BELARUSIAN: return "be_BY";
470*a8fa202aSchristos case LANG_BENGALI: return "bn_IN";
471*a8fa202aSchristos case LANG_BULGARIAN: return "bg_BG";
472*a8fa202aSchristos case LANG_CATALAN: return "ca_ES";
473*a8fa202aSchristos case LANG_CHINESE:
474*a8fa202aSchristos switch (sub)
475*a8fa202aSchristos {
476*a8fa202aSchristos case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
477*a8fa202aSchristos case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
478*a8fa202aSchristos case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
479*a8fa202aSchristos case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
480*a8fa202aSchristos case SUBLANG_CHINESE_MACAU: return "zh_MO";
481*a8fa202aSchristos }
482*a8fa202aSchristos return "zh";
483*a8fa202aSchristos case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN
484*a8fa202aSchristos * What used to be called Serbo-Croatian
485*a8fa202aSchristos * should really now be two separate
486*a8fa202aSchristos * languages because of political reasons.
487*a8fa202aSchristos * (Says tml, who knows nothing about Serbian
488*a8fa202aSchristos * or Croatian.)
489*a8fa202aSchristos * (I can feel those flames coming already.)
490*a8fa202aSchristos */
491*a8fa202aSchristos switch (sub)
492*a8fa202aSchristos {
493*a8fa202aSchristos /* FIXME: How to distinguish Croatian and Latin Serbian locales? */
494*a8fa202aSchristos case SUBLANG_SERBIAN_LATIN: return "sr_YU";
495*a8fa202aSchristos case SUBLANG_SERBIAN_CYRILLIC: return "sr_YU@cyrillic";
496*a8fa202aSchristos default: return "hr_HR";
497*a8fa202aSchristos }
498*a8fa202aSchristos case LANG_CZECH: return "cs_CZ";
499*a8fa202aSchristos case LANG_DANISH: return "da_DK";
500*a8fa202aSchristos case LANG_DUTCH:
501*a8fa202aSchristos switch (sub)
502*a8fa202aSchristos {
503*a8fa202aSchristos case SUBLANG_DUTCH: return "nl_NL";
504*a8fa202aSchristos case SUBLANG_DUTCH_BELGIAN: return "nl_BE";
505*a8fa202aSchristos }
506*a8fa202aSchristos return "nl";
507*a8fa202aSchristos case LANG_ENGLISH:
508*a8fa202aSchristos switch (sub)
509*a8fa202aSchristos {
510*a8fa202aSchristos /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
511*a8fa202aSchristos * English was the language spoken in England.
512*a8fa202aSchristos * Oh well.
513*a8fa202aSchristos */
514*a8fa202aSchristos case SUBLANG_ENGLISH_US: return "en_US";
515*a8fa202aSchristos case SUBLANG_ENGLISH_UK: return "en_GB";
516*a8fa202aSchristos case SUBLANG_ENGLISH_AUS: return "en_AU";
517*a8fa202aSchristos case SUBLANG_ENGLISH_CAN: return "en_CA";
518*a8fa202aSchristos case SUBLANG_ENGLISH_NZ: return "en_NZ";
519*a8fa202aSchristos case SUBLANG_ENGLISH_EIRE: return "en_IE";
520*a8fa202aSchristos case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
521*a8fa202aSchristos case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
522*a8fa202aSchristos case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
523*a8fa202aSchristos case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
524*a8fa202aSchristos case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
525*a8fa202aSchristos case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
526*a8fa202aSchristos case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
527*a8fa202aSchristos }
528*a8fa202aSchristos return "en";
529*a8fa202aSchristos case LANG_ESTONIAN: return "et_EE";
530*a8fa202aSchristos case LANG_FAEROESE: return "fo_FO";
531*a8fa202aSchristos case LANG_FARSI: return "fa_IR";
532*a8fa202aSchristos case LANG_FINNISH: return "fi_FI";
533*a8fa202aSchristos case LANG_FRENCH:
534*a8fa202aSchristos switch (sub)
535*a8fa202aSchristos {
536*a8fa202aSchristos case SUBLANG_FRENCH: return "fr_FR";
537*a8fa202aSchristos case SUBLANG_FRENCH_BELGIAN: return "fr_BE";
538*a8fa202aSchristos case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
539*a8fa202aSchristos case SUBLANG_FRENCH_SWISS: return "fr_CH";
540*a8fa202aSchristos case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
541*a8fa202aSchristos case SUBLANG_FRENCH_MONACO: return "fr_MC";
542*a8fa202aSchristos }
543*a8fa202aSchristos return "fr";
544*a8fa202aSchristos case LANG_GEORGIAN: return "ka_GE";
545*a8fa202aSchristos case LANG_GERMAN:
546*a8fa202aSchristos switch (sub)
547*a8fa202aSchristos {
548*a8fa202aSchristos case SUBLANG_GERMAN: return "de_DE";
549*a8fa202aSchristos case SUBLANG_GERMAN_SWISS: return "de_CH";
550*a8fa202aSchristos case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
551*a8fa202aSchristos case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
552*a8fa202aSchristos case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
553*a8fa202aSchristos }
554*a8fa202aSchristos return "de";
555*a8fa202aSchristos case LANG_GREEK: return "el_GR";
556*a8fa202aSchristos case LANG_GUJARATI: return "gu_IN";
557*a8fa202aSchristos case LANG_HEBREW: return "he_IL";
558*a8fa202aSchristos case LANG_HINDI: return "hi_IN";
559*a8fa202aSchristos case LANG_HUNGARIAN: return "hu_HU";
560*a8fa202aSchristos case LANG_ICELANDIC: return "is_IS";
561*a8fa202aSchristos case LANG_INDONESIAN: return "id_ID";
562*a8fa202aSchristos case LANG_ITALIAN:
563*a8fa202aSchristos switch (sub)
564*a8fa202aSchristos {
565*a8fa202aSchristos case SUBLANG_ITALIAN: return "it_IT";
566*a8fa202aSchristos case SUBLANG_ITALIAN_SWISS: return "it_CH";
567*a8fa202aSchristos }
568*a8fa202aSchristos return "it";
569*a8fa202aSchristos case LANG_JAPANESE: return "ja_JP";
570*a8fa202aSchristos case LANG_KANNADA: return "kn_IN";
571*a8fa202aSchristos case LANG_KASHMIRI:
572*a8fa202aSchristos switch (sub)
573*a8fa202aSchristos {
574*a8fa202aSchristos case SUBLANG_DEFAULT: return "ks_PK";
575*a8fa202aSchristos case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
576*a8fa202aSchristos }
577*a8fa202aSchristos return "ks";
578*a8fa202aSchristos case LANG_KAZAK: return "kk_KZ";
579*a8fa202aSchristos case LANG_KONKANI:
580*a8fa202aSchristos /* FIXME: Adjust this when such locales appear on Unix. */
581*a8fa202aSchristos return "kok_IN";
582*a8fa202aSchristos case LANG_KOREAN: return "ko_KR";
583*a8fa202aSchristos case LANG_LATVIAN: return "lv_LV";
584*a8fa202aSchristos case LANG_LITHUANIAN: return "lt_LT";
585*a8fa202aSchristos case LANG_MACEDONIAN: return "mk_MK";
586*a8fa202aSchristos case LANG_MALAY:
587*a8fa202aSchristos switch (sub)
588*a8fa202aSchristos {
589*a8fa202aSchristos case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
590*a8fa202aSchristos case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
591*a8fa202aSchristos }
592*a8fa202aSchristos return "ms";
593*a8fa202aSchristos case LANG_MALAYALAM: return "ml_IN";
594*a8fa202aSchristos case LANG_MANIPURI:
595*a8fa202aSchristos /* FIXME: Adjust this when such locales appear on Unix. */
596*a8fa202aSchristos return "mni_IN";
597*a8fa202aSchristos case LANG_MARATHI: return "mr_IN";
598*a8fa202aSchristos case LANG_NEPALI:
599*a8fa202aSchristos switch (sub)
600*a8fa202aSchristos {
601*a8fa202aSchristos case SUBLANG_DEFAULT: return "ne_NP";
602*a8fa202aSchristos case SUBLANG_NEPALI_INDIA: return "ne_IN";
603*a8fa202aSchristos }
604*a8fa202aSchristos return "ne";
605*a8fa202aSchristos case LANG_NORWEGIAN:
606*a8fa202aSchristos switch (sub)
607*a8fa202aSchristos {
608*a8fa202aSchristos case SUBLANG_NORWEGIAN_BOKMAL: return "no_NO";
609*a8fa202aSchristos case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
610*a8fa202aSchristos }
611*a8fa202aSchristos return "no";
612*a8fa202aSchristos case LANG_ORIYA: return "or_IN";
613*a8fa202aSchristos case LANG_POLISH: return "pl_PL";
614*a8fa202aSchristos case LANG_PORTUGUESE:
615*a8fa202aSchristos switch (sub)
616*a8fa202aSchristos {
617*a8fa202aSchristos case SUBLANG_PORTUGUESE: return "pt_PT";
618*a8fa202aSchristos /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
619*a8fa202aSchristos Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
620*a8fa202aSchristos case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
621*a8fa202aSchristos }
622*a8fa202aSchristos return "pt";
623*a8fa202aSchristos case LANG_PUNJABI: return "pa_IN";
624*a8fa202aSchristos case LANG_ROMANIAN: return "ro_RO";
625*a8fa202aSchristos case LANG_RUSSIAN:
626*a8fa202aSchristos return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA". */
627*a8fa202aSchristos case LANG_SANSKRIT: return "sa_IN";
628*a8fa202aSchristos case LANG_SINDHI: return "sd";
629*a8fa202aSchristos case LANG_SLOVAK: return "sk_SK";
630*a8fa202aSchristos case LANG_SLOVENIAN: return "sl_SI";
631*a8fa202aSchristos case LANG_SORBIAN:
632*a8fa202aSchristos /* FIXME: Adjust this when such locales appear on Unix. */
633*a8fa202aSchristos return "wen_DE";
634*a8fa202aSchristos case LANG_SPANISH:
635*a8fa202aSchristos switch (sub)
636*a8fa202aSchristos {
637*a8fa202aSchristos case SUBLANG_SPANISH: return "es_ES";
638*a8fa202aSchristos case SUBLANG_SPANISH_MEXICAN: return "es_MX";
639*a8fa202aSchristos case SUBLANG_SPANISH_MODERN:
640*a8fa202aSchristos return "es_ES@modern"; /* not seen on Unix */
641*a8fa202aSchristos case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
642*a8fa202aSchristos case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
643*a8fa202aSchristos case SUBLANG_SPANISH_PANAMA: return "es_PA";
644*a8fa202aSchristos case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
645*a8fa202aSchristos case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
646*a8fa202aSchristos case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
647*a8fa202aSchristos case SUBLANG_SPANISH_PERU: return "es_PE";
648*a8fa202aSchristos case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
649*a8fa202aSchristos case SUBLANG_SPANISH_ECUADOR: return "es_EC";
650*a8fa202aSchristos case SUBLANG_SPANISH_CHILE: return "es_CL";
651*a8fa202aSchristos case SUBLANG_SPANISH_URUGUAY: return "es_UY";
652*a8fa202aSchristos case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
653*a8fa202aSchristos case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
654*a8fa202aSchristos case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
655*a8fa202aSchristos case SUBLANG_SPANISH_HONDURAS: return "es_HN";
656*a8fa202aSchristos case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
657*a8fa202aSchristos case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
658*a8fa202aSchristos }
659*a8fa202aSchristos return "es";
660*a8fa202aSchristos case LANG_SWAHILI: return "sw";
661*a8fa202aSchristos case LANG_SWEDISH:
662*a8fa202aSchristos switch (sub)
663*a8fa202aSchristos {
664*a8fa202aSchristos case SUBLANG_DEFAULT: return "sv_SE";
665*a8fa202aSchristos case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
666*a8fa202aSchristos }
667*a8fa202aSchristos return "sv";
668*a8fa202aSchristos case LANG_TAMIL:
669*a8fa202aSchristos return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
670*a8fa202aSchristos case LANG_TATAR: return "tt";
671*a8fa202aSchristos case LANG_TELUGU: return "te_IN";
672*a8fa202aSchristos case LANG_THAI: return "th_TH";
673*a8fa202aSchristos case LANG_TURKISH: return "tr_TR";
674*a8fa202aSchristos case LANG_UKRAINIAN: return "uk_UA";
675*a8fa202aSchristos case LANG_URDU:
676*a8fa202aSchristos switch (sub)
677*a8fa202aSchristos {
678*a8fa202aSchristos case SUBLANG_URDU_PAKISTAN: return "ur_PK";
679*a8fa202aSchristos case SUBLANG_URDU_INDIA: return "ur_IN";
680*a8fa202aSchristos }
681*a8fa202aSchristos return "ur";
682*a8fa202aSchristos case LANG_UZBEK:
683*a8fa202aSchristos switch (sub)
684*a8fa202aSchristos {
685*a8fa202aSchristos /* FIXME: Adjust this when Uzbek locales appear on Unix. */
686*a8fa202aSchristos case SUBLANG_UZBEK_LATIN: return "uz_UZ@latin";
687*a8fa202aSchristos case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
688*a8fa202aSchristos }
689*a8fa202aSchristos return "uz";
690*a8fa202aSchristos case LANG_VIETNAMESE: return "vi_VN";
691*a8fa202aSchristos default: return "C";
692*a8fa202aSchristos }
693*a8fa202aSchristos
694*a8fa202aSchristos #endif
695*a8fa202aSchristos }
696