Lolly 1.4.28
Loading...
Searching...
No Matches
locale.cpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : locale.cpp
4 * DESCRIPTION: Locale related routines
5 * COPYRIGHT : (C) 1999-2019 Joris van der Hoeven, Darcy Shen
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#include "locale.hpp"
13
14#if !defined(OS_MINGW) && !defined(OS_WIN)
15#include <langinfo.h>
16#ifndef X11TEXMACS
17#include <locale>
18#endif
19#endif
20
21#if defined(OS_WIN)
22#define NOGDI
23#include <windows.h>
24#include <winnls.h>
25#elif defined(OS_MINGW)
26#include <winnls.h>
27#endif
28
29#define outline Core_outline
30#define extend Core_extends
31#ifdef OS_MACOS
32#include <CoreFoundation/CFLocale.h>
33#include <CoreFoundation/CFString.h>
34#endif
35#undef extend
36#undef outline
37
38#include "analyze.hpp"
39#include "sys_utils.hpp"
40
41/******************************************************************************
42 * Locales
43 ******************************************************************************/
44
45#if defined(OS_MINGW) || defined(OS_WIN)
46const string
48 static string language;
49
50 if (N (language) == 0) {
52 switch (PRIMARYLANGID (lid)) {
53 case LANG_BULGARIAN:
54 language= "bulgarian";
55 break;
56 case LANG_CHINESE:
57 language= "chinese";
58 break;
60 language= "taiwanese";
61 break;
62 case LANG_CROATIAN:
63 language= "croatian";
64 break;
65 case LANG_CZECH:
66 language= "czech";
67 break;
68 case LANG_DANISH:
69 language= "danish";
70 break;
71 case LANG_DUTCH:
72 language= "dutch";
73 break;
74 case LANG_ENGLISH:
75 switch (SUBLANGID (lid)) {
77 language= "british";
78 break;
79 default:
80 language= "english";
81 break;
82 }
83 break;
84 case LANG_FRENCH:
85 language= "french";
86 break;
87 case LANG_GERMAN:
88 language= "german";
89 break;
90 case LANG_GREEK:
91 language= "greek";
92 break;
93 case LANG_HUNGARIAN:
94 language= "hungarian";
95 break;
96 case LANG_ITALIAN:
97 language= "italian";
98 break;
99 case LANG_JAPANESE:
100 language= "japanese";
101 break;
102 case LANG_KOREAN:
103 language= "korean";
104 break;
105 case LANG_POLISH:
106 language= "polish";
107 break;
108 case LANG_PORTUGUESE:
109 language= "portuguese";
110 break;
111 case LANG_ROMANIAN:
112 language= "romanian";
113 break;
114 case LANG_RUSSIAN:
115 language= "russian";
116 break;
117 case LANG_SLOVAK:
118 language= "slovak";
119 break;
120 case LANG_SLOVENIAN:
121 language= "slovene";
122 break;
123 case LANG_SPANISH:
124 language= "spanish";
125 break;
126 case LANG_SWEDISH:
127 language= "swedish";
128 break;
129 case LANG_UKRAINIAN:
130 language= "ukrainian";
131 break;
132 default:
133 language= "english";
134 break;
135 }
136 }
137 return language;
138}
139#endif
140
141#ifdef OS_MACOS
142string
144 char mac_lang[50];
150 return string (mac_lang);
151}
152#endif
153
154string
156 if (N (s) > 5) s= s (0, 5);
157 if (s == "en_GB") return "british";
158 if (s == "zh_TW") return "taiwanese";
159 if (N (s) > 2) s= s (0, 2);
160 if (s == "bg") return "bulgarian";
161 if (s == "zh") return "chinese";
162 if (s == "hr") return "croatian";
163 if (s == "cs") return "czech";
164 if (s == "da") return "danish";
165 if (s == "nl") return "dutch";
166 if (s == "en") return "english";
167 if (s == "eo") return "esperanto";
168 if (s == "fi") return "finnish";
169 if (s == "fr") return "french";
170 if (s == "de") return "german";
171 if (s == "gr") return "greek";
172 if (s == "hu") return "hungarian";
173 if (s == "it") return "italian";
174 if (s == "ja") return "japanese";
175 if (s == "ko") return "korean";
176 if (s == "pl") return "polish";
177 if (s == "pt") return "portuguese";
178 if (s == "ro") return "romanian";
179 if (s == "ru") return "russian";
180 if (s == "sk") return "slovak";
181 if (s == "sl") return "slovene";
182 if (s == "es") return "spanish";
183 if (s == "sv") return "swedish";
184 if (s == "uk") return "ukrainian";
185 return "english";
186}
187
188string
190 if (s == "american") return "en_US";
191 if (s == "british") return "en_GB";
192 if (s == "bulgarian") return "bg_BG";
193 if (s == "chinese") return "zh_CN";
194 if (s == "croatian") return "hr_HR";
195 if (s == "czech") return "cs_CZ";
196 if (s == "danish") return "da_DK";
197 if (s == "dutch") return "nl_NL";
198 if (s == "english") return "en_US";
199 if (s == "esperanto") return "eo_EO";
200 if (s == "finnish") return "fi_FI";
201 if (s == "french") return "fr_FR";
202 if (s == "german") return "de_DE";
203 if (s == "greek") return "gr_GR";
204 if (s == "hungarian") return "hu_HU";
205 if (s == "italian") return "it_IT";
206 if (s == "japanese") return "ja_JP";
207 if (s == "korean") return "ko_KR";
208 if (s == "polish") return "pl_PL";
209 if (s == "portuguese") return "pt_PT";
210 if (s == "romanian") return "ro_RO";
211 if (s == "russian") return "ru_RU";
212 if (s == "slovak") return "sk_SK";
213 if (s == "slovene") return "sl_SI";
214 if (s == "spanish") return "es_ES";
215 if (s == "swedish") return "sv_SV";
216 if (s == "taiwanese") return "zh_TW";
217 if (s == "ukrainian") return "uk_UA";
218 return "en_US";
219}
220
221string
223 if (s == "bulgarian") return "ISO-8859-5";
224 if (s == "chinese") return "";
225 if (s == "croatian") return "ISO-8859-2";
226 if (s == "czech") return "ISO-8859-2";
227 if (s == "greek") return "ISO-8859-7";
228 if (s == "hungarian") return "ISO-8859-2";
229 if (s == "japanese") return "";
230 if (s == "korean") return "";
231 if (s == "polish") return "ISO-8859-2";
232 if (s == "romanian") return "ISO-8859-2";
233 if (s == "russian") return "ISO-8859-5";
234 if (s == "slovak") return "ISO-8859-2";
235 if (s == "slovene") return "ISO-8859-2";
236 if (s == "taiwanese") return "";
237 if (s == "ukrainian") return "ISO-8859-5";
238 return "ISO-8859-1";
239}
240
241string
243#if defined(OS_MINGW) || defined(OS_WIN)
245#endif
246
247#ifdef OS_MACOS
249#endif
250
251#ifdef OS_WASM
252 return "english";
253#endif
254
255#ifdef OS_LINUX
256 string env_lan= get_env ("LC_ALL");
257 if (env_lan != "") return locale_to_language (env_lan);
258 env_lan= get_env ("LC_MESSAGES");
259 if (env_lan != "") return locale_to_language (env_lan);
260 env_lan= get_env ("LANG");
261 if (env_lan != "") return locale_to_language (env_lan);
262 env_lan= get_env ("GDM_LANG");
263 if (env_lan != "") return locale_to_language (env_lan);
264#endif
265 return "english";
266}
267
268string
270 return "UTF-8";
271}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
The list class represents a linked list.
Definition list.hpp:48
string locale_to_language(string s)
Definition locale.cpp:155
string language_to_local_ISO_charset(string s)
Definition locale.cpp:222
string language_to_locale(string s)
Definition locale.cpp:189
string get_locale_charset()
Definition locale.cpp:269
string get_locale_language()
Definition locale.cpp:242
string get_env(string var)
Definition sys_utils.cpp:25