]> git.saurik.com Git - wxWidgets.git/blame - src/common/intl.cpp
Make WXK_NUMPAD_TAB member of WXK_CATEGORY_TAB.
[wxWidgets.git] / src / common / intl.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
dccce9ea 2// Name: src/common/intl.cpp
77ffb593 3// Purpose: Internationalization and localisation for wxWidgets
c801d85f 4// Author: Vadim Zeitlin
849a28d0
VS
5// Modified by: Michael N. Filippov <michael@idisys.iae.nsk.su>
6// (2003/09/30 - PluralForms support)
c801d85f
KB
7// Created: 29/01/98
8// RCS-ID: $Id$
9// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
13// ============================================================================
1678ad78 14// declaration
c801d85f
KB
15// ============================================================================
16
17// ----------------------------------------------------------------------------
18// headers
19// ----------------------------------------------------------------------------
20
c801d85f
KB
21// For compilers that support precompilation, includes "wx.h".
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
84c18814 25 #pragma hdrstop
c801d85f
KB
26#endif
27
6908078e
VZ
28#ifdef __EMX__
29// The following define is needed by Innotek's libc to
30// make the definition of struct localeconv available.
31#define __INTERNAL_DEFS
32#endif
33
d427503c
VZ
34#if wxUSE_INTL
35
ad9835c9
WS
36#ifndef WX_PRECOMP
37 #include "wx/dynarray.h"
38 #include "wx/string.h"
39 #include "wx/intl.h"
40 #include "wx/log.h"
ad9835c9 41 #include "wx/utils.h"
670f9935 42 #include "wx/app.h"
df69528b 43 #include "wx/hashmap.h"
02761f6c 44 #include "wx/module.h"
ad9835c9 45#endif // WX_PRECOMP
1c193821
JS
46
47#ifndef __WXWINCE__
ad9835c9 48 #include <locale.h>
1c193821
JS
49#endif
50
ad9835c9 51// standard headers
dccce9ea
VZ
52#include <ctype.h>
53#include <stdlib.h>
2ec6905c 54#ifdef HAVE_LANGINFO_H
670f9935 55 #include <langinfo.h>
2ec6905c 56#endif
7502ba29 57
1c193821
JS
58#ifdef __WIN32__
59 #include "wx/msw/private.h"
60#elif defined(__UNIX_LIKE__)
61 #include "wx/fontmap.h" // for CharsetToEncoding()
62#endif
63
c801d85f 64#include "wx/file.h"
58ad1bab 65#include "wx/filename.h"
dccce9ea 66#include "wx/tokenzr.h"
030c0bea
VS
67#include "wx/fontmap.h"
68#include "wx/encconv.h"
664e1314 69#include "wx/scopedptr.h"
4d931bcc 70#include "wx/apptrait.h"
f830b2b1 71#include "wx/stdpaths.h"
a64be16e 72#include "wx/hashset.h"
c0030ca7 73#include "wx/filesys.h"
dccce9ea 74
89a7e1ff 75#if defined(__WXOSX__)
c933e267 76 #include "wx/osx/core/cfref.h"
529e125d 77 #include <CoreFoundation/CFLocale.h>
e9e53eb1 78 #include <CoreFoundation/CFDateFormatter.h>
c933e267 79 #include "wx/osx/core/cfstring.h"
5a9cd2d1 80#endif
dff6cf57 81
84c18814
VZ
82// ----------------------------------------------------------------------------
83// simple types
84// ----------------------------------------------------------------------------
85
e939abfd 86// this should *not* be wxChar, this type must have exactly 8 bits!
563d535e
VS
87typedef wxUint8 size_t8;
88typedef wxUint32 size_t32;
84c18814 89
c801d85f
KB
90// ----------------------------------------------------------------------------
91// constants
92// ----------------------------------------------------------------------------
93
94// magic number identifying the .mo format file
c86f1403
VZ
95const size_t32 MSGCATALOG_MAGIC = 0x950412de;
96const size_t32 MSGCATALOG_MAGIC_SW = 0xde120495;
c801d85f 97
f6ba36e4 98// the constants describing the format of ll_CC locale string
ec37df57
VZ
99static const size_t LEN_LANG = 2;
100static const size_t LEN_SUBLANG = 2;
101static const size_t LEN_FULL = LEN_LANG + 1 + LEN_SUBLANG; // 1 for '_'
102
a0516656 103#define TRACE_I18N wxS("i18n")
ca6a9a14 104
c801d85f 105// ----------------------------------------------------------------------------
1678ad78 106// global functions
c801d85f
KB
107// ----------------------------------------------------------------------------
108
84c18814 109static wxLocale *wxSetLocale(wxLocale *pLocale);
c801d85f 110
f6ba36e4
VZ
111namespace
112{
ec37df57
VZ
113
114// get just the language part
f6ba36e4 115inline wxString ExtractLang(const wxString& langFull)
ec37df57
VZ
116{
117 return langFull.Left(LEN_LANG);
118}
119
f6ba36e4
VZ
120// helper functions of GetSystemLanguage()
121#ifdef __UNIX__
122
ec37df57 123// get everything else (including the leading '_')
f6ba36e4 124inline wxString ExtractNotLang(const wxString& langFull)
ec37df57
VZ
125{
126 return langFull.Mid(LEN_LANG);
127}
128
129#endif // __UNIX__
130
f6ba36e4 131} // anonymous namespace
563d535e 132
849a28d0
VS
133// ----------------------------------------------------------------------------
134// Plural forms parser
135// ----------------------------------------------------------------------------
136
b7b97e77 137/*
849a28d0
VS
138 Simplified Grammar
139
140Expression:
141 LogicalOrExpression '?' Expression ':' Expression
142 LogicalOrExpression
143
144LogicalOrExpression:
145 LogicalAndExpression "||" LogicalOrExpression // to (a || b) || c
146 LogicalAndExpression
147
148LogicalAndExpression:
149 EqualityExpression "&&" LogicalAndExpression // to (a && b) && c
150 EqualityExpression
151
152EqualityExpression:
153 RelationalExpression "==" RelationalExperession
154 RelationalExpression "!=" RelationalExperession
155 RelationalExpression
156
157RelationalExpression:
158 MultiplicativeExpression '>' MultiplicativeExpression
159 MultiplicativeExpression '<' MultiplicativeExpression
160 MultiplicativeExpression ">=" MultiplicativeExpression
161 MultiplicativeExpression "<=" MultiplicativeExpression
162 MultiplicativeExpression
b7b97e77 163
849a28d0
VS
164MultiplicativeExpression:
165 PmExpression '%' PmExpression
166 PmExpression
167
168PmExpression:
169 N
170 Number
171 '(' Expression ')'
172*/
173
174class wxPluralFormsToken
175{
176public:
177 enum Type
178 {
179 T_ERROR, T_EOF, T_NUMBER, T_N, T_PLURAL, T_NPLURALS, T_EQUAL, T_ASSIGN,
180 T_GREATER, T_GREATER_OR_EQUAL, T_LESS, T_LESS_OR_EQUAL,
181 T_REMINDER, T_NOT_EQUAL,
182 T_LOGICAL_AND, T_LOGICAL_OR, T_QUESTION, T_COLON, T_SEMICOLON,
183 T_LEFT_BRACKET, T_RIGHT_BRACKET
184 };
185 Type type() const { return m_type; }
186 void setType(Type type) { m_type = type; }
187 // for T_NUMBER only
188 typedef int Number;
189 Number number() const { return m_number; }
190 void setNumber(Number num) { m_number = num; }
191private:
192 Type m_type;
193 Number m_number;
194};
195
196
197class wxPluralFormsScanner
198{
199public:
200 wxPluralFormsScanner(const char* s);
201 const wxPluralFormsToken& token() const { return m_token; }
202 bool nextToken(); // returns false if error
203private:
204 const char* m_s;
205 wxPluralFormsToken m_token;
206};
207
208wxPluralFormsScanner::wxPluralFormsScanner(const char* s) : m_s(s)
209{
210 nextToken();
211}
212
213bool wxPluralFormsScanner::nextToken()
214{
215 wxPluralFormsToken::Type type = wxPluralFormsToken::T_ERROR;
2eb37f73 216 while (isspace((unsigned char) *m_s))
849a28d0
VS
217 {
218 ++m_s;
219 }
220 if (*m_s == 0)
221 {
222 type = wxPluralFormsToken::T_EOF;
223 }
2eb37f73 224 else if (isdigit((unsigned char) *m_s))
849a28d0
VS
225 {
226 wxPluralFormsToken::Number number = *m_s++ - '0';
2eb37f73 227 while (isdigit((unsigned char) *m_s))
849a28d0
VS
228 {
229 number = number * 10 + (*m_s++ - '0');
230 }
231 m_token.setNumber(number);
232 type = wxPluralFormsToken::T_NUMBER;
233 }
2eb37f73 234 else if (isalpha((unsigned char) *m_s))
849a28d0
VS
235 {
236 const char* begin = m_s++;
2eb37f73 237 while (isalnum((unsigned char) *m_s))
849a28d0
VS
238 {
239 ++m_s;
240 }
241 size_t size = m_s - begin;
242 if (size == 1 && memcmp(begin, "n", size) == 0)
243 {
244 type = wxPluralFormsToken::T_N;
245 }
246 else if (size == 6 && memcmp(begin, "plural", size) == 0)
247 {
248 type = wxPluralFormsToken::T_PLURAL;
249 }
250 else if (size == 8 && memcmp(begin, "nplurals", size) == 0)
251 {
252 type = wxPluralFormsToken::T_NPLURALS;
253 }
254 }
255 else if (*m_s == '=')
256 {
257 ++m_s;
258 if (*m_s == '=')
259 {
260 ++m_s;
261 type = wxPluralFormsToken::T_EQUAL;
262 }
263 else
264 {
265 type = wxPluralFormsToken::T_ASSIGN;
266 }
267 }
268 else if (*m_s == '>')
269 {
270 ++m_s;
271 if (*m_s == '=')
272 {
273 ++m_s;
274 type = wxPluralFormsToken::T_GREATER_OR_EQUAL;
275 }
276 else
277 {
278 type = wxPluralFormsToken::T_GREATER;
279 }
280 }
281 else if (*m_s == '<')
282 {
283 ++m_s;
284 if (*m_s == '=')
285 {
286 ++m_s;
287 type = wxPluralFormsToken::T_LESS_OR_EQUAL;
288 }
289 else
290 {
291 type = wxPluralFormsToken::T_LESS;
292 }
293 }
294 else if (*m_s == '%')
295 {
296 ++m_s;
297 type = wxPluralFormsToken::T_REMINDER;
298 }
299 else if (*m_s == '!' && m_s[1] == '=')
300 {
301 m_s += 2;
302 type = wxPluralFormsToken::T_NOT_EQUAL;
303 }
304 else if (*m_s == '&' && m_s[1] == '&')
305 {
306 m_s += 2;
307 type = wxPluralFormsToken::T_LOGICAL_AND;
308 }
309 else if (*m_s == '|' && m_s[1] == '|')
310 {
311 m_s += 2;
312 type = wxPluralFormsToken::T_LOGICAL_OR;
313 }
314 else if (*m_s == '?')
315 {
316 ++m_s;
317 type = wxPluralFormsToken::T_QUESTION;
318 }
319 else if (*m_s == ':')
320 {
321 ++m_s;
322 type = wxPluralFormsToken::T_COLON;
323 } else if (*m_s == ';') {
324 ++m_s;
325 type = wxPluralFormsToken::T_SEMICOLON;
326 }
327 else if (*m_s == '(')
328 {
329 ++m_s;
330 type = wxPluralFormsToken::T_LEFT_BRACKET;
331 }
332 else if (*m_s == ')')
333 {
334 ++m_s;
335 type = wxPluralFormsToken::T_RIGHT_BRACKET;
336 }
337 m_token.setType(type);
338 return type != wxPluralFormsToken::T_ERROR;
339}
340
341class wxPluralFormsNode;
342
343// NB: Can't use wxDEFINE_SCOPED_PTR_TYPE because wxPluralFormsNode is not
344// fully defined yet:
345class wxPluralFormsNodePtr
346{
347public:
348 wxPluralFormsNodePtr(wxPluralFormsNode *p = NULL) : m_p(p) {}
349 ~wxPluralFormsNodePtr();
350 wxPluralFormsNode& operator*() const { return *m_p; }
351 wxPluralFormsNode* operator->() const { return m_p; }
352 wxPluralFormsNode* get() const { return m_p; }
353 wxPluralFormsNode* release();
354 void reset(wxPluralFormsNode *p);
355
356private:
357 wxPluralFormsNode *m_p;
358};
359
360class wxPluralFormsNode
361{
362public:
363 wxPluralFormsNode(const wxPluralFormsToken& token) : m_token(token) {}
364 const wxPluralFormsToken& token() const { return m_token; }
365 const wxPluralFormsNode* node(size_t i) const
366 { return m_nodes[i].get(); }
367 void setNode(size_t i, wxPluralFormsNode* n);
368 wxPluralFormsNode* releaseNode(size_t i);
369 wxPluralFormsToken::Number evaluate(wxPluralFormsToken::Number n) const;
370
371private:
372 wxPluralFormsToken m_token;
373 wxPluralFormsNodePtr m_nodes[3];
374};
b7b97e77 375
849a28d0
VS
376wxPluralFormsNodePtr::~wxPluralFormsNodePtr()
377{
378 delete m_p;
379}
380wxPluralFormsNode* wxPluralFormsNodePtr::release()
381{
382 wxPluralFormsNode *p = m_p;
383 m_p = NULL;
384 return p;
385}
386void wxPluralFormsNodePtr::reset(wxPluralFormsNode *p)
387{
388 if (p != m_p)
389 {
390 delete m_p;
391 m_p = p;
392 }
393}
394
395
396void wxPluralFormsNode::setNode(size_t i, wxPluralFormsNode* n)
397{
398 m_nodes[i].reset(n);
399}
400
401wxPluralFormsNode* wxPluralFormsNode::releaseNode(size_t i)
402{
403 return m_nodes[i].release();
404}
405
406wxPluralFormsToken::Number
407wxPluralFormsNode::evaluate(wxPluralFormsToken::Number n) const
408{
409 switch (token().type())
410 {
411 // leaf
412 case wxPluralFormsToken::T_NUMBER:
413 return token().number();
414 case wxPluralFormsToken::T_N:
415 return n;
416 // 2 args
417 case wxPluralFormsToken::T_EQUAL:
418 return node(0)->evaluate(n) == node(1)->evaluate(n);
419 case wxPluralFormsToken::T_NOT_EQUAL:
420 return node(0)->evaluate(n) != node(1)->evaluate(n);
421 case wxPluralFormsToken::T_GREATER:
422 return node(0)->evaluate(n) > node(1)->evaluate(n);
423 case wxPluralFormsToken::T_GREATER_OR_EQUAL:
424 return node(0)->evaluate(n) >= node(1)->evaluate(n);
425 case wxPluralFormsToken::T_LESS:
426 return node(0)->evaluate(n) < node(1)->evaluate(n);
427 case wxPluralFormsToken::T_LESS_OR_EQUAL:
428 return node(0)->evaluate(n) <= node(1)->evaluate(n);
429 case wxPluralFormsToken::T_REMINDER:
430 {
431 wxPluralFormsToken::Number number = node(1)->evaluate(n);
432 if (number != 0)
433 {
434 return node(0)->evaluate(n) % number;
435 }
436 else
437 {
438 return 0;
439 }
440 }
441 case wxPluralFormsToken::T_LOGICAL_AND:
442 return node(0)->evaluate(n) && node(1)->evaluate(n);
443 case wxPluralFormsToken::T_LOGICAL_OR:
444 return node(0)->evaluate(n) || node(1)->evaluate(n);
445 // 3 args
446 case wxPluralFormsToken::T_QUESTION:
447 return node(0)->evaluate(n)
448 ? node(1)->evaluate(n)
449 : node(2)->evaluate(n);
450 default:
451 return 0;
452 }
453}
454
455
456class wxPluralFormsCalculator
457{
458public:
459 wxPluralFormsCalculator() : m_nplurals(0), m_plural(0) {}
b7b97e77 460
849a28d0
VS
461 // input: number, returns msgstr index
462 int evaluate(int n) const;
463
464 // input: text after "Plural-Forms:" (e.g. "nplurals=2; plural=(n != 1);"),
465 // if s == 0, creates default handler
466 // returns 0 if error
467 static wxPluralFormsCalculator* make(const char* s = 0);
468
469 ~wxPluralFormsCalculator() {}
470
471 void init(wxPluralFormsToken::Number nplurals, wxPluralFormsNode* plural);
b7b97e77 472
849a28d0
VS
473private:
474 wxPluralFormsToken::Number m_nplurals;
475 wxPluralFormsNodePtr m_plural;
476};
477
4115960d 478wxDEFINE_SCOPED_PTR_TYPE(wxPluralFormsCalculator)
849a28d0
VS
479
480void wxPluralFormsCalculator::init(wxPluralFormsToken::Number nplurals,
ca642c8a 481 wxPluralFormsNode* plural)
849a28d0
VS
482{
483 m_nplurals = nplurals;
484 m_plural.reset(plural);
485}
486
487int wxPluralFormsCalculator::evaluate(int n) const
488{
489 if (m_plural.get() == 0)
490 {
491 return 0;
492 }
493 wxPluralFormsToken::Number number = m_plural->evaluate(n);
494 if (number < 0 || number > m_nplurals)
495 {
496 return 0;
497 }
498 return number;
499}
500
501
502class wxPluralFormsParser
503{
504public:
505 wxPluralFormsParser(wxPluralFormsScanner& scanner) : m_scanner(scanner) {}
506 bool parse(wxPluralFormsCalculator& rCalculator);
507
508private:
509 wxPluralFormsNode* parsePlural();
510 // stops at T_SEMICOLON, returns 0 if error
511 wxPluralFormsScanner& m_scanner;
512 const wxPluralFormsToken& token() const;
513 bool nextToken();
b7b97e77 514
849a28d0
VS
515 wxPluralFormsNode* expression();
516 wxPluralFormsNode* logicalOrExpression();
517 wxPluralFormsNode* logicalAndExpression();
518 wxPluralFormsNode* equalityExpression();
519 wxPluralFormsNode* multiplicativeExpression();
520 wxPluralFormsNode* relationalExpression();
521 wxPluralFormsNode* pmExpression();
522};
523
524bool wxPluralFormsParser::parse(wxPluralFormsCalculator& rCalculator)
525{
526 if (token().type() != wxPluralFormsToken::T_NPLURALS)
527 return false;
528 if (!nextToken())
529 return false;
530 if (token().type() != wxPluralFormsToken::T_ASSIGN)
531 return false;
532 if (!nextToken())
533 return false;
534 if (token().type() != wxPluralFormsToken::T_NUMBER)
535 return false;
536 wxPluralFormsToken::Number nplurals = token().number();
537 if (!nextToken())
538 return false;
539 if (token().type() != wxPluralFormsToken::T_SEMICOLON)
540 return false;
541 if (!nextToken())
542 return false;
543 if (token().type() != wxPluralFormsToken::T_PLURAL)
544 return false;
545 if (!nextToken())
546 return false;
547 if (token().type() != wxPluralFormsToken::T_ASSIGN)
548 return false;
549 if (!nextToken())
550 return false;
551 wxPluralFormsNode* plural = parsePlural();
552 if (plural == 0)
553 return false;
554 if (token().type() != wxPluralFormsToken::T_SEMICOLON)
555 return false;
556 if (!nextToken())
557 return false;
558 if (token().type() != wxPluralFormsToken::T_EOF)
559 return false;
560 rCalculator.init(nplurals, plural);
561 return true;
562}
563
564wxPluralFormsNode* wxPluralFormsParser::parsePlural()
565{
566 wxPluralFormsNode* p = expression();
567 if (p == NULL)
568 {
569 return NULL;
570 }
571 wxPluralFormsNodePtr n(p);
572 if (token().type() != wxPluralFormsToken::T_SEMICOLON)
573 {
574 return NULL;
575 }
576 return n.release();
577}
578
579const wxPluralFormsToken& wxPluralFormsParser::token() const
580{
581 return m_scanner.token();
582}
583
584bool wxPluralFormsParser::nextToken()
585{
586 if (!m_scanner.nextToken())
587 return false;
588 return true;
589}
590
591wxPluralFormsNode* wxPluralFormsParser::expression()
592{
593 wxPluralFormsNode* p = logicalOrExpression();
594 if (p == NULL)
595 return NULL;
596 wxPluralFormsNodePtr n(p);
597 if (token().type() == wxPluralFormsToken::T_QUESTION)
598 {
599 wxPluralFormsNodePtr qn(new wxPluralFormsNode(token()));
600 if (!nextToken())
601 {
602 return 0;
603 }
604 p = expression();
605 if (p == 0)
606 {
607 return 0;
608 }
609 qn->setNode(1, p);
610 if (token().type() != wxPluralFormsToken::T_COLON)
611 {
612 return 0;
613 }
614 if (!nextToken())
615 {
616 return 0;
617 }
618 p = expression();
619 if (p == 0)
620 {
621 return 0;
622 }
623 qn->setNode(2, p);
624 qn->setNode(0, n.release());
625 return qn.release();
626 }
627 return n.release();
628}
629
630wxPluralFormsNode*wxPluralFormsParser::logicalOrExpression()
631{
632 wxPluralFormsNode* p = logicalAndExpression();
633 if (p == NULL)
634 return NULL;
635 wxPluralFormsNodePtr ln(p);
636 if (token().type() == wxPluralFormsToken::T_LOGICAL_OR)
637 {
638 wxPluralFormsNodePtr un(new wxPluralFormsNode(token()));
639 if (!nextToken())
640 {
641 return 0;
642 }
643 p = logicalOrExpression();
644 if (p == 0)
645 {
646 return 0;
647 }
648 wxPluralFormsNodePtr rn(p); // right
649 if (rn->token().type() == wxPluralFormsToken::T_LOGICAL_OR)
650 {
651 // see logicalAndExpression comment
652 un->setNode(0, ln.release());
653 un->setNode(1, rn->releaseNode(0));
654 rn->setNode(0, un.release());
655 return rn.release();
656 }
a509f830
VZ
657
658
659 un->setNode(0, ln.release());
660 un->setNode(1, rn.release());
661 return un.release();
849a28d0
VS
662 }
663 return ln.release();
664}
665
666wxPluralFormsNode* wxPluralFormsParser::logicalAndExpression()
667{
668 wxPluralFormsNode* p = equalityExpression();
669 if (p == NULL)
670 return NULL;
671 wxPluralFormsNodePtr ln(p); // left
672 if (token().type() == wxPluralFormsToken::T_LOGICAL_AND)
673 {
674 wxPluralFormsNodePtr un(new wxPluralFormsNode(token())); // up
675 if (!nextToken())
676 {
677 return NULL;
678 }
679 p = logicalAndExpression();
680 if (p == 0)
681 {
682 return NULL;
683 }
684 wxPluralFormsNodePtr rn(p); // right
685 if (rn->token().type() == wxPluralFormsToken::T_LOGICAL_AND)
686 {
687// transform 1 && (2 && 3) -> (1 && 2) && 3
688// u r
689// l r -> u 3
690// 2 3 l 2
691 un->setNode(0, ln.release());
692 un->setNode(1, rn->releaseNode(0));
693 rn->setNode(0, un.release());
694 return rn.release();
695 }
a509f830
VZ
696
697 un->setNode(0, ln.release());
698 un->setNode(1, rn.release());
699 return un.release();
849a28d0
VS
700 }
701 return ln.release();
702}
703
704wxPluralFormsNode* wxPluralFormsParser::equalityExpression()
705{
706 wxPluralFormsNode* p = relationalExpression();
707 if (p == NULL)
708 return NULL;
709 wxPluralFormsNodePtr n(p);
710 if (token().type() == wxPluralFormsToken::T_EQUAL
711 || token().type() == wxPluralFormsToken::T_NOT_EQUAL)
712 {
713 wxPluralFormsNodePtr qn(new wxPluralFormsNode(token()));
714 if (!nextToken())
715 {
716 return NULL;
717 }
718 p = relationalExpression();
719 if (p == NULL)
720 {
721 return NULL;
722 }
723 qn->setNode(1, p);
724 qn->setNode(0, n.release());
725 return qn.release();
726 }
727 return n.release();
728}
729
730wxPluralFormsNode* wxPluralFormsParser::relationalExpression()
731{
732 wxPluralFormsNode* p = multiplicativeExpression();
733 if (p == NULL)
734 return NULL;
735 wxPluralFormsNodePtr n(p);
736 if (token().type() == wxPluralFormsToken::T_GREATER
737 || token().type() == wxPluralFormsToken::T_LESS
738 || token().type() == wxPluralFormsToken::T_GREATER_OR_EQUAL
739 || token().type() == wxPluralFormsToken::T_LESS_OR_EQUAL)
740 {
741 wxPluralFormsNodePtr qn(new wxPluralFormsNode(token()));
742 if (!nextToken())
743 {
744 return NULL;
745 }
746 p = multiplicativeExpression();
747 if (p == NULL)
748 {
749 return NULL;
750 }
751 qn->setNode(1, p);
752 qn->setNode(0, n.release());
753 return qn.release();
754 }
755 return n.release();
756}
757
758wxPluralFormsNode* wxPluralFormsParser::multiplicativeExpression()
759{
760 wxPluralFormsNode* p = pmExpression();
761 if (p == NULL)
762 return NULL;
763 wxPluralFormsNodePtr n(p);
764 if (token().type() == wxPluralFormsToken::T_REMINDER)
765 {
766 wxPluralFormsNodePtr qn(new wxPluralFormsNode(token()));
767 if (!nextToken())
768 {
769 return NULL;
770 }
771 p = pmExpression();
772 if (p == NULL)
773 {
774 return NULL;
775 }
776 qn->setNode(1, p);
777 qn->setNode(0, n.release());
778 return qn.release();
779 }
780 return n.release();
781}
782
783wxPluralFormsNode* wxPluralFormsParser::pmExpression()
784{
785 wxPluralFormsNodePtr n;
786 if (token().type() == wxPluralFormsToken::T_N
787 || token().type() == wxPluralFormsToken::T_NUMBER)
788 {
789 n.reset(new wxPluralFormsNode(token()));
790 if (!nextToken())
791 {
792 return NULL;
793 }
794 }
795 else if (token().type() == wxPluralFormsToken::T_LEFT_BRACKET) {
796 if (!nextToken())
797 {
798 return NULL;
799 }
800 wxPluralFormsNode* p = expression();
801 if (p == NULL)
802 {
803 return NULL;
804 }
805 n.reset(p);
806 if (token().type() != wxPluralFormsToken::T_RIGHT_BRACKET)
807 {
808 return NULL;
809 }
810 if (!nextToken())
811 {
812 return NULL;
813 }
814 }
815 else
816 {
817 return NULL;
818 }
819 return n.release();
820}
821
822wxPluralFormsCalculator* wxPluralFormsCalculator::make(const char* s)
823{
824 wxPluralFormsCalculatorPtr calculator(new wxPluralFormsCalculator);
825 if (s != NULL)
826 {
827 wxPluralFormsScanner scanner(s);
828 wxPluralFormsParser p(scanner);
829 if (!p.parse(*calculator))
830 {
831 return NULL;
832 }
833 }
834 return calculator.release();
835}
836
837
838
41524ffc 839
563d535e
VS
840// ----------------------------------------------------------------------------
841// wxMsgCatalogFile corresponds to one disk-file message catalog.
842//
843// This is a "low-level" class and is used only by wxMsgCatalog
f00204d3 844// NOTE: for the documentation of the binary catalog (.MO) files refer to
89a7e1ff 845// the GNU gettext manual:
f00204d3 846// http://www.gnu.org/software/autoconf/manual/gettext/MO-Files.html
563d535e
VS
847// ----------------------------------------------------------------------------
848
3f5c62f9 849WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxString, wxMessagesHash);
563d535e
VS
850
851class wxMsgCatalogFile
852{
853public:
854 // ctor & dtor
855 wxMsgCatalogFile();
ca642c8a 856 ~wxMsgCatalogFile();
563d535e
VS
857
858 // load the catalog from disk (szDirPrefix corresponds to language)
52de37c7 859 bool Load(const wxString& szDirPrefix, const wxString& szName,
f00204d3 860 wxPluralFormsCalculatorPtr& rPluralFormsCalculator);
563d535e
VS
861
862 // fills the hash with string-translation pairs
f00204d3
FM
863 bool FillHash(wxMessagesHash& hash,
864 const wxString& msgIdCharset,
865 bool convertEncoding) const;
563d535e 866
77c514d1
VZ
867 // return the charset of the strings in this catalog or empty string if
868 // none/unknown
869 wxString GetCharset() const { return m_charset; }
870
563d535e
VS
871private:
872 // this implementation is binary compatible with GNU gettext() version 0.10
873
874 // an entry in the string table
875 struct wxMsgTableEntry
876 {
ca642c8a
FM
877 size_t32 nLen; // length of the string
878 size_t32 ofsString; // pointer to the string
563d535e
VS
879 };
880
881 // header of a .mo file
882 struct wxMsgCatalogHeader
883 {
ca642c8a
FM
884 size_t32 magic, // offset +00: magic id
885 revision, // +04: revision
886 numStrings; // +08: number of strings in the file
887 size_t32 ofsOrigTable, // +0C: start of original string table
888 ofsTransTable; // +10: start of translated string table
889 size_t32 nHashSize, // +14: hash table size
890 ofsHashTable; // +18: offset of hash table start
563d535e
VS
891 };
892
c0030ca7
VZ
893 // all data is stored here
894 wxMemoryBuffer m_data;
869c7549 895
563d535e
VS
896 // data description
897 size_t32 m_numStrings; // number of strings in this domain
898 wxMsgTableEntry *m_pOrigTable, // pointer to original strings
899 *m_pTransTable; // translated
900
77c514d1
VZ
901 wxString m_charset; // from the message catalog header
902
b7b97e77 903
869c7549
VZ
904 // swap the 2 halves of 32 bit integer if needed
905 size_t32 Swap(size_t32 ui) const
906 {
ca642c8a
FM
907 return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
908 ((ui >> 8) & 0xff00) | (ui >> 24)
869c7549
VZ
909 : ui;
910 }
9e7ed2b0 911
c0030ca7
VZ
912 // just return the pointer to the start of the data as "char *" to
913 // facilitate doing pointer arithmetic with it
914 char *StringData() const
915 {
5c33522f 916 return static_cast<char *>(m_data.GetData());
c0030ca7
VZ
917 }
918
869c7549
VZ
919 const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 n) const
920 {
921 const wxMsgTableEntry * const ent = pTable + n;
563d535e 922
869c7549
VZ
923 // this check could fail for a corrupt message catalog
924 size_t32 ofsString = Swap(ent->ofsString);
c0030ca7 925 if ( ofsString + Swap(ent->nLen) > m_data.GetDataLen())
849a28d0 926 {
869c7549 927 return NULL;
849a28d0 928 }
563d535e 929
c0030ca7 930 return StringData() + ofsString;
b7b97e77 931 }
869c7549
VZ
932
933 bool m_bSwapped; // wrong endianness?
22f3361e 934
c0c133e1 935 wxDECLARE_NO_COPY_CLASS(wxMsgCatalogFile);
563d535e
VS
936};
937
938
c801d85f 939// ----------------------------------------------------------------------------
563d535e 940// wxMsgCatalog corresponds to one loaded message catalog.
c801d85f
KB
941//
942// This is a "low-level" class and is used only by wxLocale (that's why
943// it's designed to be stored in a linked list)
944// ----------------------------------------------------------------------------
945
946class wxMsgCatalog
947{
948public:
6fbc2636 949#if !wxUSE_UNICODE
77c514d1
VZ
950 wxMsgCatalog() { m_conv = NULL; }
951 ~wxMsgCatalog();
6fbc2636 952#endif
77c514d1 953
563d535e 954 // load the catalog from disk (szDirPrefix corresponds to language)
31b7522e 955 bool Load(const wxString& dirPrefix, const wxString& name,
ca642c8a 956 const wxString& msgIdCharset, bool bConvertEncoding = false);
c801d85f 957
563d535e
VS
958 // get name of the catalog
959 wxString GetName() const { return m_name; }
c801d85f 960
563d535e 961 // get the translated string: returns NULL if not found
31b7522e 962 const wxString *GetString(const wxString& sz, size_t n = size_t(-1)) const;
c801d85f 963
563d535e
VS
964 // public variable pointing to the next element in a linked list (or NULL)
965 wxMsgCatalog *m_pNext;
7af89395 966
c801d85f 967private:
563d535e
VS
968 wxMessagesHash m_messages; // all messages in the catalog
969 wxString m_name; // name of the domain
77c514d1 970
6fbc2636 971#if !wxUSE_UNICODE
77c514d1
VZ
972 // the conversion corresponding to this catalog charset if we installed it
973 // as the global one
974 wxCSConv *m_conv;
6fbc2636 975#endif
77c514d1 976
849a28d0 977 wxPluralFormsCalculatorPtr m_pluralFormsCalculator;
c801d85f
KB
978};
979
fd323a5e
VZ
980// ----------------------------------------------------------------------------
981// global variables
982// ----------------------------------------------------------------------------
983
984// the list of the directories to search for message catalog files
f830b2b1 985static wxArrayString gs_searchPrefixes;
fd323a5e 986
c801d85f
KB
987// ============================================================================
988// implementation
989// ============================================================================
990
ea65760d
VZ
991// ----------------------------------------------------------------------------
992// wxLanguageInfo
993// ----------------------------------------------------------------------------
994
071ccf2a
PC
995#ifdef __WXMSW__
996
42db82fd
VZ
997// helper used by wxLanguageInfo::GetLocaleName() and elsewhere to determine
998// whether the locale is Unicode-only (it is if this function returns empty
999// string)
1000static wxString wxGetANSICodePageForLocale(LCID lcid)
1001{
1002 wxString cp;
1003
1004 wxChar buffer[16];
1005 if ( ::GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE,
ca642c8a 1006 buffer, WXSIZEOF(buffer)) > 0 )
42db82fd 1007 {
9a83f860 1008 if ( buffer[0] != wxT('0') || buffer[1] != wxT('\0') )
42db82fd
VZ
1009 cp = buffer;
1010 //else: this locale doesn't use ANSI code page
1011 }
1012
1013 return cp;
1014}
1015
ea65760d
VZ
1016wxUint32 wxLanguageInfo::GetLCID() const
1017{
1018 return MAKELCID(MAKELANGID(WinLang, WinSublang), SORT_DEFAULT);
1019}
1020
86d62b51
VZ
1021wxString wxLanguageInfo::GetLocaleName() const
1022{
1023 wxString locale;
1024
1025 const LCID lcid = GetLCID();
1026
1027 wxChar buffer[256];
9a83f860 1028 buffer[0] = wxT('\0');
86d62b51
VZ
1029 if ( !::GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buffer, WXSIZEOF(buffer)) )
1030 {
9a83f860 1031 wxLogLastError(wxT("GetLocaleInfo(LOCALE_SENGLANGUAGE)"));
86d62b51
VZ
1032 return locale;
1033 }
1034
1035 locale << buffer;
1036 if ( ::GetLocaleInfo(lcid, LOCALE_SENGCOUNTRY,
ca642c8a 1037 buffer, WXSIZEOF(buffer)) > 0 )
86d62b51 1038 {
9a83f860 1039 locale << wxT('_') << buffer;
86d62b51
VZ
1040 }
1041
42db82fd
VZ
1042 const wxString cp = wxGetANSICodePageForLocale(lcid);
1043 if ( !cp.empty() )
86d62b51 1044 {
9a83f860 1045 locale << wxT('.') << cp;
86d62b51
VZ
1046 }
1047
1048 return locale;
1049}
1050
ea65760d
VZ
1051#endif // __WXMSW__
1052
c801d85f 1053// ----------------------------------------------------------------------------
563d535e 1054// wxMsgCatalogFile class
c801d85f
KB
1055// ----------------------------------------------------------------------------
1056
563d535e 1057wxMsgCatalogFile::wxMsgCatalogFile()
7af89395 1058{
c801d85f
KB
1059}
1060
563d535e 1061wxMsgCatalogFile::~wxMsgCatalogFile()
7af89395 1062{
c801d85f
KB
1063}
1064
b5297239
VS
1065// return the directories to search for message catalogs under the given
1066// prefix, separated by wxPATH_SEP
f830b2b1 1067static
52de37c7 1068wxString GetMsgCatalogSubdirs(const wxString& prefix, const wxString& lang)
fd323a5e 1069{
a19e936e
VZ
1070 // Search first in Unix-standard prefix/lang/LC_MESSAGES, then in
1071 // prefix/lang and finally in just prefix.
1072 //
1073 // Note that we use LC_MESSAGES on all platforms and not just Unix, because
1074 // it doesn't cost much to look into one more directory and doing it this
1075 // way has two important benefits:
43e995b6
VS
1076 // a) we don't break compatibility with wx-2.6 and older by stopping to
1077 // look in a directory where the catalogs used to be and thus silently
1078 // breaking apps after they are recompiled against the latest wx
1079 // b) it makes it possible to package app's support files in the same
1080 // way on all target platforms
9b3b7f55 1081 const wxString pathPrefix = wxFileName(prefix, lang).GetFullPath();
a19e936e
VZ
1082
1083 wxString searchPath;
1084 searchPath.reserve(4*pathPrefix.length());
1085 searchPath << pathPrefix << wxFILE_SEP_PATH << "LC_MESSAGES" << wxPATH_SEP
ca642c8a
FM
1086 << prefix << wxFILE_SEP_PATH << wxPATH_SEP
1087 << pathPrefix;
fd323a5e
VZ
1088
1089 return searchPath;
1090}
1091
1092// construct the search path for the given language
52de37c7 1093static wxString GetFullSearchPath(const wxString& lang)
fd323a5e 1094{
fd323a5e 1095 // first take the entries explicitly added by the program
f830b2b1
VZ
1096 wxArrayString paths;
1097 paths.reserve(gs_searchPrefixes.size() + 1);
1098 size_t n,
ca642c8a 1099 count = gs_searchPrefixes.size();
f830b2b1 1100 for ( n = 0; n < count; n++ )
fd323a5e 1101 {
b5297239 1102 paths.Add(GetMsgCatalogSubdirs(gs_searchPrefixes[n], lang));
fd323a5e
VZ
1103 }
1104
30984dea 1105
f830b2b1
VZ
1106#if wxUSE_STDPATHS
1107 // then look in the standard location
1108 const wxString stdp = wxStandardPaths::Get().
1109 GetLocalizedResourcesDir(lang, wxStandardPaths::ResourceCat_Messages);
1110
1111 if ( paths.Index(stdp) == wxNOT_FOUND )
1112 paths.Add(stdp);
1113#endif // wxUSE_STDPATHS
1114
1115 // last look in default locations
1116#ifdef __UNIX__
5f170f33
VZ
1117 // LC_PATH is a standard env var containing the search path for the .mo
1118 // files
a0516656 1119 const char *pszLcPath = wxGetenv("LC_PATH");
f830b2b1
VZ
1120 if ( pszLcPath )
1121 {
b5297239 1122 const wxString lcp = GetMsgCatalogSubdirs(pszLcPath, lang);
f830b2b1
VZ
1123 if ( paths.Index(lcp) == wxNOT_FOUND )
1124 paths.Add(lcp);
1125 }
5f170f33 1126
f830b2b1
VZ
1127 // also add the one from where wxWin was installed:
1128 wxString wxp = wxGetInstallPrefix();
1129 if ( !wxp.empty() )
1130 {
a0516656 1131 wxp = GetMsgCatalogSubdirs(wxp + wxS("/share/locale"), lang);
f830b2b1
VZ
1132 if ( paths.Index(wxp) == wxNOT_FOUND )
1133 paths.Add(wxp);
1134 }
c3ccca4a
VS
1135#endif // __UNIX__
1136
f830b2b1
VZ
1137
1138 // finally construct the full search path
1139 wxString searchPath;
1140 searchPath.reserve(500);
1141 count = paths.size();
1142 for ( n = 0; n < count; n++ )
1143 {
1144 searchPath += paths[n];
1145 if ( n != count - 1 )
1146 searchPath += wxPATH_SEP;
1147 }
45e97ca0 1148
fd323a5e
VZ
1149 return searchPath;
1150}
1151
c801d85f 1152// open disk file and read in it's contents
52de37c7 1153bool wxMsgCatalogFile::Load(const wxString& szDirPrefix, const wxString& szName,
849a28d0 1154 wxPluralFormsCalculatorPtr& rPluralFormsCalculator)
c801d85f 1155{
6f011443
VZ
1156 wxCHECK_MSG( szDirPrefix.length() >= LEN_LANG, false,
1157 "invalid language specification" );
1158
ca642c8a 1159 wxString searchPath;
ca6a9a14
VZ
1160
1161#if wxUSE_FONTMAP
ca642c8a
FM
1162 // first look for the catalog for this language and the current locale:
1163 // notice that we don't use the system name for the locale as this would
1164 // force us to install catalogs in different locations depending on the
1165 // system but always use the canonical name
1166 wxFontEncoding encSys = wxLocale::GetSystemEncoding();
1167 if ( encSys != wxFONTENCODING_SYSTEM )
1168 {
1169 wxString fullname(szDirPrefix);
1170 fullname << wxS('.') << wxFontMapperBase::GetEncodingName(encSys);
1171 searchPath << GetFullSearchPath(fullname) << wxPATH_SEP;
1172 }
ca6a9a14
VZ
1173#endif // wxUSE_FONTMAP
1174
2ce0a6e2 1175
ca642c8a 1176 searchPath += GetFullSearchPath(szDirPrefix);
4cb21a7b 1177 if ( szDirPrefix.length() > LEN_LANG && szDirPrefix[LEN_LANG] == wxS('_') )
ca642c8a
FM
1178 {
1179 // also add just base locale name: for things like "fr_BE" (Belgium
1180 // French) we should use fall back on plain "fr" if no Belgium-specific
1181 // message catalogs exist
1182 searchPath << wxPATH_SEP
1183 << GetFullSearchPath(ExtractLang(szDirPrefix));
1184 }
7af89395 1185
4b6a582b
VZ
1186 wxLogTrace(TRACE_I18N, wxS("Looking for \"%s.mo\" in search path \"%s\""),
1187 szName, searchPath);
c801d85f 1188
ca642c8a
FM
1189 wxFileName fn(szName);
1190 fn.SetExt(wxS("mo"));
c0030ca7 1191
ca642c8a 1192 wxString strFullName;
c0030ca7 1193#if wxUSE_FILESYSTEM
ca642c8a
FM
1194 wxFileSystem fileSys;
1195 if ( !fileSys.FindFileInPath(&strFullName, searchPath, fn.GetFullPath()) )
c0030ca7 1196#else // !wxUSE_FILESYSTEM
ca642c8a 1197 if ( !wxFindFileInPath(&strFullName, searchPath, fn.GetFullPath()) )
c0030ca7 1198#endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM
ca642c8a
FM
1199 {
1200 wxLogVerbose(_("catalog file for domain '%s' not found."), szName);
1201 wxLogTrace(TRACE_I18N, wxS("Catalog \"%s.mo\" not found"), szName);
1202 return false;
1203 }
c801d85f 1204
ca642c8a
FM
1205 // open file and read its data
1206 wxLogVerbose(_("using catalog '%s' from '%s'."), szName, strFullName.c_str());
1207 wxLogTrace(TRACE_I18N, wxS("Using catalog \"%s\"."), strFullName.c_str());
7af89395 1208
c0030ca7 1209#if wxUSE_FILESYSTEM
ca642c8a
FM
1210 wxFSFile * const fileMsg = fileSys.OpenFile(strFullName);
1211 if ( !fileMsg )
1212 return false;
c0030ca7 1213
ca642c8a
FM
1214 wxInputStream *fileStream = fileMsg->GetStream();
1215 m_data.SetDataLen(0);
c0030ca7 1216
ca642c8a
FM
1217 static const size_t chunkSize = 4096;
1218 while ( !fileStream->Eof() ) {
1219 fileStream->Read(m_data.GetAppendBuf(chunkSize), chunkSize);
1220 m_data.UngetAppendBuf(fileStream->LastRead());
1221 }
c0030ca7 1222
ca642c8a 1223 delete fileMsg;
c0030ca7 1224#else // !wxUSE_FILESYSTEM
ca642c8a
FM
1225 wxFile fileMsg(strFullName);
1226 if ( !fileMsg.IsOpened() )
1227 return false;
c801d85f 1228
ca642c8a
FM
1229 // get the file size (assume it is less than 4Gb...)
1230 wxFileOffset lenFile = fileMsg.Length();
1231 if ( lenFile == wxInvalidOffset )
1232 return false;
c801d85f 1233
ca642c8a
FM
1234 size_t nSize = wx_truncate_cast(size_t, lenFile);
1235 wxASSERT_MSG( nSize == lenFile + size_t(0), wxS("message catalog bigger than 4GB?") );
17a1ebd1 1236
ca642c8a
FM
1237 // read the whole file in memory
1238 if ( fileMsg.Read(m_data.GetWriteBuf(nSize), nSize) != lenFile )
1239 return false;
778ce432 1240
ca642c8a 1241 m_data.UngetWriteBuf(nSize);
c0030ca7
VZ
1242#endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM
1243
7af89395 1244
ca642c8a
FM
1245 // examine header
1246 bool bValid = m_data.GetDataLen() > sizeof(wxMsgCatalogHeader);
1247
1248 const wxMsgCatalogHeader *pHeader = (wxMsgCatalogHeader *)m_data.GetData();
1249 if ( bValid ) {
1250 // we'll have to swap all the integers if it's true
1251 m_bSwapped = pHeader->magic == MSGCATALOG_MAGIC_SW;
7af89395 1252
ca642c8a
FM
1253 // check the magic number
1254 bValid = m_bSwapped || pHeader->magic == MSGCATALOG_MAGIC;
1255 }
c801d85f 1256
ca642c8a
FM
1257 if ( !bValid ) {
1258 // it's either too short or has incorrect magic number
1259 wxLogWarning(_("'%s' is not a valid message catalog."), strFullName.c_str());
7af89395 1260
ca642c8a
FM
1261 return false;
1262 }
7af89395 1263
ca642c8a
FM
1264 // initialize
1265 m_numStrings = Swap(pHeader->numStrings);
1266 m_pOrigTable = (wxMsgTableEntry *)(StringData() +
1267 Swap(pHeader->ofsOrigTable));
1268 m_pTransTable = (wxMsgTableEntry *)(StringData() +
1269 Swap(pHeader->ofsTransTable));
1270
1271 // now parse catalog's header and try to extract catalog charset and
1272 // plural forms formula from it:
1273
1274 const char* headerData = StringAtOfs(m_pOrigTable, 0);
23fb33aa 1275 if ( headerData && headerData[0] == '\0' )
ca642c8a
FM
1276 {
1277 // Extract the charset:
23fb33aa
VZ
1278 const char * const header = StringAtOfs(m_pTransTable, 0);
1279 const char *
1280 cset = strstr(header, "Content-Type: text/plain; charset=");
1281 if ( cset )
ca642c8a 1282 {
23fb33aa
VZ
1283 cset += 34; // strlen("Content-Type: text/plain; charset=")
1284
1285 const char * const csetEnd = strchr(cset, '\n');
1286 if ( csetEnd )
ca642c8a 1287 {
23fb33aa
VZ
1288 m_charset = wxString(cset, csetEnd - cset);
1289 if ( m_charset == wxS("CHARSET") )
ca642c8a
FM
1290 {
1291 // "CHARSET" is not valid charset, but lazy translator
23fb33aa 1292 m_charset.empty();
ca642c8a
FM
1293 }
1294 }
1295 }
1296 // else: incorrectly filled Content-Type header
1297
1298 // Extract plural forms:
23fb33aa
VZ
1299 const char * plurals = strstr(header, "Plural-Forms:");
1300 if ( plurals )
ca642c8a 1301 {
23fb33aa
VZ
1302 plurals += 13; // strlen("Plural-Forms:")
1303 const char * const pluralsEnd = strchr(plurals, '\n');
1304 if ( pluralsEnd )
ca642c8a 1305 {
23fb33aa
VZ
1306 const size_t pluralsLen = pluralsEnd - plurals;
1307 wxCharBuffer buf(pluralsLen);
1308 strncpy(buf.data(), plurals, pluralsLen);
1309 wxPluralFormsCalculator * const
1310 pCalculator = wxPluralFormsCalculator::make(buf);
1311 if ( pCalculator )
ca642c8a
FM
1312 {
1313 rPluralFormsCalculator.reset(pCalculator);
1314 }
1315 else
1316 {
23fb33aa
VZ
1317 wxLogVerbose(_("Failed to parse Plural-Forms: '%s'"),
1318 buf.data());
ca642c8a
FM
1319 }
1320 }
1321 }
23fb33aa
VZ
1322
1323 if ( !rPluralFormsCalculator.get() )
ca642c8a 1324 rPluralFormsCalculator.reset(wxPluralFormsCalculator::make());
ca642c8a
FM
1325 }
1326
1327 // everything is fine
1328 return true;
c801d85f
KB
1329}
1330
f00204d3 1331bool wxMsgCatalogFile::FillHash(wxMessagesHash& hash,
d721baa9
VS
1332 const wxString& msgIdCharset,
1333 bool convertEncoding) const
c801d85f 1334{
7a4b1e66
VZ
1335#if wxUSE_UNICODE
1336 // this parameter doesn't make sense, we always must convert encoding in
1337 // Unicode build
1338 convertEncoding = true;
1339#elif wxUSE_FONTMAP
7cb06872
VZ
1340 if ( convertEncoding )
1341 {
77c514d1 1342 // determine if we need any conversion at all
7cb06872
VZ
1343 wxFontEncoding encCat = wxFontMapperBase::GetEncodingFromName(m_charset);
1344 if ( encCat == wxLocale::GetSystemEncoding() )
1345 {
1346 // no need to convert
1347 convertEncoding = false;
1348 }
1349 }
7a4b1e66 1350#endif // wxUSE_UNICODE/wxUSE_FONTMAP
7cb06872 1351
563d535e 1352#if wxUSE_WCHAR_T
35d10652
VZ
1353 // conversion to use to convert catalog strings to the GUI encoding
1354 wxMBConv *inputConv,
ca642c8a 1355 *inputConvPtr = NULL; // same as inputConv but safely deleteable
7a4b1e66 1356 if ( convertEncoding && !m_charset.empty() )
35d10652 1357 {
7a4b1e66
VZ
1358 inputConvPtr =
1359 inputConv = new wxCSConv(m_charset);
35d10652 1360 }
7a4b1e66 1361 else // no need or not possible to convert the encoding
35d10652 1362 {
f15fa3a9 1363#if wxUSE_UNICODE
7a4b1e66
VZ
1364 // we must somehow convert the narrow strings in the message catalog to
1365 // wide strings, so use the default conversion if we have no charset
f15fa3a9
VZ
1366 inputConv = wxConvCurrent;
1367#else // !wxUSE_UNICODE
35d10652 1368 inputConv = NULL;
f15fa3a9 1369#endif // wxUSE_UNICODE/!wxUSE_UNICODE
35d10652 1370 }
d721baa9 1371
35d10652
VZ
1372 // conversion to apply to msgid strings before looking them up: we only
1373 // need it if the msgids are neither in 7 bit ASCII nor in the same
1374 // encoding as the catalog
1375 wxCSConv *sourceConv = msgIdCharset.empty() || (msgIdCharset == m_charset)
1376 ? NULL
1377 : new wxCSConv(msgIdCharset);
d721baa9 1378
849a28d0 1379#elif wxUSE_FONTMAP
31b7522e 1380 wxASSERT_MSG( msgIdCharset.empty(),
ca642c8a 1381 wxS("non-ASCII msgid languages only supported if wxUSE_WCHAR_T=1") );
7beb59f3 1382
849a28d0 1383 wxEncodingConverter converter;
563d535e
VS
1384 if ( convertEncoding )
1385 {
baf736e1 1386 wxFontEncoding targetEnc = wxFONTENCODING_SYSTEM;
267e11c5 1387 wxFontEncoding enc = wxFontMapperBase::Get()->CharsetToEncoding(m_charset, false);
563d535e
VS
1388 if ( enc == wxFONTENCODING_SYSTEM )
1389 {
7beb59f3 1390 convertEncoding = false; // unknown encoding
563d535e
VS
1391 }
1392 else
1393 {
baf736e1 1394 targetEnc = wxLocale::GetSystemEncoding();
563d535e
VS
1395 if (targetEnc == wxFONTENCODING_SYSTEM)
1396 {
1397 wxFontEncodingArray a = wxEncodingConverter::GetPlatformEquivalents(enc);
1398 if (a[0] == enc)
1399 // no conversion needed, locale uses native encoding
7beb59f3 1400 convertEncoding = false;
563d535e
VS
1401 if (a.GetCount() == 0)
1402 // we don't know common equiv. under this platform
7beb59f3 1403 convertEncoding = false;
563d535e
VS
1404 targetEnc = a[0];
1405 }
1406 }
1407
1408 if ( convertEncoding )
1409 {
563d535e 1410 converter.Init(enc, targetEnc);
563d535e
VS
1411 }
1412 }
563d535e 1413#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
0c93d67c 1414 (void)convertEncoding; // get rid of warnings about unused parameter
bc385ba9 1415
4a10ea8b 1416 for (size_t32 i = 0; i < m_numStrings; i++)
563d535e 1417 {
849a28d0 1418 const char *data = StringAtOfs(m_pOrigTable, i);
f00204d3
FM
1419 if (!data)
1420 return false; // may happen for invalid MO files
7a4b1e66
VZ
1421
1422 wxString msgid;
d721baa9 1423#if wxUSE_UNICODE
7a4b1e66 1424 msgid = wxString(data, *inputConv);
35d10652 1425#else // ASCII
f15fa3a9
VZ
1426 #if wxUSE_WCHAR_T
1427 if ( inputConv && sourceConv )
1428 msgid = wxString(inputConv->cMB2WC(data), *sourceConv);
1429 else
1430 #endif
7a4b1e66 1431 msgid = data;
d721baa9 1432#endif // wxUSE_UNICODE
563d535e 1433
849a28d0 1434 data = StringAtOfs(m_pTransTable, i);
f00204d3
FM
1435 if (!data)
1436 return false; // may happen for invalid MO files
1437
849a28d0
VS
1438 size_t length = Swap(m_pTransTable[i].nLen);
1439 size_t offset = 0;
1440 size_t index = 0;
1441 while (offset < length)
1442 {
7a4b1e66
VZ
1443 const char * const str = data + offset;
1444
849a28d0 1445 wxString msgstr;
7a4b1e66
VZ
1446#if wxUSE_UNICODE
1447 msgstr = wxString(str, *inputConv);
1448#elif wxUSE_WCHAR_T
35d10652 1449 if ( inputConv )
7a4b1e66 1450 msgstr = wxString(inputConv->cMB2WC(str), *wxConvUI);
849a28d0 1451 else
7a4b1e66 1452 msgstr = str;
849a28d0
VS
1453#else // !wxUSE_WCHAR_T
1454 #if wxUSE_FONTMAP
31b7522e 1455 if ( bConvertEncoding )
7a4b1e66 1456 msgstr = wxString(converter.Convert(str));
849a28d0
VS
1457 else
1458 #endif
7a4b1e66 1459 msgstr = str;
849a28d0 1460#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
9e7ed2b0 1461
849a28d0
VS
1462 if ( !msgstr.empty() )
1463 {
1464 hash[index == 0 ? msgid : msgid + wxChar(index)] = msgstr;
1465 }
7a4b1e66
VZ
1466
1467 // skip this string
89a7e1ff 1468 // IMPORTANT: accesses to the 'data' pointer are valid only for
f00204d3 1469 // the first 'length+1' bytes (GNU specs says that the
89a7e1ff 1470 // final NUL is not counted in length); using wxStrnlen()
f00204d3
FM
1471 // we make sure we don't access memory beyond the valid range
1472 // (which otherwise may happen for invalid MO files):
1473 offset += wxStrnlen(str, length - offset) + 1;
849a28d0
VS
1474 ++index;
1475 }
41780009 1476 }
9e7ed2b0 1477
849a28d0 1478#if wxUSE_WCHAR_T
d721baa9 1479 delete sourceConv;
7a4b1e66
VZ
1480 delete inputConvPtr;
1481#endif // wxUSE_WCHAR_T
f00204d3
FM
1482
1483 return true;
563d535e 1484}
bc385ba9 1485
849a28d0 1486
563d535e
VS
1487// ----------------------------------------------------------------------------
1488// wxMsgCatalog class
1489// ----------------------------------------------------------------------------
bc385ba9 1490
6fbc2636 1491#if !wxUSE_UNICODE
77c514d1
VZ
1492wxMsgCatalog::~wxMsgCatalog()
1493{
1494 if ( m_conv )
1495 {
1496 if ( wxConvUI == m_conv )
1497 {
1498 // we only change wxConvUI if it points to wxConvLocal so we reset
1499 // it back to it too
1500 wxConvUI = &wxConvLocal;
1501 }
1502
1503 delete m_conv;
1504 }
1505}
6fbc2636 1506#endif // !wxUSE_UNICODE
77c514d1 1507
31b7522e
VS
1508bool wxMsgCatalog::Load(const wxString& dirPrefix, const wxString& name,
1509 const wxString& msgIdCharset, bool bConvertEncoding)
563d535e
VS
1510{
1511 wxMsgCatalogFile file;
9e7ed2b0 1512
31b7522e 1513 m_name = name;
9e7ed2b0 1514
31b7522e 1515 if ( !file.Load(dirPrefix, name, m_pluralFormsCalculator) )
77c514d1
VZ
1516 return false;
1517
f00204d3
FM
1518 if ( !file.FillHash(m_messages, msgIdCharset, bConvertEncoding) )
1519 return false;
77c514d1 1520
6fbc2636 1521#if !wxUSE_UNICODE
77c514d1
VZ
1522 // we should use a conversion compatible with the message catalog encoding
1523 // in the GUI if we don't convert the strings to the current conversion but
1524 // as the encoding is global, only change it once, otherwise we could get
1525 // into trouble if we use several message catalogs with different encodings
1526 //
1527 // this is, of course, a hack but it at least allows the program to use
1528 // message catalogs in any encodings without asking the user to change his
1529 // locale
1530 if ( !bConvertEncoding &&
1531 !file.GetCharset().empty() &&
1532 wxConvUI == &wxConvLocal )
563d535e 1533 {
77c514d1
VZ
1534 wxConvUI =
1535 m_conv = new wxCSConv(file.GetCharset());
563d535e 1536 }
6fbc2636 1537#endif // !wxUSE_UNICODE
821d0fef 1538
77c514d1 1539 return true;
afc94fa6
VS
1540}
1541
31b7522e 1542const wxString *wxMsgCatalog::GetString(const wxString& str, size_t n) const
563d535e 1543{
849a28d0
VS
1544 int index = 0;
1545 if (n != size_t(-1))
1546 {
1547 index = m_pluralFormsCalculator->evaluate(n);
1548 }
1549 wxMessagesHash::const_iterator i;
1550 if (index != 0)
1551 {
31b7522e 1552 i = m_messages.find(wxString(str) + wxChar(index)); // plural
849a28d0
VS
1553 }
1554 else
1555 {
31b7522e 1556 i = m_messages.find(str);
849a28d0
VS
1557 }
1558
563d535e
VS
1559 if ( i != m_messages.end() )
1560 {
31b7522e 1561 return &i->second;
563d535e
VS
1562 }
1563 else
1564 return NULL;
1565}
afc94fa6 1566
c801d85f
KB
1567// ----------------------------------------------------------------------------
1568// wxLocale
1569// ----------------------------------------------------------------------------
1570
d3f3e35f
VS
1571#include "wx/arrimpl.cpp"
1572WX_DECLARE_EXPORTED_OBJARRAY(wxLanguageInfo, wxLanguageInfoArray);
4115960d 1573WX_DEFINE_OBJARRAY(wxLanguageInfoArray)
d3f3e35f 1574
41780009
VS
1575wxLanguageInfoArray *wxLocale::ms_languagesDB = NULL;
1576
1577/*static*/ void wxLocale::CreateLanguagesDB()
1578{
1579 if (ms_languagesDB == NULL)
1580 {
1581 ms_languagesDB = new wxLanguageInfoArray;
1582 InitLanguagesDB();
1583 }
1584}
1585
1586/*static*/ void wxLocale::DestroyLanguagesDB()
1587{
1588 delete ms_languagesDB;
1589 ms_languagesDB = NULL;
1590}
1591
1592
ea8f6fc7 1593void wxLocale::DoCommonInit()
c801d85f 1594{
ca642c8a 1595 m_pszOldLocale = NULL;
eb48778d 1596
ca642c8a 1597 m_pOldLocale = wxSetLocale(this);
eb48778d 1598
ca642c8a
FM
1599 m_pMsgCat = NULL;
1600 m_language = wxLANGUAGE_UNKNOWN;
1601 m_initialized = false;
23fcecf7
VZ
1602}
1603
1604// NB: this function has (desired) side effect of changing current locale
31b7522e
VS
1605bool wxLocale::Init(const wxString& name,
1606 const wxString& shortName,
1607 const wxString& locale,
1608 bool bLoadDefault,
1609 bool bConvertEncoding)
23fcecf7 1610{
ca642c8a
FM
1611 wxASSERT_MSG( !m_initialized,
1612 wxS("you can't call wxLocale::Init more than once") );
b7b97e77 1613
ca642c8a
FM
1614 m_initialized = true;
1615 m_strLocale = name;
1616 m_strShort = shortName;
1617 m_bConvertEncoding = bConvertEncoding;
1618 m_language = wxLANGUAGE_UNKNOWN;
23fcecf7 1619
ca642c8a
FM
1620 // change current locale (default: same as long name)
1621 wxString szLocale(locale);
1622 if ( szLocale.empty() )
1623 {
1624 // the argument to setlocale()
1625 szLocale = shortName;
52558258 1626
ca642c8a
FM
1627 wxCHECK_MSG( !szLocale.empty(), false,
1628 wxS("no locale to set in wxLocale::Init()") );
1629 }
10545ca4 1630
ca642c8a
FM
1631 const char *oldLocale = wxSetlocale(LC_ALL, szLocale);
1632 if ( oldLocale )
1633 m_pszOldLocale = wxStrdup(oldLocale);
1634 else
1635 m_pszOldLocale = NULL;
1c193821 1636
ca642c8a 1637 if ( m_pszOldLocale == NULL )
af588446 1638 {
ca642c8a 1639 wxLogError(_("locale '%s' can not be set."), szLocale);
af588446 1640 }
c801d85f 1641
ca642c8a
FM
1642 // the short name will be used to look for catalog files as well,
1643 // so we need something here
1644 if ( m_strShort.empty() ) {
1645 // FIXME I don't know how these 2 letter abbreviations are formed,
1646 // this wild guess is surely wrong
1647 if ( !szLocale.empty() )
1648 {
1649 m_strShort += (wxChar)wxTolower(szLocale[0]);
1650 if ( szLocale.length() > 1 )
1651 m_strShort += (wxChar)wxTolower(szLocale[1]);
1652 }
70426fba 1653 }
7af89395 1654
ca642c8a
FM
1655 // load the default catalog with wxWidgets standard messages
1656 m_pMsgCat = NULL;
1657 bool bOk = true;
1658 if ( bLoadDefault )
4d931bcc 1659 {
ca642c8a
FM
1660 bOk = AddCatalog(wxS("wxstd"));
1661
1662 // there may be a catalog with toolkit specific overrides, it is not
1663 // an error if this does not exist
1664 if ( bOk )
1665 {
1666 wxString port(wxPlatformInfo::Get().GetPortIdName());
1667 if ( !port.empty() )
1668 {
1669 AddCatalog(port.BeforeFirst(wxS('/')).MakeLower());
1670 }
1671 }
4d931bcc 1672 }
4d931bcc 1673
ca642c8a 1674 return bOk;
c801d85f
KB
1675}
1676
41524ffc 1677
1cc549e5 1678#if defined(__UNIX__) && wxUSE_UNICODE && !defined(__WXMAC__)
52de37c7 1679static const char *wxSetlocaleTryUTF8(int c, const wxString& lc)
41524ffc 1680{
aff909dd 1681 const char *l = NULL;
cb352236
VS
1682
1683 // NB: We prefer to set UTF-8 locale if it's possible and only fall back to
1684 // non-UTF-8 locale if it fails
1685
52de37c7 1686 if ( !lc.empty() )
41524ffc 1687 {
7beb59f3 1688 wxString buf(lc);
2d34a303 1689 wxString buf2;
a0516656 1690 buf2 = buf + wxS(".UTF-8");
52de37c7 1691 l = wxSetlocale(c, buf2);
2d34a303
VS
1692 if ( !l )
1693 {
a0516656 1694 buf2 = buf + wxS(".utf-8");
52de37c7 1695 l = wxSetlocale(c, buf2);
2d34a303
VS
1696 }
1697 if ( !l )
1698 {
a0516656 1699 buf2 = buf + wxS(".UTF8");
52de37c7 1700 l = wxSetlocale(c, buf2);
2d34a303
VS
1701 }
1702 if ( !l )
1703 {
a0516656 1704 buf2 = buf + wxS(".utf8");
52de37c7 1705 l = wxSetlocale(c, buf2);
2d34a303 1706 }
41524ffc 1707 }
cb352236
VS
1708
1709 // if we can't set UTF-8 locale, try non-UTF-8 one:
1710 if ( !l )
1711 l = wxSetlocale(c, lc);
1712
41524ffc
VS
1713 return l;
1714}
1715#else
cb352236 1716#define wxSetlocaleTryUTF8(c, lc) wxSetlocale(c, lc)
41524ffc
VS
1717#endif
1718
d3f3e35f
VS
1719bool wxLocale::Init(int language, int flags)
1720{
2aebd278
VZ
1721 bool ret = true;
1722
d3f3e35f 1723 int lang = language;
ec37df57
VZ
1724 if (lang == wxLANGUAGE_DEFAULT)
1725 {
1726 // auto detect the language
1727 lang = GetSystemLanguage();
1728 }
1729
1730 // We failed to detect system language, so we will use English:
1731 if (lang == wxLANGUAGE_UNKNOWN)
1732 {
ca642c8a 1733 return false;
ec37df57
VZ
1734 }
1735
14f8fa9d 1736 const wxLanguageInfo *info = GetLanguageInfo(lang);
d3f3e35f 1737
d3f3e35f
VS
1738 // Unknown language:
1739 if (info == NULL)
1740 {
a0516656 1741 wxLogError(wxS("Unknown language %i."), lang);
7beb59f3 1742 return false;
d3f3e35f
VS
1743 }
1744
1745 wxString name = info->Description;
1746 wxString canonical = info->CanonicalName;
1747 wxString locale;
ec37df57 1748
d3f3e35f 1749 // Set the locale:
55034339 1750#if defined(__OS2__)
52de37c7 1751 const char *retloc = wxSetlocale(LC_ALL , wxEmptyString);
55034339 1752#elif defined(__UNIX__) && !defined(__WXMAC__)
d368dbea 1753 if (language != wxLANGUAGE_DEFAULT)
ec37df57 1754 locale = info->CanonicalName;
d3f3e35f 1755
52de37c7 1756 const char *retloc = wxSetlocaleTryUTF8(LC_ALL, locale);
d3f3e35f 1757
f6ba36e4 1758 const wxString langOnly = ExtractLang(locale);
2b5f62a0 1759 if ( !retloc )
d3f3e35f
VS
1760 {
1761 // Some C libraries don't like xx_YY form and require xx only
cb352236 1762 retloc = wxSetlocaleTryUTF8(LC_ALL, langOnly);
d3f3e35f 1763 }
d368dbea
VZ
1764
1765#if wxUSE_FONTMAP
1766 // some systems (e.g. FreeBSD and HP-UX) don't have xx_YY aliases but
1767 // require the full xx_YY.encoding form, so try using UTF-8 because this is
1768 // the only thing we can do generically
1769 //
1770 // TODO: add encodings applicable to each language to the lang DB and try
1771 // them all in turn here
2b5f62a0 1772 if ( !retloc )
d3f3e35f 1773 {
d368dbea
VZ
1774 const wxChar **names =
1775 wxFontMapperBase::GetAllEncodingNames(wxFONTENCODING_UTF8);
1776 while ( *names )
1777 {
a0516656 1778 retloc = wxSetlocale(LC_ALL, locale + wxS('.') + *names++);
d368dbea
VZ
1779 if ( retloc )
1780 break;
1781 }
d3f3e35f 1782 }
d368dbea
VZ
1783#endif // wxUSE_FONTMAP
1784
2b5f62a0 1785 if ( !retloc )
d3f3e35f 1786 {
d368dbea
VZ
1787 // Some C libraries (namely glibc) still use old ISO 639,
1788 // so will translate the abbrev for them
1789 wxString localeAlt;
a0516656 1790 if ( langOnly == wxS("he") )
f6ba36e4 1791 localeAlt = wxS("iw") + ExtractNotLang(locale);
a0516656 1792 else if ( langOnly == wxS("id") )
f6ba36e4 1793 localeAlt = wxS("in") + ExtractNotLang(locale);
a0516656 1794 else if ( langOnly == wxS("yi") )
f6ba36e4 1795 localeAlt = wxS("ji") + ExtractNotLang(locale);
a0516656
VZ
1796 else if ( langOnly == wxS("nb") )
1797 localeAlt = wxS("no_NO");
1798 else if ( langOnly == wxS("nn") )
1799 localeAlt = wxS("no_NY");
d368dbea
VZ
1800
1801 if ( !localeAlt.empty() )
1802 {
cb352236 1803 retloc = wxSetlocaleTryUTF8(LC_ALL, localeAlt);
d368dbea 1804 if ( !retloc )
f6ba36e4 1805 retloc = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(localeAlt));
d368dbea 1806 }
d3f3e35f 1807 }
d368dbea 1808
2b5f62a0 1809 if ( !retloc )
2aebd278 1810 ret = false;
d368dbea
VZ
1811
1812#ifdef __AIX__
31b7522e
VS
1813 // at least in AIX 5.2 libc is buggy and the string returned from
1814 // setlocale(LC_ALL) can't be passed back to it because it returns 6
1815 // strings (one for each locale category), i.e. for C locale we get back
1816 // "C C C C C C"
d368dbea 1817 //
31b7522e
VS
1818 // this contradicts IBM own docs but this is not of much help, so just work
1819 // around it in the crudest possible manner
c222ad41 1820 char* p = const_cast<char*>(wxStrchr(retloc, ' '));
d368dbea 1821 if ( p )
52de37c7 1822 *p = '\0';
d368dbea
VZ
1823#endif // __AIX__
1824
d3f3e35f 1825#elif defined(__WIN32__)
52de37c7 1826 const char *retloc = "C";
42db82fd 1827 if ( language != wxLANGUAGE_DEFAULT )
d3f3e35f 1828 {
42db82fd 1829 if ( info->WinLang == 0 )
d3f3e35f 1830 {
a0516656 1831 wxLogWarning(wxS("Locale '%s' not supported by OS."), name.c_str());
2b5f62a0 1832 // retloc already set to "C"
63986ba6 1833 }
42db82fd 1834 else // language supported by Windows
ec37df57 1835 {
99abd9c8
VZ
1836 // Windows CE doesn't have SetThreadLocale() and there doesn't seem
1837 // to be any equivalent
1c193821 1838#ifndef __WXWINCE__
fb090fa1
VZ
1839 const wxUint32 lcid = info->GetLCID();
1840
86d62b51
VZ
1841 // change locale used by Windows functions
1842 ::SetThreadLocale(lcid);
1c193821 1843#endif
99abd9c8 1844
86d62b51
VZ
1845 // and also call setlocale() to change locale used by the CRT
1846 locale = info->GetLocaleName();
1847 if ( locale.empty() )
65dc921d 1848 {
2aebd278 1849 ret = false;
2b5f62a0 1850 }
86d62b51 1851 else // have a valid locale
c611452f 1852 {
65dc921d 1853 retloc = wxSetlocale(LC_ALL, locale);
c611452f 1854 }
d3f3e35f
VS
1855 }
1856 }
42db82fd 1857 else // language == wxLANGUAGE_DEFAULT
2b5f62a0 1858 {
c611452f 1859 retloc = wxSetlocale(LC_ALL, wxEmptyString);
42db82fd 1860 }
99abd9c8 1861
42db82fd
VZ
1862#if wxUSE_UNICODE && (defined(__VISUALC__) || defined(__MINGW32__))
1863 // VC++ setlocale() (also used by Mingw) can't set locale to languages that
1864 // can only be written using Unicode, therefore wxSetlocale() call fails
1865 // for such languages but we don't want to report it as an error -- so that
1866 // at least message catalogs can be used.
1867 if ( !retloc )
1868 {
1869 if ( wxGetANSICodePageForLocale(LOCALE_USER_DEFAULT).empty() )
65dc921d 1870 {
42db82fd
VZ
1871 // we set the locale to a Unicode-only language, don't treat the
1872 // inability of CRT to use it as an error
1873 retloc = "C";
65dc921d 1874 }
2b5f62a0 1875 }
42db82fd 1876#endif // CRT not handling Unicode-only languages
c611452f 1877
2b5f62a0 1878 if ( !retloc )
2aebd278 1879 ret = false;
85fb2206 1880#elif defined(__WXMAC__)
b51daa4f 1881 if (lang == wxLANGUAGE_DEFAULT)
85fb2206
SC
1882 locale = wxEmptyString;
1883 else
1884 locale = info->CanonicalName;
1885
52de37c7 1886 const char *retloc = wxSetlocale(LC_ALL, locale);
85fb2206
SC
1887
1888 if ( !retloc )
1889 {
1890 // Some C libraries don't like xx_YY form and require xx only
f6ba36e4 1891 retloc = wxSetlocale(LC_ALL, ExtractLang(locale));
85fb2206 1892 }
d3f3e35f 1893#else
ead190e4 1894 wxUnusedVar(flags);
7beb59f3 1895 return false;
e879e020 1896 #define WX_NO_LOCALE_SUPPORT
d3f3e35f 1897#endif
ec37df57 1898
e879e020 1899#ifndef WX_NO_LOCALE_SUPPORT
2aebd278
VZ
1900 if ( !ret )
1901 {
1902 wxLogWarning(_("Cannot set locale to language \"%s\"."), name.c_str());
1903
1904 // continue nevertheless and try to load at least the translations for
1905 // this language
1906 }
1907
1908 if ( !Init(name, canonical, retloc,
ca642c8a
FM
1909 (flags & wxLOCALE_LOAD_DEFAULT) != 0,
1910 (flags & wxLOCALE_CONV_ENCODING) != 0) )
2aebd278
VZ
1911 {
1912 ret = false;
1913 }
10545ca4 1914
549a7c37 1915 if (IsOk()) // setlocale() succeeded
10545ca4
VZ
1916 m_language = lang;
1917
b78a78f7 1918 return ret;
b7e1957a 1919#endif // !WX_NO_LOCALE_SUPPORT
d3f3e35f
VS
1920}
1921
1922
1923
fd323a5e
VZ
1924void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix)
1925{
f830b2b1 1926 if ( gs_searchPrefixes.Index(prefix) == wxNOT_FOUND )
fd323a5e 1927 {
f830b2b1 1928 gs_searchPrefixes.Add(prefix);
fd323a5e
VZ
1929 }
1930 //else: already have it
1931}
1932
41780009 1933/*static*/ int wxLocale::GetSystemLanguage()
d3f3e35f 1934{
41780009 1935 CreateLanguagesDB();
ec37df57
VZ
1936
1937 // init i to avoid compiler warning
1938 size_t i = 0,
ca642c8a 1939 count = ms_languagesDB->GetCount();
d3f3e35f 1940
9b3dbb11 1941#if defined(__UNIX__)
ec37df57
VZ
1942 // first get the string identifying the language from the environment
1943 wxString langFull;
9b3dbb11 1944#ifdef __WXMAC__
9b3dbb11 1945 wxCFRef<CFLocaleRef> userLocaleRef(CFLocaleCopyCurrent());
529e125d
JS
1946
1947 // because the locale identifier (kCFLocaleIdentifier) is formatted a little bit differently, eg
9b3dbb11 1948 // az_Cyrl_AZ@calendar=buddhist;currency=JPY we just recreate the base info as expected by wx here
529e125d 1949
80539f04 1950 wxCFStringRef str(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleLanguageCode)));
9b3dbb11 1951 langFull = str.AsString()+"_";
80539f04 1952 str.reset(wxCFRetain((CFStringRef)CFLocaleGetValue(userLocaleRef, kCFLocaleCountryCode)));
9b3dbb11
SC
1953 langFull += str.AsString();
1954#else
a0516656
VZ
1955 if (!wxGetEnv(wxS("LC_ALL"), &langFull) &&
1956 !wxGetEnv(wxS("LC_MESSAGES"), &langFull) &&
1957 !wxGetEnv(wxS("LANG"), &langFull))
ec37df57 1958 {
ff1bd293
VZ
1959 // no language specified, treat it as English
1960 return wxLANGUAGE_ENGLISH_US;
ec37df57 1961 }
d3f3e35f 1962
a0516656 1963 if ( langFull == wxS("C") || langFull == wxS("POSIX") )
d3f3e35f 1964 {
ff1bd293
VZ
1965 // default C locale is English too
1966 return wxLANGUAGE_ENGLISH_US;
d3f3e35f 1967 }
9b3dbb11 1968#endif
d3f3e35f 1969
ec37df57
VZ
1970 // the language string has the following form
1971 //
efd1393b 1972 // lang[_LANG][.encoding][@modifier]
ec37df57 1973 //
efd1393b
VZ
1974 // (see environ(5) in the Open Unix specification)
1975 //
1976 // where lang is the primary language, LANG is a sublang/territory,
1977 // encoding is the charset to use and modifier "allows the user to select
1978 // a specific instance of localization data within a single category"
ec37df57
VZ
1979 //
1980 // for example, the following strings are valid:
1981 // fr
1982 // fr_FR
1983 // de_DE.iso88591
efd1393b
VZ
1984 // de_DE@euro
1985 // de_DE.iso88591@euro
ec37df57
VZ
1986
1987 // for now we don't use the encoding, although we probably should (doing
1988 // translations of the msg catalogs on the fly as required) (TODO)
efd1393b 1989 //
8cee59b5
VZ
1990 // we need the modified for languages like Valencian: ca_ES@valencia
1991 // though, remember it
1992 wxString modifier;
1993 size_t posModifier = langFull.find_first_of(wxS("@"));
1994 if ( posModifier != wxString::npos )
1995 modifier = langFull.Mid(posModifier);
1996
a0516656 1997 size_t posEndLang = langFull.find_first_of(wxS("@."));
efd1393b
VZ
1998 if ( posEndLang != wxString::npos )
1999 {
2000 langFull.Truncate(posEndLang);
2001 }
ec37df57
VZ
2002
2003 // in addition to the format above, we also can have full language names
2004 // in LANG env var - for example, SuSE is known to use LANG="german" - so
2005 // check for this
2006
2007 // do we have just the language (or sublang too)?
df69528b 2008 bool justLang = langFull.length() == LEN_LANG;
ec37df57 2009 if ( justLang ||
ca642c8a 2010 (langFull.length() == LEN_FULL && langFull[LEN_LANG] == wxS('_')) )
d3f3e35f 2011 {
ec37df57 2012 // 0. Make sure the lang is according to latest ISO 639
3103e8a9 2013 // (this is necessary because glibc uses iw and in instead
ec37df57
VZ
2014 // of he and id respectively).
2015
2016 // the language itself (second part is the dialect/sublang)
2017 wxString langOrig = ExtractLang(langFull);
2018
2019 wxString lang;
a0516656
VZ
2020 if ( langOrig == wxS("iw"))
2021 lang = wxS("he");
2022 else if (langOrig == wxS("in"))
2023 lang = wxS("id");
2024 else if (langOrig == wxS("ji"))
2025 lang = wxS("yi");
2026 else if (langOrig == wxS("no_NO"))
2027 lang = wxS("nb_NO");
2028 else if (langOrig == wxS("no_NY"))
2029 lang = wxS("nn_NO");
2030 else if (langOrig == wxS("no"))
2031 lang = wxS("nb_NO");
ec37df57
VZ
2032 else
2033 lang = langOrig;
2034
2035 // did we change it?
2036 if ( lang != langOrig )
d3f3e35f 2037 {
ec37df57
VZ
2038 langFull = lang + ExtractNotLang(langFull);
2039 }
2040
2041 // 1. Try to find the language either as is:
8cee59b5
VZ
2042 // a) With modifier if set
2043 if ( !modifier.empty() )
ec37df57 2044 {
8cee59b5
VZ
2045 wxString langFullWithModifier = langFull + modifier;
2046 for ( i = 0; i < count; i++ )
d3f3e35f 2047 {
8cee59b5
VZ
2048 if ( ms_languagesDB->Item(i).CanonicalName == langFullWithModifier )
2049 break;
2050 }
2051 }
2052
2053 // b) Without modifier
2054 if ( modifier.empty() || i == count )
2055 {
2056 for ( i = 0; i < count; i++ )
2057 {
2058 if ( ms_languagesDB->Item(i).CanonicalName == langFull )
2059 break;
d3f3e35f
VS
2060 }
2061 }
d3f3e35f 2062
ec37df57
VZ
2063 // 2. If langFull is of the form xx_YY, try to find xx:
2064 if ( i == count && !justLang )
d3f3e35f 2065 {
ec37df57 2066 for ( i = 0; i < count; i++ )
d3f3e35f 2067 {
41780009 2068 if ( ms_languagesDB->Item(i).CanonicalName == lang )
ec37df57
VZ
2069 {
2070 break;
2071 }
d3f3e35f
VS
2072 }
2073 }
d3f3e35f 2074
ec37df57
VZ
2075 // 3. If langFull is of the form xx, try to find any xx_YY record:
2076 if ( i == count && justLang )
d3f3e35f 2077 {
ec37df57 2078 for ( i = 0; i < count; i++ )
d3f3e35f 2079 {
41780009 2080 if ( ExtractLang(ms_languagesDB->Item(i).CanonicalName)
ec37df57
VZ
2081 == langFull )
2082 {
2083 break;
2084 }
d3f3e35f
VS
2085 }
2086 }
2087 }
ec37df57 2088 else // not standard format
d3f3e35f 2089 {
ec37df57
VZ
2090 // try to find the name in verbose description
2091 for ( i = 0; i < count; i++ )
d3f3e35f 2092 {
41780009 2093 if (ms_languagesDB->Item(i).Description.CmpNoCase(langFull) == 0)
d3f3e35f 2094 {
d3f3e35f
VS
2095 break;
2096 }
2097 }
2098 }
d3f3e35f
VS
2099#elif defined(__WIN32__)
2100 LCID lcid = GetUserDefaultLCID();
ec37df57 2101 if ( lcid != 0 )
d3f3e35f 2102 {
ec37df57
VZ
2103 wxUint32 lang = PRIMARYLANGID(LANGIDFROMLCID(lcid));
2104 wxUint32 sublang = SUBLANGID(LANGIDFROMLCID(lcid));
2105
2106 for ( i = 0; i < count; i++ )
d3f3e35f 2107 {
41780009
VS
2108 if (ms_languagesDB->Item(i).WinLang == lang &&
2109 ms_languagesDB->Item(i).WinSublang == sublang)
ec37df57
VZ
2110 {
2111 break;
2112 }
d3f3e35f
VS
2113 }
2114 }
ec37df57
VZ
2115 //else: leave wxlang == wxLANGUAGE_UNKNOWN
2116#endif // Unix/Win32
d3f3e35f 2117
ec37df57
VZ
2118 if ( i < count )
2119 {
2120 // we did find a matching entry, use it
41780009 2121 return ms_languagesDB->Item(i).Language;
ec37df57 2122 }
d3f3e35f 2123
ec37df57
VZ
2124 // no info about this language in the database
2125 return wxLANGUAGE_UNKNOWN;
2126}
d3f3e35f 2127
dccce9ea
VZ
2128// ----------------------------------------------------------------------------
2129// encoding stuff
2130// ----------------------------------------------------------------------------
2131
2132// this is a bit strange as under Windows we get the encoding name using its
2133// numeric value and under Unix we do it the other way round, but this just
97626624 2134// reflects the way different systems provide the encoding info
dccce9ea
VZ
2135
2136/* static */
2137wxString wxLocale::GetSystemEncodingName()
2138{
2139 wxString encname;
2140
c67d6888 2141#if defined(__WIN32__) && !defined(__WXMICROWIN__)
dccce9ea
VZ
2142 // FIXME: what is the error return value for GetACP()?
2143 UINT codepage = ::GetACP();
a0516656 2144 encname.Printf(wxS("windows-%u"), codepage);
1ad48afb
SC
2145#elif defined(__WXMAC__)
2146 // default is just empty string, this resolves to the default system
2147 // encoding later
dccce9ea
VZ
2148#elif defined(__UNIX_LIKE__)
2149
2150#if defined(HAVE_LANGINFO_H) && defined(CODESET)
2151 // GNU libc provides current character set this way (this conforms
2152 // to Unix98)
2ec6905c
VS
2153 char *oldLocale = strdup(setlocale(LC_CTYPE, NULL));
2154 setlocale(LC_CTYPE, "");
f284605f 2155 const char *alang = nl_langinfo(CODESET);
2ec6905c 2156 setlocale(LC_CTYPE, oldLocale);
030c0bea 2157 free(oldLocale);
84f858e9
VZ
2158
2159 if ( alang )
dccce9ea 2160 {
09d2016d 2161 encname = wxString::FromAscii( alang );
dccce9ea 2162 }
09d2016d 2163 else // nl_langinfo() failed
dccce9ea
VZ
2164#endif // HAVE_LANGINFO_H
2165 {
2166 // if we can't get at the character set directly, try to see if it's in
2167 // the environment variables (in most cases this won't work, but I was
2168 // out of ideas)
b1ac3b56 2169 char *lang = getenv( "LC_ALL");
d3b9f782 2170 char *dot = lang ? strchr(lang, '.') : NULL;
dccce9ea
VZ
2171 if (!dot)
2172 {
b1ac3b56 2173 lang = getenv( "LC_CTYPE" );
dccce9ea 2174 if ( lang )
b1ac3b56 2175 dot = strchr(lang, '.' );
dccce9ea
VZ
2176 }
2177 if (!dot)
2178 {
b1ac3b56 2179 lang = getenv( "LANG");
dccce9ea 2180 if ( lang )
b1ac3b56 2181 dot = strchr(lang, '.');
dccce9ea
VZ
2182 }
2183
2184 if ( dot )
2185 {
b1ac3b56 2186 encname = wxString::FromAscii( dot+1 );
dccce9ea
VZ
2187 }
2188 }
2189#endif // Win32/Unix
2190
2191 return encname;
2192}
2193
2194/* static */
2195wxFontEncoding wxLocale::GetSystemEncoding()
2196{
c67d6888 2197#if defined(__WIN32__) && !defined(__WXMICROWIN__)
dccce9ea
VZ
2198 UINT codepage = ::GetACP();
2199
3c832d58 2200 // wxWidgets only knows about CP1250-1257, 874, 932, 936, 949, 950
dccce9ea
VZ
2201 if ( codepage >= 1250 && codepage <= 1257 )
2202 {
2203 return (wxFontEncoding)(wxFONTENCODING_CP1250 + codepage - 1250);
2204 }
c7821f94 2205
3c832d58
DS
2206 if ( codepage == 874 )
2207 {
2208 return wxFONTENCODING_CP874;
2209 }
2210
c7821f94
VZ
2211 if ( codepage == 932 )
2212 {
2213 return wxFONTENCODING_CP932;
2214 }
2215
2216 if ( codepage == 936 )
2217 {
2218 return wxFONTENCODING_CP936;
2219 }
2220
2221 if ( codepage == 949 )
2222 {
2223 return wxFONTENCODING_CP949;
2224 }
2225
2226 if ( codepage == 950 )
2227 {
2228 return wxFONTENCODING_CP950;
2229 }
ec79aded 2230#elif defined(__WXMAC__)
73b51ea4 2231 CFStringEncoding encoding = 0 ;
7beb59f3 2232 encoding = CFStringGetSystemEncoding() ;
9e687455 2233 return wxMacGetFontEncFromSystemEnc( encoding ) ;
1e6feb95 2234#elif defined(__UNIX_LIKE__) && wxUSE_FONTMAP
09d2016d 2235 const wxString encname = GetSystemEncodingName();
dccce9ea
VZ
2236 if ( !encname.empty() )
2237 {
09d2016d 2238 wxFontEncoding enc = wxFontMapperBase::GetEncodingFromName(encname);
9cf28550 2239
2b5f62a0 2240 // on some modern Linux systems (RedHat 8) the default system locale
13f095d2 2241 // is UTF8 -- but it isn't supported by wxGTK1 in ANSI build at all so
2b5f62a0 2242 // don't even try to use it in this case
13f095d2
VZ
2243#if !wxUSE_UNICODE && \
2244 ((defined(__WXGTK__) && !defined(__WXGTK20__)) || defined(__WXMOTIF__))
2b5f62a0
VZ
2245 if ( enc == wxFONTENCODING_UTF8 )
2246 {
2247 // the most similar supported encoding...
2248 enc = wxFONTENCODING_ISO8859_1;
2249 }
2250#endif // !wxUSE_UNICODE
2251
09d2016d
VZ
2252 // GetEncodingFromName() returns wxFONTENCODING_DEFAULT for C locale
2253 // (a.k.a. US-ASCII) which is arguably a bug but keep it like this for
2254 // backwards compatibility and just take care to not return
2255 // wxFONTENCODING_DEFAULT from here as this surely doesn't make sense
8b34b163
VZ
2256 if ( enc == wxFONTENCODING_DEFAULT )
2257 {
2258 // we don't have wxFONTENCODING_ASCII, so use the closest one
2259 return wxFONTENCODING_ISO8859_1;
2260 }
2261
2262 if ( enc != wxFONTENCODING_MAX )
9cf28550
VZ
2263 {
2264 return enc;
2265 }
2266 //else: return wxFONTENCODING_SYSTEM below
dccce9ea
VZ
2267 }
2268#endif // Win32/Unix
2269
2270 return wxFONTENCODING_SYSTEM;
2271}
2272
14f8fa9d
VZ
2273/* static */
2274void wxLocale::AddLanguage(const wxLanguageInfo& info)
d3f3e35f 2275{
41780009
VS
2276 CreateLanguagesDB();
2277 ms_languagesDB->Add(info);
d3f3e35f
VS
2278}
2279
14f8fa9d
VZ
2280/* static */
2281const wxLanguageInfo *wxLocale::GetLanguageInfo(int lang)
2282{
2283 CreateLanguagesDB();
2284
f0ab09cc
VZ
2285 // calling GetLanguageInfo(wxLANGUAGE_DEFAULT) is a natural thing to do, so
2286 // make it work
2287 if ( lang == wxLANGUAGE_DEFAULT )
2288 lang = GetSystemLanguage();
2289
9d1e1be4 2290 const size_t count = ms_languagesDB->GetCount();
14f8fa9d
VZ
2291 for ( size_t i = 0; i < count; i++ )
2292 {
2293 if ( ms_languagesDB->Item(i).Language == lang )
2294 {
b2fde0cf
CE
2295 // We need to create a temporary here in order to make this work with BCC in final build mode
2296 wxLanguageInfo *ptr = &ms_languagesDB->Item(i);
2297 return ptr;
14f8fa9d
VZ
2298 }
2299 }
2300
2301 return NULL;
2302}
2303
4a6e4a46
VS
2304/* static */
2305wxString wxLocale::GetLanguageName(int lang)
2306{
2307 const wxLanguageInfo *info = GetLanguageInfo(lang);
2308 if ( !info )
2309 return wxEmptyString;
2310 else
2311 return info->Description;
2312}
2313
9d1e1be4
VZ
2314/* static */
2315const wxLanguageInfo *wxLocale::FindLanguageInfo(const wxString& locale)
2316{
2317 CreateLanguagesDB();
2318
2319 const wxLanguageInfo *infoRet = NULL;
2320
2321 const size_t count = ms_languagesDB->GetCount();
2322 for ( size_t i = 0; i < count; i++ )
2323 {
2324 const wxLanguageInfo *info = &ms_languagesDB->Item(i);
2325
2326 if ( wxStricmp(locale, info->CanonicalName) == 0 ||
2327 wxStricmp(locale, info->Description) == 0 )
2328 {
2329 // exact match, stop searching
2330 infoRet = info;
2331 break;
2332 }
2333
a0516656 2334 if ( wxStricmp(locale, info->CanonicalName.BeforeFirst(wxS('_'))) == 0 )
9d1e1be4
VZ
2335 {
2336 // a match -- but maybe we'll find an exact one later, so continue
2337 // looking
2338 //
2339 // OTOH, maybe we had already found a language match and in this
52de37c7 2340 // case don't overwrite it because the entry for the default
9d1e1be4
VZ
2341 // country always appears first in ms_languagesDB
2342 if ( !infoRet )
2343 infoRet = info;
2344 }
2345 }
2346
2347 return infoRet;
2348}
2349
d3f3e35f
VS
2350wxString wxLocale::GetSysName() const
2351{
2352 return wxSetlocale(LC_ALL, NULL);
2353}
2354
c801d85f
KB
2355// clean up
2356wxLocale::~wxLocale()
2357{
fd323a5e
VZ
2358 // free memory
2359 wxMsgCatalog *pTmpCat;
2360 while ( m_pMsgCat != NULL ) {
2361 pTmpCat = m_pMsgCat;
2362 m_pMsgCat = m_pMsgCat->m_pNext;
2363 delete pTmpCat;
2364 }
2365
eb48778d
VZ
2366 // restore old locale pointer
2367 wxSetLocale(m_pOldLocale);
bea561ce 2368
e36e6f95 2369 wxSetlocale(LC_ALL, m_pszOldLocale);
10545ca4 2370 free((wxChar *)m_pszOldLocale); // const_cast
c801d85f
KB
2371}
2372
2373// get the translation of given string in current locale
31b7522e
VS
2374const wxString& wxLocale::GetString(const wxString& origString,
2375 const wxString& domain) const
849a28d0 2376{
31b7522e 2377 return GetString(origString, origString, size_t(-1), domain);
849a28d0
VS
2378}
2379
31b7522e
VS
2380const wxString& wxLocale::GetString(const wxString& origString,
2381 const wxString& origString2,
2382 size_t n,
2383 const wxString& domain) const
c801d85f 2384{
31b7522e 2385 if ( origString.empty() )
a64be16e 2386 return GetUntranslatedString(origString);
c801d85f 2387
31b7522e 2388 const wxString *trans = NULL;
563d535e 2389 wxMsgCatalog *pMsgCat;
7af89395 2390
31b7522e 2391 if ( !domain.empty() )
563d535e 2392 {
31b7522e 2393 pMsgCat = FindCatalog(domain);
563d535e
VS
2394
2395 // does the catalog exist?
2396 if ( pMsgCat != NULL )
31b7522e 2397 trans = pMsgCat->GetString(origString, n);
563d535e 2398 }
9e7ed2b0 2399 else
563d535e
VS
2400 {
2401 // search in all domains
9e7ed2b0 2402 for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext )
563d535e 2403 {
31b7522e
VS
2404 trans = pMsgCat->GetString(origString, n);
2405 if ( trans != NULL ) // take the first found
563d535e
VS
2406 break;
2407 }
c801d85f
KB
2408 }
2409
31b7522e 2410 if ( trans == NULL )
563d535e 2411 {
4b6a582b
VZ
2412 wxLogTrace(TRACE_I18N,
2413 wxS("string \"%s\"[%ld] not found in %slocale '%s'."),
2414 origString, (long)n,
2415 wxString::Format(wxS("domain '%s' "), domain).c_str(),
2416 m_strLocale.c_str());
12419383 2417
849a28d0 2418 if (n == size_t(-1))
a64be16e 2419 return GetUntranslatedString(origString);
849a28d0 2420 else
a64be16e 2421 return GetUntranslatedString(n == 1 ? origString : origString2);
563d535e 2422 }
12419383 2423
31b7522e 2424 return *trans;
c801d85f
KB
2425}
2426
a64be16e
VS
2427WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual,
2428 wxLocaleUntranslatedStrings);
2429
2430/* static */
2431const wxString& wxLocale::GetUntranslatedString(const wxString& str)
2432{
2433 static wxLocaleUntranslatedStrings s_strings;
2434
2435 wxLocaleUntranslatedStrings::iterator i = s_strings.find(str);
4dfbedd3 2436 if ( i == s_strings.end() )
a64be16e
VS
2437 return *s_strings.insert(str).first;
2438
2439 return *i;
2440}
2441
31b7522e 2442wxString wxLocale::GetHeaderValue(const wxString& header,
ca642c8a 2443 const wxString& domain) const
c48908df 2444{
31b7522e 2445 if ( header.empty() )
c48908df
VZ
2446 return wxEmptyString;
2447
31b7522e 2448 const wxString *trans = NULL;
c48908df
VZ
2449 wxMsgCatalog *pMsgCat;
2450
31b7522e 2451 if ( !domain.empty() )
c48908df 2452 {
31b7522e 2453 pMsgCat = FindCatalog(domain);
c48908df
VZ
2454
2455 // does the catalog exist?
2456 if ( pMsgCat == NULL )
2457 return wxEmptyString;
2458
31b7522e 2459 trans = pMsgCat->GetString(wxEmptyString, (size_t)-1);
c48908df
VZ
2460 }
2461 else
2462 {
2463 // search in all domains
2464 for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext )
2465 {
31b7522e
VS
2466 trans = pMsgCat->GetString(wxEmptyString, (size_t)-1);
2467 if ( trans != NULL ) // take the first found
c48908df
VZ
2468 break;
2469 }
2470 }
2471
31b7522e 2472 if ( !trans || trans->empty() )
ca642c8a 2473 return wxEmptyString;
c48908df 2474
31b7522e
VS
2475 size_t found = trans->find(header);
2476 if ( found == wxString::npos )
ca642c8a 2477 return wxEmptyString;
7beb59f3 2478
31b7522e 2479 found += header.length() + 2 /* ': ' */;
c48908df
VZ
2480
2481 // Every header is separated by \n
7beb59f3 2482
a0516656 2483 size_t endLine = trans->find(wxS('\n'), found);
31b7522e 2484 size_t len = (endLine == wxString::npos) ?
ca642c8a 2485 wxString::npos : (endLine - found);
c48908df 2486
31b7522e 2487 return trans->substr(found, len);
c48908df
VZ
2488}
2489
2490
c801d85f 2491// find catalog by name in a linked list, return NULL if !found
31b7522e 2492wxMsgCatalog *wxLocale::FindCatalog(const wxString& domain) const
c801d85f 2493{
563d535e
VS
2494 // linear search in the linked list
2495 wxMsgCatalog *pMsgCat;
9e7ed2b0 2496 for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext )
563d535e 2497 {
31b7522e 2498 if ( pMsgCat->GetName() == domain )
ca642c8a 2499 return pMsgCat;
563d535e 2500 }
7af89395 2501
563d535e 2502 return NULL;
c801d85f
KB
2503}
2504
cec5ffc4
VZ
2505// check if the given locale is provided by OS and C run time
2506/* static */
2507bool wxLocale::IsAvailable(int lang)
2508{
2509 const wxLanguageInfo *info = wxLocale::GetLanguageInfo(lang);
a0516656 2510 wxCHECK_MSG( info, false, wxS("invalid language") );
cec5ffc4 2511
327bf990 2512#if defined(__WIN32__)
cec5ffc4
VZ
2513 if ( !info->WinLang )
2514 return false;
2515
ea65760d 2516 if ( !::IsValidLocale(info->GetLCID(), LCID_INSTALLED) )
327bf990
RD
2517 return false;
2518
2519#elif defined(__UNIX__)
52de37c7
VS
2520
2521 // Test if setting the locale works, then set it back.
375330ac
FM
2522 const char *oldLocale = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName);
2523 if ( !oldLocale )
327bf990
RD
2524 {
2525 // Some C libraries don't like xx_YY form and require xx only
375330ac
FM
2526 oldLocale = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName));
2527 if ( !oldLocale )
327bf990
RD
2528 return false;
2529 }
2530 // restore the original locale
52de37c7
VS
2531 wxSetlocale(LC_ALL, oldLocale);
2532#endif
cec5ffc4
VZ
2533
2534 return true;
2535}
2536
c801d85f 2537// check if the given catalog is loaded
31b7522e 2538bool wxLocale::IsLoaded(const wxString& szDomain) const
c801d85f 2539{
ca642c8a 2540 return FindCatalog(szDomain) != NULL;
c801d85f
KB
2541}
2542
2543// add a catalog to our linked list
31b7522e 2544bool wxLocale::AddCatalog(const wxString& szDomain)
d721baa9 2545{
31b7522e 2546 return AddCatalog(szDomain, wxLANGUAGE_ENGLISH_US, wxEmptyString);
d721baa9
VS
2547}
2548
2549// add a catalog to our linked list
31b7522e 2550bool wxLocale::AddCatalog(const wxString& szDomain,
ca642c8a
FM
2551 wxLanguage msgIdLanguage,
2552 const wxString& msgIdCharset)
d721baa9 2553
c801d85f 2554{
e5cf63c9 2555 wxCHECK_MSG( !m_strShort.empty(), false, "must initialize catalog first" );
6f011443 2556
a343fe63
VZ
2557
2558 // It is OK to not load catalog if the msgid language and m_language match,
2559 // in which case we can directly display the texts embedded in program's
2560 // source code:
2561 if ( msgIdLanguage == m_language )
2562 return true;
2563
2564
f6ba36e4
VZ
2565 wxMsgCatalog *pMsgCat = new wxMsgCatalog;
2566
2567 if ( pMsgCat->Load(m_strShort, szDomain, msgIdCharset, m_bConvertEncoding) )
2568 {
2569 // add it to the head of the list so that in GetString it will
2570 // be searched before the catalogs added earlier
2571 pMsgCat->m_pNext = m_pMsgCat;
2572 m_pMsgCat = pMsgCat;
7af89395 2573
f6ba36e4
VZ
2574 return true;
2575 }
7af89395 2576
c801d85f
KB
2577 // don't add it because it couldn't be loaded anyway
2578 delete pMsgCat;
7af89395 2579
f6ba36e4 2580
d721baa9
VS
2581 // If there's no exact match, we may still get partial match where the
2582 // (basic) language is same, but the country differs. For example, it's
2583 // permitted to use en_US strings from sources even if m_language is en_GB:
2584 const wxLanguageInfo *msgIdLangInfo = GetLanguageInfo(msgIdLanguage);
2585 if ( msgIdLangInfo &&
ca642c8a 2586 ExtractLang(msgIdLangInfo->CanonicalName) == ExtractLang(m_strShort) )
d721baa9
VS
2587 {
2588 return true;
2589 }
2590
2591 return false;
c801d85f
KB
2592}
2593
cfb20656
VZ
2594// ----------------------------------------------------------------------------
2595// accessors for locale-dependent data
2596// ----------------------------------------------------------------------------
2597
89a7e1ff
VZ
2598#if defined(__WXMSW__) || defined(__WXOSX__)
2599
2600namespace
2601{
2602
2603// This function translates from Unicode date formats described at
2604//
2605// http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
2606//
2607// to strftime()-like syntax. This translation is not lossless but we try to do
2608// our best.
2609
2610static wxString TranslateFromUnicodeFormat(const wxString& fmt)
2611{
2612 wxString fmtWX;
2613 fmtWX.reserve(fmt.length());
2614
2615 char chLast = '\0';
2616 size_t lastCount = 0;
03647350
VZ
2617
2618 const char* formatchars =
3e43b647
SC
2619 "dghHmMsSy"
2620#ifdef __WXMSW__
2621 "t"
47029843
SC
2622#else
2623 "EawD"
3e43b647
SC
2624#endif
2625 ;
89a7e1ff
VZ
2626 for ( wxString::const_iterator p = fmt.begin(); /* end handled inside */; ++p )
2627 {
2628 if ( p != fmt.end() )
2629 {
2630 if ( *p == chLast )
2631 {
2632 lastCount++;
2633 continue;
2634 }
2635
2636 const wxUniChar ch = (*p).GetValue();
3e43b647 2637 if ( ch.IsAscii() && strchr(formatchars, ch) )
89a7e1ff
VZ
2638 {
2639 // these characters come in groups, start counting them
2640 chLast = ch;
2641 lastCount = 1;
2642 continue;
2643 }
2644 }
2645
2646 // interpret any special characters we collected so far
2647 if ( lastCount )
2648 {
2649 switch ( chLast )
2650 {
2651 case 'd':
2652 switch ( lastCount )
2653 {
2654 case 1: // d
2655 case 2: // dd
2656 // these two are the same as we don't distinguish
2657 // between 1 and 2 digits for days
2658 fmtWX += "%d";
2659 break;
47029843 2660#ifdef __WXMSW__
89a7e1ff
VZ
2661 case 3: // ddd
2662 fmtWX += "%a";
2663 break;
2664
2665 case 4: // dddd
2666 fmtWX += "%A";
2667 break;
47029843 2668#endif
89a7e1ff
VZ
2669 default:
2670 wxFAIL_MSG( "too many 'd's" );
2671 }
2672 break;
47029843
SC
2673#ifndef __WXMSW__
2674 case 'D':
2675 switch ( lastCount )
2676 {
2677 case 1: // D
2678 case 2: // DD
2679 case 3: // DDD
2680 fmtWX += "%j";
2681 break;
2682
2683 default:
2684 wxFAIL_MSG( "wrong number of 'D's" );
2685 }
2686 break;
2687 case 'w':
2688 switch ( lastCount )
2689 {
2690 case 1: // w
2691 case 2: // ww
2692 fmtWX += "%W";
2693 break;
2694
2695 default:
2696 wxFAIL_MSG( "wrong number of 'w's" );
2697 }
2698 break;
2699 case 'E':
2700 switch ( lastCount )
2701 {
2702 case 1: // E
2703 case 2: // EE
2704 case 3: // EEE
2705 fmtWX += "%a";
2706 break;
2707 case 4: // EEEE
2708 fmtWX += "%A";
2709 break;
2710 case 5: // EEEEE
2711 fmtWX += "%a";
2712 break;
89a7e1ff 2713
47029843
SC
2714 default:
2715 wxFAIL_MSG( "wrong number of 'E's" );
2716 }
2717 break;
2718#endif
89a7e1ff
VZ
2719 case 'M':
2720 switch ( lastCount )
2721 {
2722 case 1: // M
2723 case 2: // MM
2724 // as for 'd' and 'dd' above
2725 fmtWX += "%m";
2726 break;
2727
2728 case 3:
2729 fmtWX += "%b";
2730 break;
2731
2732 case 4:
2733 fmtWX += "%B";
2734 break;
2735
2736 default:
2737 wxFAIL_MSG( "too many 'M's" );
2738 }
2739 break;
2740
2741 case 'y':
2742 switch ( lastCount )
2743 {
2744 case 1: // y
2745 case 2: // yy
2746 fmtWX += "%y";
2747 break;
2748
2749 case 4: // yyyy
2750 fmtWX += "%Y";
2751 break;
2752
2753 default:
2754 wxFAIL_MSG( "wrong number of 'y's" );
2755 }
2756 break;
2757
2758 case 'H':
2759 switch ( lastCount )
2760 {
2761 case 1: // H
2762 case 2: // HH
2763 fmtWX += "%H";
2764 break;
2765
2766 default:
2767 wxFAIL_MSG( "wrong number of 'H's" );
2768 }
2769 break;
2770
2771 case 'h':
2772 switch ( lastCount )
2773 {
2774 case 1: // h
2775 case 2: // hh
756b5a98 2776 fmtWX += "%I";
89a7e1ff
VZ
2777 break;
2778
2779 default:
2780 wxFAIL_MSG( "wrong number of 'h's" );
2781 }
2782 break;
2783
2784 case 'm':
2785 switch ( lastCount )
2786 {
2787 case 1: // m
2788 case 2: // mm
2789 fmtWX += "%M";
2790 break;
2791
2792 default:
2793 wxFAIL_MSG( "wrong number of 'm's" );
2794 }
2795 break;
2796
2797 case 's':
2798 switch ( lastCount )
2799 {
2800 case 1: // s
2801 case 2: // ss
2802 fmtWX += "%S";
2803 break;
2804
2805 default:
2806 wxFAIL_MSG( "wrong number of 's's" );
2807 }
2808 break;
2809
2810 case 'g':
2811 // strftime() doesn't have era string,
2812 // ignore this format
2813 wxASSERT_MSG( lastCount <= 2, "too many 'g's" );
03647350 2814
89a7e1ff 2815 break;
47029843 2816#ifndef __WXMSW__
3e43b647
SC
2817 case 'a':
2818 fmtWX += "%p";
2819 break;
47029843 2820#endif
3e43b647
SC
2821#ifdef __WXMSW__
2822 case 't':
2823 switch ( lastCount )
2824 {
2825 case 1: // t
2826 case 2: // tt
2827 fmtWX += "%p";
2828 break;
2829
2830 default:
2831 wxFAIL_MSG( "too many 't's" );
2832 }
2833 break;
2834#endif
89a7e1ff
VZ
2835 default:
2836 wxFAIL_MSG( "unreachable" );
2837 }
2838
2839 chLast = '\0';
2840 lastCount = 0;
2841 }
2842
2843 if ( p == fmt.end() )
2844 break;
2845
2846 // not a special character so must be just a separator, treat as is
9a83f860 2847 if ( *p == wxT('%') )
89a7e1ff
VZ
2848 {
2849 // this one needs to be escaped
9a83f860 2850 fmtWX += wxT('%');
89a7e1ff
VZ
2851 }
2852
2853 fmtWX += *p;
2854 }
2855
2856 return fmtWX;
2857}
2858
2859} // anonymous namespace
2860
2861#endif // __WXMSW__ || __WXOSX__
2862
dff6cf57 2863#if defined(__WXMSW__)
cfb20656 2864
89a7e1ff
VZ
2865namespace
2866{
2867
2868LCTYPE GetLCTYPEFormatFromLocalInfo(wxLocaleInfo index)
2869{
2870 switch ( index )
2871 {
2872 case wxLOCALE_SHORT_DATE_FMT:
2873 return LOCALE_SSHORTDATE;
2874
2875 case wxLOCALE_LONG_DATE_FMT:
2876 return LOCALE_SLONGDATE;
2877
2878 case wxLOCALE_TIME_FMT:
2879 return LOCALE_STIMEFORMAT;
2880
2881 default:
2882 wxFAIL_MSG( "no matching LCTYPE" );
2883 }
2884
2885 return 0;
2886}
2887
2888} // anonymous namespace
2889
cfb20656 2890/* static */
3fe73755 2891wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory WXUNUSED(cat))
cfb20656 2892{
529e125d 2893 wxUint32 lcid = LOCALE_USER_DEFAULT;
89a7e1ff 2894 if ( wxGetLocale() )
529e125d 2895 {
89a7e1ff
VZ
2896 const wxLanguageInfo * const
2897 info = GetLanguageInfo(wxGetLocale()->GetLanguage());
ea65760d
VZ
2898 if ( info )
2899 lcid = info->GetLCID();
529e125d
JS
2900 }
2901
cfb20656 2902 wxString str;
89a7e1ff
VZ
2903
2904 wxChar buf[256];
2905 buf[0] = wxT('\0');
2906
2907 switch ( index )
cfb20656 2908 {
60d876f3 2909 case wxLOCALE_DECIMAL_POINT:
89a7e1ff
VZ
2910 if ( ::GetLocaleInfo(lcid, LOCALE_SDECIMAL, buf, WXSIZEOF(buf)) )
2911 str = buf;
cfb20656 2912 break;
89a7e1ff
VZ
2913
2914 case wxLOCALE_SHORT_DATE_FMT:
2915 case wxLOCALE_LONG_DATE_FMT:
2916 case wxLOCALE_TIME_FMT:
2917 if ( ::GetLocaleInfo(lcid, GetLCTYPEFormatFromLocalInfo(index),
2918 buf, WXSIZEOF(buf)) )
2919 {
2920 return TranslateFromUnicodeFormat(buf);
2921 }
cfb20656 2922 break;
89a7e1ff
VZ
2923
2924 case wxLOCALE_DATE_TIME_FMT:
2925 // there doesn't seem to be any specific setting for this, so just
2926 // combine date and time ones
cd8a8b45
VZ
2927 //
2928 // we use the short date because this is what "%c" uses by default
2929 // ("%#c" uses long date but we have no way to specify the
2930 // alternate representation here)
89a7e1ff 2931 {
cd8a8b45 2932 const wxString datefmt = GetInfo(wxLOCALE_SHORT_DATE_FMT);
89a7e1ff
VZ
2933 if ( datefmt.empty() )
2934 break;
2935
2936 const wxString timefmt = GetInfo(wxLOCALE_TIME_FMT);
2937 if ( timefmt.empty() )
2938 break;
2939
2940 str << datefmt << ' ' << timefmt;
2941 }
cfb20656 2942 break;
89a7e1ff 2943
cfb20656 2944 default:
89a7e1ff 2945 wxFAIL_MSG( "unknown wxLocaleInfo" );
cfb20656 2946 }
89a7e1ff 2947
cfb20656
VZ
2948 return str;
2949}
2950
89a7e1ff 2951#elif defined(__WXOSX__)
dff6cf57
VZ
2952
2953/* static */
2954wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory WXUNUSED(cat))
2955{
82de050c
VZ
2956 CFLocaleRef userLocaleRefRaw;
2957 if ( wxGetLocale() )
2958 {
2959 userLocaleRefRaw = CFLocaleCreate
ca642c8a 2960 (
82de050c
VZ
2961 kCFAllocatorDefault,
2962 wxCFStringRef(wxGetLocale()->GetCanonicalName())
ca642c8a 2963 );
82de050c
VZ
2964 }
2965 else // no current locale, use the default one
2966 {
2967 userLocaleRefRaw = CFLocaleCopyCurrent();
2968 }
2969
2970 wxCFRef<CFLocaleRef> userLocaleRef(userLocaleRefRaw);
2971
73b51ea4 2972 CFStringRef cfstr = 0;
dff6cf57
VZ
2973 switch ( index )
2974 {
2975 case wxLOCALE_THOUSANDS_SEP:
73b51ea4 2976 cfstr = (CFStringRef) CFLocaleGetValue(userLocaleRef, kCFLocaleGroupingSeparator);
dff6cf57
VZ
2977 break;
2978
2979 case wxLOCALE_DECIMAL_POINT:
73b51ea4 2980 cfstr = (CFStringRef) CFLocaleGetValue(userLocaleRef, kCFLocaleDecimalSeparator);
dff6cf57
VZ
2981 break;
2982
89a7e1ff
VZ
2983 case wxLOCALE_SHORT_DATE_FMT:
2984 case wxLOCALE_LONG_DATE_FMT:
2985 case wxLOCALE_DATE_TIME_FMT:
2986 case wxLOCALE_TIME_FMT:
e9e53eb1
SC
2987 {
2988 CFDateFormatterStyle dateStyle = kCFDateFormatterNoStyle;
2989 CFDateFormatterStyle timeStyle = kCFDateFormatterNoStyle;
2990 switch (index )
2991 {
2992 case wxLOCALE_SHORT_DATE_FMT:
47029843 2993 dateStyle = kCFDateFormatterShortStyle;
e9e53eb1
SC
2994 break;
2995 case wxLOCALE_LONG_DATE_FMT:
9fbcc679 2996 dateStyle = kCFDateFormatterFullStyle;
e9e53eb1
SC
2997 break;
2998 case wxLOCALE_DATE_TIME_FMT:
47029843 2999 dateStyle = kCFDateFormatterFullStyle;
e9e53eb1
SC
3000 timeStyle = kCFDateFormatterMediumStyle;
3001 break;
3002 case wxLOCALE_TIME_FMT:
3003 timeStyle = kCFDateFormatterMediumStyle;
3004 break;
3005 default:
3006 wxFAIL_MSG( "unexpected time locale" );
3007 return wxString();
3008 }
3009 wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
3010 (NULL, userLocaleRef, dateStyle, timeStyle));
3011 wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
47029843
SC
3012 wxString format = TranslateFromUnicodeFormat(cfs.AsString());
3013 // we always want full years
3014 format.Replace("%y","%Y");
3015 return format;
e9e53eb1
SC
3016 }
3017 break;
89a7e1ff 3018
dff6cf57
VZ
3019 default:
3020 wxFAIL_MSG( "Unknown locale info" );
89a7e1ff 3021 return wxString();
dff6cf57
VZ
3022 }
3023
73b51ea4 3024 wxCFStringRef str(wxCFRetain(cfstr));
dff6cf57
VZ
3025 return str.AsString();
3026}
3027
89a7e1ff
VZ
3028#else // !__WXMSW__ && !__WXOSX__, assume generic POSIX
3029
3030namespace
3031{
3032
3033wxString GetDateFormatFromLangInfo(wxLocaleInfo index)
3034{
3035#ifdef HAVE_LANGINFO_H
3036 // array containing parameters for nl_langinfo() indexes by offset of index
3037 // from wxLOCALE_SHORT_DATE_FMT
3038 static const nl_item items[] =
3039 {
3040 D_FMT, D_T_FMT, D_T_FMT, T_FMT,
3041 };
3042
3043 const int nlidx = index - wxLOCALE_SHORT_DATE_FMT;
3044 if ( nlidx < 0 || nlidx >= (int)WXSIZEOF(items) )
3045 {
3046 wxFAIL_MSG( "logic error in GetInfo() code" );
3047 return wxString();
3048 }
3049
3050 const wxString fmt(nl_langinfo(items[nlidx]));
3051
3052 // just return the format returned by nl_langinfo() except for long date
3053 // format which we need to recover from date/time format ourselves (but not
3054 // if we failed completely)
3055 if ( fmt.empty() || index != wxLOCALE_LONG_DATE_FMT )
3056 return fmt;
3057
3058 // this is not 100% precise but the idea is that a typical date/time format
3059 // under POSIX systems is a combination of a long date format with time one
3060 // so we should be able to get just the long date format by removing all
3061 // time-specific format specifiers
3062 static const char *timeFmtSpecs = "HIklMpPrRsSTXzZ";
3063 static const char *timeSep = " :./-";
3064
3065 wxString fmtDateOnly;
3066 const wxString::const_iterator end = fmt.end();
3067 wxString::const_iterator lastSep = end;
3068 for ( wxString::const_iterator p = fmt.begin(); p != end; ++p )
3069 {
3070 if ( strchr(timeSep, *p) )
3071 {
3072 if ( lastSep == end )
3073 lastSep = p;
3074
3075 // skip it for now, we'll discard it if it's followed by a time
3076 // specifier later or add it to fmtDateOnly if it is not
3077 continue;
3078 }
3079
3080 if ( *p == '%' &&
3081 (p + 1 != end) && strchr(timeFmtSpecs, p[1]) )
3082 {
3083 // time specified found: skip it and any preceding separators
3084 ++p;
3085 lastSep = end;
3086 continue;
3087 }
3088
3089 if ( lastSep != end )
3090 {
3091 fmtDateOnly += wxString(lastSep, p);
3092 lastSep = end;
3093 }
3094
3095 fmtDateOnly += *p;
3096 }
3097
3098 return fmtDateOnly;
3099#else // !HAVE_LANGINFO_H
3100 // no fallback, let the application deal with unavailability of
3101 // nl_langinfo() itself as there is no good way for us to do it (well, we
3102 // could try to reverse engineer the format from strftime() output but this
3103 // looks like too much trouble considering the relatively small number of
3104 // systems without nl_langinfo() still in use)
3105 return wxString();
3106#endif // HAVE_LANGINFO_H/!HAVE_LANGINFO_H
3107}
3108
3109} // anonymous namespace
cfb20656
VZ
3110
3111/* static */
60d876f3 3112wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory cat)
cfb20656 3113{
f3342781
VZ
3114 lconv * const lc = localeconv();
3115 if ( !lc )
3116 return wxString();
3117
89a7e1ff 3118 switch ( index )
60d876f3 3119 {
89a7e1ff
VZ
3120 case wxLOCALE_THOUSANDS_SEP:
3121 if ( cat == wxLOCALE_CAT_NUMBER )
3122 return lc->thousands_sep;
3123 else if ( cat == wxLOCALE_CAT_MONEY )
3124 return lc->mon_thousands_sep;
f3342781 3125
89a7e1ff 3126 wxFAIL_MSG( "invalid wxLocaleCategory" );
f3342781
VZ
3127 break;
3128
f3342781 3129
89a7e1ff
VZ
3130 case wxLOCALE_DECIMAL_POINT:
3131 if ( cat == wxLOCALE_CAT_NUMBER )
3132 return lc->decimal_point;
3133 else if ( cat == wxLOCALE_CAT_MONEY )
3134 return lc->mon_decimal_point;
3135
3136 wxFAIL_MSG( "invalid wxLocaleCategory" );
f3342781
VZ
3137 break;
3138
89a7e1ff
VZ
3139 case wxLOCALE_SHORT_DATE_FMT:
3140 case wxLOCALE_LONG_DATE_FMT:
3141 case wxLOCALE_DATE_TIME_FMT:
3142 case wxLOCALE_TIME_FMT:
3143 if ( cat != wxLOCALE_CAT_DATE && cat != wxLOCALE_CAT_DEFAULT )
3144 {
3145 wxFAIL_MSG( "invalid wxLocaleCategory" );
3146 break;
3147 }
3148
3149 return GetDateFormatFromLangInfo(index);
3150
3151
60d876f3 3152 default:
89a7e1ff 3153 wxFAIL_MSG( "unknown wxLocaleInfo value" );
60d876f3 3154 }
f3342781 3155
f3342781 3156 return wxString();
b7b97e77 3157}
cfb20656 3158
dff6cf57 3159#endif // platform
cfb20656 3160
c801d85f
KB
3161// ----------------------------------------------------------------------------
3162// global functions and variables
3163// ----------------------------------------------------------------------------
3164
c801d85f
KB
3165// retrieve/change current locale
3166// ------------------------------
3167
3168// the current locale object
84c18814 3169static wxLocale *g_pLocale = NULL;
c801d85f 3170
1678ad78
GL
3171wxLocale *wxGetLocale()
3172{
ca642c8a 3173 return g_pLocale;
1678ad78
GL
3174}
3175
c801d85f
KB
3176wxLocale *wxSetLocale(wxLocale *pLocale)
3177{
ca642c8a
FM
3178 wxLocale *pOld = g_pLocale;
3179 g_pLocale = pLocale;
3180 return pOld;
c801d85f 3181}
d427503c 3182
41780009
VS
3183
3184
3185// ----------------------------------------------------------------------------
3186// wxLocale module (for lazy destruction of languagesDB)
3187// ----------------------------------------------------------------------------
3188
3189class wxLocaleModule: public wxModule
3190{
3191 DECLARE_DYNAMIC_CLASS(wxLocaleModule)
3192 public:
3193 wxLocaleModule() {}
7beb59f3 3194 bool OnInit() { return true; }
41780009
VS
3195 void OnExit() { wxLocale::DestroyLanguagesDB(); }
3196};
3197
3198IMPLEMENT_DYNAMIC_CLASS(wxLocaleModule, wxModule)
3199
3200
3201
d3f3e35f
VS
3202// ----------------------------------------------------------------------------
3203// default languages table & initialization
3204// ----------------------------------------------------------------------------
3205
865a1730 3206
41780009
VS
3207// --- --- --- generated code begins here --- --- ---
3208
d3f3e35f
VS
3209// This table is generated by misc/languages/genlang.py
3210// When making changes, please put them into misc/languages/langtabl.txt
3211
04ef50df 3212#if !defined(__WIN32__) || defined(__WXMICROWIN__)
63986ba6
VS
3213
3214#define SETWINLANG(info,lang,sublang)
3215
3216#else
3217
d3f3e35f
VS
3218#define SETWINLANG(info,lang,sublang) \
3219 info.WinLang = lang, info.WinSublang = sublang;
63986ba6
VS
3220
3221#ifndef LANG_AFRIKAANS
3222#define LANG_AFRIKAANS (0)
3223#endif
3224#ifndef LANG_ALBANIAN
3225#define LANG_ALBANIAN (0)
3226#endif
3227#ifndef LANG_ARABIC
3228#define LANG_ARABIC (0)
3229#endif
3230#ifndef LANG_ARMENIAN
3231#define LANG_ARMENIAN (0)
3232#endif
3233#ifndef LANG_ASSAMESE
3234#define LANG_ASSAMESE (0)
3235#endif
3236#ifndef LANG_AZERI
3237#define LANG_AZERI (0)
3238#endif
3239#ifndef LANG_BASQUE
3240#define LANG_BASQUE (0)
3241#endif
3242#ifndef LANG_BELARUSIAN
3243#define LANG_BELARUSIAN (0)
3244#endif
3245#ifndef LANG_BENGALI
3246#define LANG_BENGALI (0)
3247#endif
3248#ifndef LANG_BULGARIAN
3249#define LANG_BULGARIAN (0)
3250#endif
3251#ifndef LANG_CATALAN
3252#define LANG_CATALAN (0)
3253#endif
3254#ifndef LANG_CHINESE
3255#define LANG_CHINESE (0)
3256#endif
3257#ifndef LANG_CROATIAN
3258#define LANG_CROATIAN (0)
3259#endif
3260#ifndef LANG_CZECH
3261#define LANG_CZECH (0)
3262#endif
3263#ifndef LANG_DANISH
3264#define LANG_DANISH (0)
3265#endif
3266#ifndef LANG_DUTCH
3267#define LANG_DUTCH (0)
3268#endif
3269#ifndef LANG_ENGLISH
3270#define LANG_ENGLISH (0)
3271#endif
3272#ifndef LANG_ESTONIAN
3273#define LANG_ESTONIAN (0)
3274#endif
3275#ifndef LANG_FAEROESE
3276#define LANG_FAEROESE (0)
3277#endif
3278#ifndef LANG_FARSI
3279#define LANG_FARSI (0)
3280#endif
3281#ifndef LANG_FINNISH
3282#define LANG_FINNISH (0)
3283#endif
3284#ifndef LANG_FRENCH
3285#define LANG_FRENCH (0)
3286#endif
3287#ifndef LANG_GEORGIAN
3288#define LANG_GEORGIAN (0)
3289#endif
3290#ifndef LANG_GERMAN
3291#define LANG_GERMAN (0)
3292#endif
3293#ifndef LANG_GREEK
3294#define LANG_GREEK (0)
3295#endif
3296#ifndef LANG_GUJARATI
3297#define LANG_GUJARATI (0)
3298#endif
3299#ifndef LANG_HEBREW
3300#define LANG_HEBREW (0)
3301#endif
3302#ifndef LANG_HINDI
3303#define LANG_HINDI (0)
3304#endif
3305#ifndef LANG_HUNGARIAN
3306#define LANG_HUNGARIAN (0)
3307#endif
3308#ifndef LANG_ICELANDIC
3309#define LANG_ICELANDIC (0)
3310#endif
3311#ifndef LANG_INDONESIAN
3312#define LANG_INDONESIAN (0)
3313#endif
3314#ifndef LANG_ITALIAN
3315#define LANG_ITALIAN (0)
3316#endif
3317#ifndef LANG_JAPANESE
3318#define LANG_JAPANESE (0)
3319#endif
3320#ifndef LANG_KANNADA
3321#define LANG_KANNADA (0)
3322#endif
3323#ifndef LANG_KASHMIRI
3324#define LANG_KASHMIRI (0)
3325#endif
3326#ifndef LANG_KAZAK
3327#define LANG_KAZAK (0)
3328#endif
3329#ifndef LANG_KONKANI
3330#define LANG_KONKANI (0)
3331#endif
3332#ifndef LANG_KOREAN
3333#define LANG_KOREAN (0)
3334#endif
3335#ifndef LANG_LATVIAN
3336#define LANG_LATVIAN (0)
3337#endif
3338#ifndef LANG_LITHUANIAN
3339#define LANG_LITHUANIAN (0)
3340#endif
3341#ifndef LANG_MACEDONIAN
3342#define LANG_MACEDONIAN (0)
3343#endif
3344#ifndef LANG_MALAY
3345#define LANG_MALAY (0)
3346#endif
3347#ifndef LANG_MALAYALAM
3348#define LANG_MALAYALAM (0)
3349#endif
3350#ifndef LANG_MANIPURI
3351#define LANG_MANIPURI (0)
3352#endif
3353#ifndef LANG_MARATHI
3354#define LANG_MARATHI (0)
3355#endif
3356#ifndef LANG_NEPALI
3357#define LANG_NEPALI (0)
3358#endif
3359#ifndef LANG_NORWEGIAN
3360#define LANG_NORWEGIAN (0)
3361#endif
3362#ifndef LANG_ORIYA
3363#define LANG_ORIYA (0)
3364#endif
3365#ifndef LANG_POLISH
3366#define LANG_POLISH (0)
3367#endif
3368#ifndef LANG_PORTUGUESE
3369#define LANG_PORTUGUESE (0)
3370#endif
3371#ifndef LANG_PUNJABI
3372#define LANG_PUNJABI (0)
3373#endif
3374#ifndef LANG_ROMANIAN
3375#define LANG_ROMANIAN (0)
3376#endif
3377#ifndef LANG_RUSSIAN
3378#define LANG_RUSSIAN (0)
3379#endif
7bf2b088
VZ
3380#ifndef LANG_SAMI
3381#define LANG_SAMI (0)
3382#endif
63986ba6
VS
3383#ifndef LANG_SANSKRIT
3384#define LANG_SANSKRIT (0)
3385#endif
3386#ifndef LANG_SERBIAN
3387#define LANG_SERBIAN (0)
3388#endif
3389#ifndef LANG_SINDHI
3390#define LANG_SINDHI (0)
3391#endif
3392#ifndef LANG_SLOVAK
3393#define LANG_SLOVAK (0)
3394#endif
3395#ifndef LANG_SLOVENIAN
3396#define LANG_SLOVENIAN (0)
3397#endif
3398#ifndef LANG_SPANISH
3399#define LANG_SPANISH (0)
3400#endif
3401#ifndef LANG_SWAHILI
3402#define LANG_SWAHILI (0)
3403#endif
3404#ifndef LANG_SWEDISH
3405#define LANG_SWEDISH (0)
3406#endif
3407#ifndef LANG_TAMIL
3408#define LANG_TAMIL (0)
3409#endif
3410#ifndef LANG_TATAR
3411#define LANG_TATAR (0)
3412#endif
3413#ifndef LANG_TELUGU
3414#define LANG_TELUGU (0)
3415#endif
3416#ifndef LANG_THAI
3417#define LANG_THAI (0)
3418#endif
3419#ifndef LANG_TURKISH
3420#define LANG_TURKISH (0)
3421#endif
3422#ifndef LANG_UKRAINIAN
3423#define LANG_UKRAINIAN (0)
3424#endif
3425#ifndef LANG_URDU
3426#define LANG_URDU (0)
3427#endif
3428#ifndef LANG_UZBEK
3429#define LANG_UZBEK (0)
3430#endif
3431#ifndef LANG_VIETNAMESE
3432#define LANG_VIETNAMESE (0)
3433#endif
3434#ifndef SUBLANG_ARABIC_ALGERIA
3435#define SUBLANG_ARABIC_ALGERIA SUBLANG_DEFAULT
3436#endif
3437#ifndef SUBLANG_ARABIC_BAHRAIN
3438#define SUBLANG_ARABIC_BAHRAIN SUBLANG_DEFAULT
3439#endif
3440#ifndef SUBLANG_ARABIC_EGYPT
3441#define SUBLANG_ARABIC_EGYPT SUBLANG_DEFAULT
3442#endif
3443#ifndef SUBLANG_ARABIC_IRAQ
3444#define SUBLANG_ARABIC_IRAQ SUBLANG_DEFAULT
3445#endif
3446#ifndef SUBLANG_ARABIC_JORDAN
3447#define SUBLANG_ARABIC_JORDAN SUBLANG_DEFAULT
3448#endif
3449#ifndef SUBLANG_ARABIC_KUWAIT
3450#define SUBLANG_ARABIC_KUWAIT SUBLANG_DEFAULT
3451#endif
3452#ifndef SUBLANG_ARABIC_LEBANON
3453#define SUBLANG_ARABIC_LEBANON SUBLANG_DEFAULT
3454#endif
3455#ifndef SUBLANG_ARABIC_LIBYA
3456#define SUBLANG_ARABIC_LIBYA SUBLANG_DEFAULT
3457#endif
3458#ifndef SUBLANG_ARABIC_MOROCCO
3459#define SUBLANG_ARABIC_MOROCCO SUBLANG_DEFAULT
3460#endif
3461#ifndef SUBLANG_ARABIC_OMAN
3462#define SUBLANG_ARABIC_OMAN SUBLANG_DEFAULT
3463#endif
3464#ifndef SUBLANG_ARABIC_QATAR
3465#define SUBLANG_ARABIC_QATAR SUBLANG_DEFAULT
3466#endif
3467#ifndef SUBLANG_ARABIC_SAUDI_ARABIA
3468#define SUBLANG_ARABIC_SAUDI_ARABIA SUBLANG_DEFAULT
3469#endif
3470#ifndef SUBLANG_ARABIC_SYRIA
3471#define SUBLANG_ARABIC_SYRIA SUBLANG_DEFAULT
3472#endif
3473#ifndef SUBLANG_ARABIC_TUNISIA
3474#define SUBLANG_ARABIC_TUNISIA SUBLANG_DEFAULT
3475#endif
3476#ifndef SUBLANG_ARABIC_UAE
3477#define SUBLANG_ARABIC_UAE SUBLANG_DEFAULT
3478#endif
3479#ifndef SUBLANG_ARABIC_YEMEN
3480#define SUBLANG_ARABIC_YEMEN SUBLANG_DEFAULT
3481#endif
3482#ifndef SUBLANG_AZERI_CYRILLIC
3483#define SUBLANG_AZERI_CYRILLIC SUBLANG_DEFAULT
3484#endif
3485#ifndef SUBLANG_AZERI_LATIN
3486#define SUBLANG_AZERI_LATIN SUBLANG_DEFAULT
3487#endif
3488#ifndef SUBLANG_CHINESE_SIMPLIFIED
3489#define SUBLANG_CHINESE_SIMPLIFIED SUBLANG_DEFAULT
3490#endif
3491#ifndef SUBLANG_CHINESE_TRADITIONAL
3492#define SUBLANG_CHINESE_TRADITIONAL SUBLANG_DEFAULT
3493#endif
3494#ifndef SUBLANG_CHINESE_HONGKONG
3495#define SUBLANG_CHINESE_HONGKONG SUBLANG_DEFAULT
3496#endif
3497#ifndef SUBLANG_CHINESE_MACAU
3498#define SUBLANG_CHINESE_MACAU SUBLANG_DEFAULT
3499#endif
3500#ifndef SUBLANG_CHINESE_SINGAPORE
3501#define SUBLANG_CHINESE_SINGAPORE SUBLANG_DEFAULT
3502#endif
3503#ifndef SUBLANG_DUTCH
3504#define SUBLANG_DUTCH SUBLANG_DEFAULT
3505#endif
3506#ifndef SUBLANG_DUTCH_BELGIAN
3507#define SUBLANG_DUTCH_BELGIAN SUBLANG_DEFAULT
3508#endif
3509#ifndef SUBLANG_ENGLISH_UK
3510#define SUBLANG_ENGLISH_UK SUBLANG_DEFAULT
3511#endif
3512#ifndef SUBLANG_ENGLISH_US
3513#define SUBLANG_ENGLISH_US SUBLANG_DEFAULT
3514#endif
3515#ifndef SUBLANG_ENGLISH_AUS
3516#define SUBLANG_ENGLISH_AUS SUBLANG_DEFAULT
3517#endif
3518#ifndef SUBLANG_ENGLISH_BELIZE
3519#define SUBLANG_ENGLISH_BELIZE SUBLANG_DEFAULT
3520#endif
3521#ifndef SUBLANG_ENGLISH_CAN
3522#define SUBLANG_ENGLISH_CAN SUBLANG_DEFAULT
3523#endif
3524#ifndef SUBLANG_ENGLISH_CARIBBEAN
3525#define SUBLANG_ENGLISH_CARIBBEAN SUBLANG_DEFAULT
3526#endif
3527#ifndef SUBLANG_ENGLISH_EIRE
3528#define SUBLANG_ENGLISH_EIRE SUBLANG_DEFAULT
3529#endif
3530#ifndef SUBLANG_ENGLISH_JAMAICA
3531#define SUBLANG_ENGLISH_JAMAICA SUBLANG_DEFAULT
3532#endif
3533#ifndef SUBLANG_ENGLISH_NZ
3534#define SUBLANG_ENGLISH_NZ SUBLANG_DEFAULT
3535#endif
3536#ifndef SUBLANG_ENGLISH_PHILIPPINES
3537#define SUBLANG_ENGLISH_PHILIPPINES SUBLANG_DEFAULT
3538#endif
3539#ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
3540#define SUBLANG_ENGLISH_SOUTH_AFRICA SUBLANG_DEFAULT
3541#endif
3542#ifndef SUBLANG_ENGLISH_TRINIDAD
3543#define SUBLANG_ENGLISH_TRINIDAD SUBLANG_DEFAULT
3544#endif
3545#ifndef SUBLANG_ENGLISH_ZIMBABWE
3546#define SUBLANG_ENGLISH_ZIMBABWE SUBLANG_DEFAULT
3547#endif
3548#ifndef SUBLANG_FRENCH
3549#define SUBLANG_FRENCH SUBLANG_DEFAULT
3550#endif
3551#ifndef SUBLANG_FRENCH_BELGIAN
3552#define SUBLANG_FRENCH_BELGIAN SUBLANG_DEFAULT
3553#endif
3554#ifndef SUBLANG_FRENCH_CANADIAN
3555#define SUBLANG_FRENCH_CANADIAN SUBLANG_DEFAULT
3556#endif
3557#ifndef SUBLANG_FRENCH_LUXEMBOURG
3558#define SUBLANG_FRENCH_LUXEMBOURG SUBLANG_DEFAULT
3559#endif
3560#ifndef SUBLANG_FRENCH_MONACO
3561#define SUBLANG_FRENCH_MONACO SUBLANG_DEFAULT
3562#endif
3563#ifndef SUBLANG_FRENCH_SWISS
3564#define SUBLANG_FRENCH_SWISS SUBLANG_DEFAULT
3565#endif
3566#ifndef SUBLANG_GERMAN
3567#define SUBLANG_GERMAN SUBLANG_DEFAULT
3568#endif
3569#ifndef SUBLANG_GERMAN_AUSTRIAN
3570#define SUBLANG_GERMAN_AUSTRIAN SUBLANG_DEFAULT
3571#endif
3572#ifndef SUBLANG_GERMAN_LIECHTENSTEIN
3573#define SUBLANG_GERMAN_LIECHTENSTEIN SUBLANG_DEFAULT
3574#endif
3575#ifndef SUBLANG_GERMAN_LUXEMBOURG
3576#define SUBLANG_GERMAN_LUXEMBOURG SUBLANG_DEFAULT
3577#endif
3578#ifndef SUBLANG_GERMAN_SWISS
3579#define SUBLANG_GERMAN_SWISS SUBLANG_DEFAULT
3580#endif
3581#ifndef SUBLANG_ITALIAN
3582#define SUBLANG_ITALIAN SUBLANG_DEFAULT
3583#endif
3584#ifndef SUBLANG_ITALIAN_SWISS
3585#define SUBLANG_ITALIAN_SWISS SUBLANG_DEFAULT
3586#endif
3587#ifndef SUBLANG_KASHMIRI_INDIA
3588#define SUBLANG_KASHMIRI_INDIA SUBLANG_DEFAULT
3589#endif
3590#ifndef SUBLANG_KOREAN
3591#define SUBLANG_KOREAN SUBLANG_DEFAULT
3592#endif
3593#ifndef SUBLANG_LITHUANIAN
3594#define SUBLANG_LITHUANIAN SUBLANG_DEFAULT
3595#endif
3596#ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
3597#define SUBLANG_MALAY_BRUNEI_DARUSSALAM SUBLANG_DEFAULT
3598#endif
3599#ifndef SUBLANG_MALAY_MALAYSIA
3600#define SUBLANG_MALAY_MALAYSIA SUBLANG_DEFAULT
3601#endif
3602#ifndef SUBLANG_NEPALI_INDIA
3603#define SUBLANG_NEPALI_INDIA SUBLANG_DEFAULT
3604#endif
3605#ifndef SUBLANG_NORWEGIAN_BOKMAL
3606#define SUBLANG_NORWEGIAN_BOKMAL SUBLANG_DEFAULT
3607#endif
3608#ifndef SUBLANG_NORWEGIAN_NYNORSK
3609#define SUBLANG_NORWEGIAN_NYNORSK SUBLANG_DEFAULT
3610#endif
3611#ifndef SUBLANG_PORTUGUESE
3612#define SUBLANG_PORTUGUESE SUBLANG_DEFAULT
3613#endif
3614#ifndef SUBLANG_PORTUGUESE_BRAZILIAN
3615#define SUBLANG_PORTUGUESE_BRAZILIAN SUBLANG_DEFAULT
3616#endif
3617#ifndef SUBLANG_SERBIAN_CYRILLIC
3618#define SUBLANG_SERBIAN_CYRILLIC SUBLANG_DEFAULT
3619#endif
3620#ifndef SUBLANG_SERBIAN_LATIN
3621#define SUBLANG_SERBIAN_LATIN SUBLANG_DEFAULT
3622#endif
3623#ifndef SUBLANG_SPANISH
3624#define SUBLANG_SPANISH SUBLANG_DEFAULT
3625#endif
3626#ifndef SUBLANG_SPANISH_ARGENTINA
3627#define SUBLANG_SPANISH_ARGENTINA SUBLANG_DEFAULT
3628#endif
3629#ifndef SUBLANG_SPANISH_BOLIVIA
3630#define SUBLANG_SPANISH_BOLIVIA SUBLANG_DEFAULT
3631#endif
3632#ifndef SUBLANG_SPANISH_CHILE
3633#define SUBLANG_SPANISH_CHILE SUBLANG_DEFAULT
3634#endif
3635#ifndef SUBLANG_SPANISH_COLOMBIA
3636#define SUBLANG_SPANISH_COLOMBIA SUBLANG_DEFAULT
3637#endif
3638#ifndef SUBLANG_SPANISH_COSTA_RICA
3639#define SUBLANG_SPANISH_COSTA_RICA SUBLANG_DEFAULT
3640#endif
3641#ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
3642#define SUBLANG_SPANISH_DOMINICAN_REPUBLIC SUBLANG_DEFAULT
3643#endif
3644#ifndef SUBLANG_SPANISH_ECUADOR
3645#define SUBLANG_SPANISH_ECUADOR SUBLANG_DEFAULT
3646#endif
3647#ifndef SUBLANG_SPANISH_EL_SALVADOR
3648#define SUBLANG_SPANISH_EL_SALVADOR SUBLANG_DEFAULT
3649#endif
3650#ifndef SUBLANG_SPANISH_GUATEMALA
3651#define SUBLANG_SPANISH_GUATEMALA SUBLANG_DEFAULT
3652#endif
3653#ifndef SUBLANG_SPANISH_HONDURAS
3654#define SUBLANG_SPANISH_HONDURAS SUBLANG_DEFAULT
3655#endif
3656#ifndef SUBLANG_SPANISH_MEXICAN
3657#define SUBLANG_SPANISH_MEXICAN SUBLANG_DEFAULT
3658#endif
3659#ifndef SUBLANG_SPANISH_MODERN
3660#define SUBLANG_SPANISH_MODERN SUBLANG_DEFAULT
3661#endif
3662#ifndef SUBLANG_SPANISH_NICARAGUA
3663#define SUBLANG_SPANISH_NICARAGUA SUBLANG_DEFAULT
3664#endif
3665#ifndef SUBLANG_SPANISH_PANAMA
3666#define SUBLANG_SPANISH_PANAMA SUBLANG_DEFAULT
3667#endif
3668#ifndef SUBLANG_SPANISH_PARAGUAY
3669#define SUBLANG_SPANISH_PARAGUAY SUBLANG_DEFAULT
3670#endif
3671#ifndef SUBLANG_SPANISH_PERU
3672#define SUBLANG_SPANISH_PERU SUBLANG_DEFAULT
3673#endif
3674#ifndef SUBLANG_SPANISH_PUERTO_RICO
3675#define SUBLANG_SPANISH_PUERTO_RICO SUBLANG_DEFAULT
3676#endif
3677#ifndef SUBLANG_SPANISH_URUGUAY
3678#define SUBLANG_SPANISH_URUGUAY SUBLANG_DEFAULT
3679#endif
3680#ifndef SUBLANG_SPANISH_VENEZUELA
3681#define SUBLANG_SPANISH_VENEZUELA SUBLANG_DEFAULT
3682#endif
3683#ifndef SUBLANG_SWEDISH
3684#define SUBLANG_SWEDISH SUBLANG_DEFAULT
3685#endif
3686#ifndef SUBLANG_SWEDISH_FINLAND
3687#define SUBLANG_SWEDISH_FINLAND SUBLANG_DEFAULT
3688#endif
3689#ifndef SUBLANG_URDU_INDIA
3690#define SUBLANG_URDU_INDIA SUBLANG_DEFAULT
3691#endif
3692#ifndef SUBLANG_URDU_PAKISTAN
3693#define SUBLANG_URDU_PAKISTAN SUBLANG_DEFAULT
3694#endif
3695#ifndef SUBLANG_UZBEK_CYRILLIC
3696#define SUBLANG_UZBEK_CYRILLIC SUBLANG_DEFAULT
3697#endif
3698#ifndef SUBLANG_UZBEK_LATIN
3699#define SUBLANG_UZBEK_LATIN SUBLANG_DEFAULT
d3f3e35f
VS
3700#endif
3701
63986ba6
VS
3702
3703#endif // __WIN32__
3704
978af864 3705#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \
d3f3e35f 3706 info.Language = wxlang; \
86c30bc5 3707 info.CanonicalName = wxT(canonical); \
978af864 3708 info.LayoutDirection = layout; \
86c30bc5 3709 info.Description = wxT(desc); \
d3f3e35f
VS
3710 SETWINLANG(info, winlang, winsublang) \
3711 AddLanguage(info);
3712
3713void wxLocale::InitLanguagesDB()
3714{
86c30bc5
VZ
3715 wxLanguageInfo info;
3716 wxStringTokenizer tkn;
3717
3718 LNG(wxLANGUAGE_ABKHAZIAN, "ab" , 0 , 0 , wxLayout_LeftToRight, "Abkhazian")
3719 LNG(wxLANGUAGE_AFAR, "aa" , 0 , 0 , wxLayout_LeftToRight, "Afar")
3720 LNG(wxLANGUAGE_AFRIKAANS, "af_ZA", LANG_AFRIKAANS , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Afrikaans")
3721 LNG(wxLANGUAGE_ALBANIAN, "sq_AL", LANG_ALBANIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Albanian")
3722 LNG(wxLANGUAGE_AMHARIC, "am" , 0 , 0 , wxLayout_LeftToRight, "Amharic")
3723 LNG(wxLANGUAGE_ARABIC, "ar" , LANG_ARABIC , SUBLANG_DEFAULT , wxLayout_RightToLeft, "Arabic")
3724 LNG(wxLANGUAGE_ARABIC_ALGERIA, "ar_DZ", LANG_ARABIC , SUBLANG_ARABIC_ALGERIA , wxLayout_RightToLeft, "Arabic (Algeria)")
3725 LNG(wxLANGUAGE_ARABIC_BAHRAIN, "ar_BH", LANG_ARABIC , SUBLANG_ARABIC_BAHRAIN , wxLayout_RightToLeft, "Arabic (Bahrain)")
3726 LNG(wxLANGUAGE_ARABIC_EGYPT, "ar_EG", LANG_ARABIC , SUBLANG_ARABIC_EGYPT , wxLayout_RightToLeft, "Arabic (Egypt)")
3727 LNG(wxLANGUAGE_ARABIC_IRAQ, "ar_IQ", LANG_ARABIC , SUBLANG_ARABIC_IRAQ , wxLayout_RightToLeft, "Arabic (Iraq)")
3728 LNG(wxLANGUAGE_ARABIC_JORDAN, "ar_JO", LANG_ARABIC , SUBLANG_ARABIC_JORDAN , wxLayout_RightToLeft, "Arabic (Jordan)")
3729 LNG(wxLANGUAGE_ARABIC_KUWAIT, "ar_KW", LANG_ARABIC , SUBLANG_ARABIC_KUWAIT , wxLayout_RightToLeft, "Arabic (Kuwait)")
3730 LNG(wxLANGUAGE_ARABIC_LEBANON, "ar_LB", LANG_ARABIC , SUBLANG_ARABIC_LEBANON , wxLayout_RightToLeft, "Arabic (Lebanon)")
3731 LNG(wxLANGUAGE_ARABIC_LIBYA, "ar_LY", LANG_ARABIC , SUBLANG_ARABIC_LIBYA , wxLayout_RightToLeft, "Arabic (Libya)")
3732 LNG(wxLANGUAGE_ARABIC_MOROCCO, "ar_MA", LANG_ARABIC , SUBLANG_ARABIC_MOROCCO , wxLayout_RightToLeft, "Arabic (Morocco)")
3733 LNG(wxLANGUAGE_ARABIC_OMAN, "ar_OM", LANG_ARABIC , SUBLANG_ARABIC_OMAN , wxLayout_RightToLeft, "Arabic (Oman)")
3734 LNG(wxLANGUAGE_ARABIC_QATAR, "ar_QA", LANG_ARABIC , SUBLANG_ARABIC_QATAR , wxLayout_RightToLeft, "Arabic (Qatar)")
3735 LNG(wxLANGUAGE_ARABIC_SAUDI_ARABIA, "ar_SA", LANG_ARABIC , SUBLANG_ARABIC_SAUDI_ARABIA , wxLayout_RightToLeft, "Arabic (Saudi Arabia)")
3736 LNG(wxLANGUAGE_ARABIC_SUDAN, "ar_SD", 0 , 0 , wxLayout_RightToLeft, "Arabic (Sudan)")
3737 LNG(wxLANGUAGE_ARABIC_SYRIA, "ar_SY", LANG_ARABIC , SUBLANG_ARABIC_SYRIA , wxLayout_RightToLeft, "Arabic (Syria)")
3738 LNG(wxLANGUAGE_ARABIC_TUNISIA, "ar_TN", LANG_ARABIC , SUBLANG_ARABIC_TUNISIA , wxLayout_RightToLeft, "Arabic (Tunisia)")
3739 LNG(wxLANGUAGE_ARABIC_UAE, "ar_AE", LANG_ARABIC , SUBLANG_ARABIC_UAE , wxLayout_RightToLeft, "Arabic (Uae)")
3740 LNG(wxLANGUAGE_ARABIC_YEMEN, "ar_YE", LANG_ARABIC , SUBLANG_ARABIC_YEMEN , wxLayout_RightToLeft, "Arabic (Yemen)")
3741 LNG(wxLANGUAGE_ARMENIAN, "hy" , LANG_ARMENIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Armenian")
3742 LNG(wxLANGUAGE_ASSAMESE, "as" , LANG_ASSAMESE , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Assamese")
3743 LNG(wxLANGUAGE_ASTURIAN, "ast" , 0 , 0 , wxLayout_LeftToRight, "Asturian")
3744 LNG(wxLANGUAGE_AYMARA, "ay" , 0 , 0 , wxLayout_LeftToRight, "Aymara")
3745 LNG(wxLANGUAGE_AZERI, "az" , LANG_AZERI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Azeri")
3746 LNG(wxLANGUAGE_AZERI_CYRILLIC, "az" , LANG_AZERI , SUBLANG_AZERI_CYRILLIC , wxLayout_LeftToRight, "Azeri (Cyrillic)")
3747 LNG(wxLANGUAGE_AZERI_LATIN, "az" , LANG_AZERI , SUBLANG_AZERI_LATIN , wxLayout_LeftToRight, "Azeri (Latin)")
3748 LNG(wxLANGUAGE_BASHKIR, "ba" , 0 , 0 , wxLayout_LeftToRight, "Bashkir")
3749 LNG(wxLANGUAGE_BASQUE, "eu_ES", LANG_BASQUE , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Basque")
3750 LNG(wxLANGUAGE_BELARUSIAN, "be_BY", LANG_BELARUSIAN, SUBLANG_DEFAULT , wxLayout_LeftToRight, "Belarusian")
3751 LNG(wxLANGUAGE_BENGALI, "bn" , LANG_BENGALI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Bengali")
3752 LNG(wxLANGUAGE_BHUTANI, "dz" , 0 , 0 , wxLayout_LeftToRight, "Bhutani")
3753 LNG(wxLANGUAGE_BIHARI, "bh" , 0 , 0 , wxLayout_LeftToRight, "Bihari")
3754 LNG(wxLANGUAGE_BISLAMA, "bi" , 0 , 0 , wxLayout_LeftToRight, "Bislama")
3755 LNG(wxLANGUAGE_BRETON, "br" , 0 , 0 , wxLayout_LeftToRight, "Breton")
3756 LNG(wxLANGUAGE_BULGARIAN, "bg_BG", LANG_BULGARIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Bulgarian")
3757 LNG(wxLANGUAGE_BURMESE, "my" , 0 , 0 , wxLayout_LeftToRight, "Burmese")
3758 LNG(wxLANGUAGE_CAMBODIAN, "km" , 0 , 0 , wxLayout_LeftToRight, "Cambodian")
3759 LNG(wxLANGUAGE_CATALAN, "ca_ES", LANG_CATALAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Catalan")
3760 LNG(wxLANGUAGE_CHINESE, "zh_TW", LANG_CHINESE , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Chinese")
3761 LNG(wxLANGUAGE_CHINESE_SIMPLIFIED, "zh_CN", LANG_CHINESE , SUBLANG_CHINESE_SIMPLIFIED , wxLayout_LeftToRight, "Chinese (Simplified)")
3762 LNG(wxLANGUAGE_CHINESE_TRADITIONAL, "zh_TW", LANG_CHINESE , SUBLANG_CHINESE_TRADITIONAL , wxLayout_LeftToRight, "Chinese (Traditional)")
3763 LNG(wxLANGUAGE_CHINESE_HONGKONG, "zh_HK", LANG_CHINESE , SUBLANG_CHINESE_HONGKONG , wxLayout_LeftToRight, "Chinese (Hongkong)")
3764 LNG(wxLANGUAGE_CHINESE_MACAU, "zh_MO", LANG_CHINESE , SUBLANG_CHINESE_MACAU , wxLayout_LeftToRight, "Chinese (Macau)")
3765 LNG(wxLANGUAGE_CHINESE_SINGAPORE, "zh_SG", LANG_CHINESE , SUBLANG_CHINESE_SINGAPORE , wxLayout_LeftToRight, "Chinese (Singapore)")
3766 LNG(wxLANGUAGE_CHINESE_TAIWAN, "zh_TW", LANG_CHINESE , SUBLANG_CHINESE_TRADITIONAL , wxLayout_LeftToRight, "Chinese (Taiwan)")
3767 LNG(wxLANGUAGE_CORSICAN, "co" , 0 , 0 , wxLayout_LeftToRight, "Corsican")
3768 LNG(wxLANGUAGE_CROATIAN, "hr_HR", LANG_CROATIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Croatian")
3769 LNG(wxLANGUAGE_CZECH, "cs_CZ", LANG_CZECH , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Czech")
3770 LNG(wxLANGUAGE_DANISH, "da_DK", LANG_DANISH , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Danish")
3771 LNG(wxLANGUAGE_DUTCH, "nl_NL", LANG_DUTCH , SUBLANG_DUTCH , wxLayout_LeftToRight, "Dutch")
3772 LNG(wxLANGUAGE_DUTCH_BELGIAN, "nl_BE", LANG_DUTCH , SUBLANG_DUTCH_BELGIAN , wxLayout_LeftToRight, "Dutch (Belgian)")
3773 LNG(wxLANGUAGE_ENGLISH, "en_GB", LANG_ENGLISH , SUBLANG_ENGLISH_UK , wxLayout_LeftToRight, "English")
3774 LNG(wxLANGUAGE_ENGLISH_UK, "en_GB", LANG_ENGLISH , SUBLANG_ENGLISH_UK , wxLayout_LeftToRight, "English (U.K.)")
3775 LNG(wxLANGUAGE_ENGLISH_US, "en_US", LANG_ENGLISH , SUBLANG_ENGLISH_US , wxLayout_LeftToRight, "English (U.S.)")
3776 LNG(wxLANGUAGE_ENGLISH_AUSTRALIA, "en_AU", LANG_ENGLISH , SUBLANG_ENGLISH_AUS , wxLayout_LeftToRight, "English (Australia)")
3777 LNG(wxLANGUAGE_ENGLISH_BELIZE, "en_BZ", LANG_ENGLISH , SUBLANG_ENGLISH_BELIZE , wxLayout_LeftToRight, "English (Belize)")
3778 LNG(wxLANGUAGE_ENGLISH_BOTSWANA, "en_BW", 0 , 0 , wxLayout_LeftToRight, "English (Botswana)")
3779 LNG(wxLANGUAGE_ENGLISH_CANADA, "en_CA", LANG_ENGLISH , SUBLANG_ENGLISH_CAN , wxLayout_LeftToRight, "English (Canada)")
3780 LNG(wxLANGUAGE_ENGLISH_CARIBBEAN, "en_CB", LANG_ENGLISH , SUBLANG_ENGLISH_CARIBBEAN , wxLayout_LeftToRight, "English (Caribbean)")
3781 LNG(wxLANGUAGE_ENGLISH_DENMARK, "en_DK", 0 , 0 , wxLayout_LeftToRight, "English (Denmark)")
3782 LNG(wxLANGUAGE_ENGLISH_EIRE, "en_IE", LANG_ENGLISH , SUBLANG_ENGLISH_EIRE , wxLayout_LeftToRight, "English (Eire)")
3783 LNG(wxLANGUAGE_ENGLISH_JAMAICA, "en_JM", LANG_ENGLISH , SUBLANG_ENGLISH_JAMAICA , wxLayout_LeftToRight, "English (Jamaica)")
3784 LNG(wxLANGUAGE_ENGLISH_NEW_ZEALAND, "en_NZ", LANG_ENGLISH , SUBLANG_ENGLISH_NZ , wxLayout_LeftToRight, "English (New Zealand)")
3785 LNG(wxLANGUAGE_ENGLISH_PHILIPPINES, "en_PH", LANG_ENGLISH , SUBLANG_ENGLISH_PHILIPPINES , wxLayout_LeftToRight, "English (Philippines)")
3786 LNG(wxLANGUAGE_ENGLISH_SOUTH_AFRICA, "en_ZA", LANG_ENGLISH , SUBLANG_ENGLISH_SOUTH_AFRICA , wxLayout_LeftToRight, "English (South Africa)")
3787 LNG(wxLANGUAGE_ENGLISH_TRINIDAD, "en_TT", LANG_ENGLISH , SUBLANG_ENGLISH_TRINIDAD , wxLayout_LeftToRight, "English (Trinidad)")
3788 LNG(wxLANGUAGE_ENGLISH_ZIMBABWE, "en_ZW", LANG_ENGLISH , SUBLANG_ENGLISH_ZIMBABWE , wxLayout_LeftToRight, "English (Zimbabwe)")
3789 LNG(wxLANGUAGE_ESPERANTO, "eo" , 0 , 0 , wxLayout_LeftToRight, "Esperanto")
3790 LNG(wxLANGUAGE_ESTONIAN, "et_EE", LANG_ESTONIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Estonian")
3791 LNG(wxLANGUAGE_FAEROESE, "fo_FO", LANG_FAEROESE , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Faeroese")
8fbd067d 3792 LNG(wxLANGUAGE_FARSI, "fa_IR", LANG_FARSI , SUBLANG_DEFAULT , wxLayout_RightToLeft, "Farsi")
86c30bc5
VZ
3793 LNG(wxLANGUAGE_FIJI, "fj" , 0 , 0 , wxLayout_LeftToRight, "Fiji")
3794 LNG(wxLANGUAGE_FINNISH, "fi_FI", LANG_FINNISH , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Finnish")
3795 LNG(wxLANGUAGE_FRENCH, "fr_FR", LANG_FRENCH , SUBLANG_FRENCH , wxLayout_LeftToRight, "French")
3796 LNG(wxLANGUAGE_FRENCH_BELGIAN, "fr_BE", LANG_FRENCH , SUBLANG_FRENCH_BELGIAN , wxLayout_LeftToRight, "French (Belgian)")
3797 LNG(wxLANGUAGE_FRENCH_CANADIAN, "fr_CA", LANG_FRENCH , SUBLANG_FRENCH_CANADIAN , wxLayout_LeftToRight, "French (Canadian)")
3798 LNG(wxLANGUAGE_FRENCH_LUXEMBOURG, "fr_LU", LANG_FRENCH , SUBLANG_FRENCH_LUXEMBOURG , wxLayout_LeftToRight, "French (Luxembourg)")
3799 LNG(wxLANGUAGE_FRENCH_MONACO, "fr_MC", LANG_FRENCH , SUBLANG_FRENCH_MONACO , wxLayout_LeftToRight, "French (Monaco)")
3800 LNG(wxLANGUAGE_FRENCH_SWISS, "fr_CH", LANG_FRENCH , SUBLANG_FRENCH_SWISS , wxLayout_LeftToRight, "French (Swiss)")
3801 LNG(wxLANGUAGE_FRISIAN, "fy" , 0 , 0 , wxLayout_LeftToRight, "Frisian")
3802 LNG(wxLANGUAGE_GALICIAN, "gl_ES", 0 , 0 , wxLayout_LeftToRight, "Galician")
3803 LNG(wxLANGUAGE_GEORGIAN, "ka_GE", LANG_GEORGIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Georgian")
3804 LNG(wxLANGUAGE_GERMAN, "de_DE", LANG_GERMAN , SUBLANG_GERMAN , wxLayout_LeftToRight, "German")
3805 LNG(wxLANGUAGE_GERMAN_AUSTRIAN, "de_AT", LANG_GERMAN , SUBLANG_GERMAN_AUSTRIAN , wxLayout_LeftToRight, "German (Austrian)")
3806 LNG(wxLANGUAGE_GERMAN_BELGIUM, "de_BE", 0 , 0 , wxLayout_LeftToRight, "German (Belgium)")
3807 LNG(wxLANGUAGE_GERMAN_LIECHTENSTEIN, "de_LI", LANG_GERMAN , SUBLANG_GERMAN_LIECHTENSTEIN , wxLayout_LeftToRight, "German (Liechtenstein)")
3808 LNG(wxLANGUAGE_GERMAN_LUXEMBOURG, "de_LU", LANG_GERMAN , SUBLANG_GERMAN_LUXEMBOURG , wxLayout_LeftToRight, "German (Luxembourg)")
3809 LNG(wxLANGUAGE_GERMAN_SWISS, "de_CH", LANG_GERMAN , SUBLANG_GERMAN_SWISS , wxLayout_LeftToRight, "German (Swiss)")
3810 LNG(wxLANGUAGE_GREEK, "el_GR", LANG_GREEK , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Greek")
3811 LNG(wxLANGUAGE_GREENLANDIC, "kl_GL", 0 , 0 , wxLayout_LeftToRight, "Greenlandic")
3812 LNG(wxLANGUAGE_GUARANI, "gn" , 0 , 0 , wxLayout_LeftToRight, "Guarani")
3813 LNG(wxLANGUAGE_GUJARATI, "gu" , LANG_GUJARATI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Gujarati")
3814 LNG(wxLANGUAGE_HAUSA, "ha" , 0 , 0 , wxLayout_LeftToRight, "Hausa")
3815 LNG(wxLANGUAGE_HEBREW, "he_IL", LANG_HEBREW , SUBLANG_DEFAULT , wxLayout_RightToLeft, "Hebrew")
3816 LNG(wxLANGUAGE_HINDI, "hi_IN", LANG_HINDI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Hindi")
3817 LNG(wxLANGUAGE_HUNGARIAN, "hu_HU", LANG_HUNGARIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Hungarian")
3818 LNG(wxLANGUAGE_ICELANDIC, "is_IS", LANG_ICELANDIC , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Icelandic")
3819 LNG(wxLANGUAGE_INDONESIAN, "id_ID", LANG_INDONESIAN, SUBLANG_DEFAULT , wxLayout_LeftToRight, "Indonesian")
3820 LNG(wxLANGUAGE_INTERLINGUA, "ia" , 0 , 0 , wxLayout_LeftToRight, "Interlingua")
3821 LNG(wxLANGUAGE_INTERLINGUE, "ie" , 0 , 0 , wxLayout_LeftToRight, "Interlingue")
3822 LNG(wxLANGUAGE_INUKTITUT, "iu" , 0 , 0 , wxLayout_LeftToRight, "Inuktitut")
3823 LNG(wxLANGUAGE_INUPIAK, "ik" , 0 , 0 , wxLayout_LeftToRight, "Inupiak")
3824 LNG(wxLANGUAGE_IRISH, "ga_IE", 0 , 0 , wxLayout_LeftToRight, "Irish")
3825 LNG(wxLANGUAGE_ITALIAN, "it_IT", LANG_ITALIAN , SUBLANG_ITALIAN , wxLayout_LeftToRight, "Italian")
3826 LNG(wxLANGUAGE_ITALIAN_SWISS, "it_CH", LANG_ITALIAN , SUBLANG_ITALIAN_SWISS , wxLayout_LeftToRight, "Italian (Swiss)")
3827 LNG(wxLANGUAGE_JAPANESE, "ja_JP", LANG_JAPANESE , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Japanese")
3828 LNG(wxLANGUAGE_JAVANESE, "jw" , 0 , 0 , wxLayout_LeftToRight, "Javanese")
3829 LNG(wxLANGUAGE_KANNADA, "kn" , LANG_KANNADA , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Kannada")
3830 LNG(wxLANGUAGE_KASHMIRI, "ks" , LANG_KASHMIRI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Kashmiri")
3831 LNG(wxLANGUAGE_KASHMIRI_INDIA, "ks_IN", LANG_KASHMIRI , SUBLANG_KASHMIRI_INDIA , wxLayout_LeftToRight, "Kashmiri (India)")
3832 LNG(wxLANGUAGE_KAZAKH, "kk" , LANG_KAZAK , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Kazakh")
3833 LNG(wxLANGUAGE_KERNEWEK, "kw_GB", 0 , 0 , wxLayout_LeftToRight, "Kernewek")
3834 LNG(wxLANGUAGE_KINYARWANDA, "rw" , 0 , 0 , wxLayout_LeftToRight, "Kinyarwanda")
3835 LNG(wxLANGUAGE_KIRGHIZ, "ky" , 0 , 0 , wxLayout_LeftToRight, "Kirghiz")
3836 LNG(wxLANGUAGE_KIRUNDI, "rn" , 0 , 0 , wxLayout_LeftToRight, "Kirundi")
3837 LNG(wxLANGUAGE_KONKANI, "" , LANG_KONKANI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Konkani")
3838 LNG(wxLANGUAGE_KOREAN, "ko_KR", LANG_KOREAN , SUBLANG_KOREAN , wxLayout_LeftToRight, "Korean")
3839 LNG(wxLANGUAGE_KURDISH, "ku_TR", 0 , 0 , wxLayout_LeftToRight, "Kurdish")
3840 LNG(wxLANGUAGE_LAOTHIAN, "lo" , 0 , 0 , wxLayout_LeftToRight, "Laothian")
3841 LNG(wxLANGUAGE_LATIN, "la" , 0 , 0 , wxLayout_LeftToRight, "Latin")
3842 LNG(wxLANGUAGE_LATVIAN, "lv_LV", LANG_LATVIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Latvian")
3843 LNG(wxLANGUAGE_LINGALA, "ln" , 0 , 0 , wxLayout_LeftToRight, "Lingala")
3844 LNG(wxLANGUAGE_LITHUANIAN, "lt_LT", LANG_LITHUANIAN, SUBLANG_LITHUANIAN , wxLayout_LeftToRight, "Lithuanian")
3845 LNG(wxLANGUAGE_MACEDONIAN, "mk_MK", LANG_MACEDONIAN, SUBLANG_DEFAULT , wxLayout_LeftToRight, "Macedonian")
3846 LNG(wxLANGUAGE_MALAGASY, "mg" , 0 , 0 , wxLayout_LeftToRight, "Malagasy")
3847 LNG(wxLANGUAGE_MALAY, "ms_MY", LANG_MALAY , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Malay")
3848 LNG(wxLANGUAGE_MALAYALAM, "ml" , LANG_MALAYALAM , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Malayalam")
3849 LNG(wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM, "ms_BN", LANG_MALAY , SUBLANG_MALAY_BRUNEI_DARUSSALAM , wxLayout_LeftToRight, "Malay (Brunei Darussalam)")
3850 LNG(wxLANGUAGE_MALAY_MALAYSIA, "ms_MY", LANG_MALAY , SUBLANG_MALAY_MALAYSIA , wxLayout_LeftToRight, "Malay (Malaysia)")
3851 LNG(wxLANGUAGE_MALTESE, "mt_MT", 0 , 0 , wxLayout_LeftToRight, "Maltese")
3852 LNG(wxLANGUAGE_MANIPURI, "" , LANG_MANIPURI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Manipuri")
3853 LNG(wxLANGUAGE_MAORI, "mi" , 0 , 0 , wxLayout_LeftToRight, "Maori")
3854 LNG(wxLANGUAGE_MARATHI, "mr_IN", LANG_MARATHI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Marathi")
3855 LNG(wxLANGUAGE_MOLDAVIAN, "mo" , 0 , 0 , wxLayout_LeftToRight, "Moldavian")
3856 LNG(wxLANGUAGE_MONGOLIAN, "mn" , 0 , 0 , wxLayout_LeftToRight, "Mongolian")
3857 LNG(wxLANGUAGE_NAURU, "na" , 0 , 0 , wxLayout_LeftToRight, "Nauru")
3858 LNG(wxLANGUAGE_NEPALI, "ne_NP", LANG_NEPALI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Nepali")
3859 LNG(wxLANGUAGE_NEPALI_INDIA, "ne_IN", LANG_NEPALI , SUBLANG_NEPALI_INDIA , wxLayout_LeftToRight, "Nepali (India)")
3860 LNG(wxLANGUAGE_NORWEGIAN_BOKMAL, "nb_NO", LANG_NORWEGIAN , SUBLANG_NORWEGIAN_BOKMAL , wxLayout_LeftToRight, "Norwegian (Bokmal)")
3861 LNG(wxLANGUAGE_NORWEGIAN_NYNORSK, "nn_NO", LANG_NORWEGIAN , SUBLANG_NORWEGIAN_NYNORSK , wxLayout_LeftToRight, "Norwegian (Nynorsk)")
3862 LNG(wxLANGUAGE_OCCITAN, "oc" , 0 , 0 , wxLayout_LeftToRight, "Occitan")
3863 LNG(wxLANGUAGE_ORIYA, "or" , LANG_ORIYA , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Oriya")
3864 LNG(wxLANGUAGE_OROMO, "om" , 0 , 0 , wxLayout_LeftToRight, "(Afan) Oromo")
3865 LNG(wxLANGUAGE_PASHTO, "ps" , 0 , 0 , wxLayout_LeftToRight, "Pashto, Pushto")
3866 LNG(wxLANGUAGE_POLISH, "pl_PL", LANG_POLISH , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Polish")
3867 LNG(wxLANGUAGE_PORTUGUESE, "pt_PT", LANG_PORTUGUESE, SUBLANG_PORTUGUESE , wxLayout_LeftToRight, "Portuguese")
3868 LNG(wxLANGUAGE_PORTUGUESE_BRAZILIAN, "pt_BR", LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN , wxLayout_LeftToRight, "Portuguese (Brazilian)")
3869 LNG(wxLANGUAGE_PUNJABI, "pa" , LANG_PUNJABI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Punjabi")
3870 LNG(wxLANGUAGE_QUECHUA, "qu" , 0 , 0 , wxLayout_LeftToRight, "Quechua")
3871 LNG(wxLANGUAGE_RHAETO_ROMANCE, "rm" , 0 , 0 , wxLayout_LeftToRight, "Rhaeto-Romance")
3872 LNG(wxLANGUAGE_ROMANIAN, "ro_RO", LANG_ROMANIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Romanian")
3873 LNG(wxLANGUAGE_RUSSIAN, "ru_RU", LANG_RUSSIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Russian")
3874 LNG(wxLANGUAGE_RUSSIAN_UKRAINE, "ru_UA", 0 , 0 , wxLayout_LeftToRight, "Russian (Ukraine)")
3875 LNG(wxLANGUAGE_SAMI, "se_NO", LANG_SAMI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Northern Sami")
3876 LNG(wxLANGUAGE_SAMOAN, "sm" , 0 , 0 , wxLayout_LeftToRight, "Samoan")
3877 LNG(wxLANGUAGE_SANGHO, "sg" , 0 , 0 , wxLayout_LeftToRight, "Sangho")
3878 LNG(wxLANGUAGE_SANSKRIT, "sa" , LANG_SANSKRIT , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Sanskrit")
3879 LNG(wxLANGUAGE_SCOTS_GAELIC, "gd" , 0 , 0 , wxLayout_LeftToRight, "Scots Gaelic")
3880 LNG(wxLANGUAGE_SERBIAN, "sr_RS", LANG_SERBIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Serbian")
3881 LNG(wxLANGUAGE_SERBIAN_CYRILLIC, "sr_RS", LANG_SERBIAN , SUBLANG_SERBIAN_CYRILLIC , wxLayout_LeftToRight, "Serbian (Cyrillic)")
3882 LNG(wxLANGUAGE_SERBIAN_LATIN, "sr_RS@latin", LANG_SERBIAN , SUBLANG_SERBIAN_LATIN , wxLayout_LeftToRight, "Serbian (Latin)")
3883 LNG(wxLANGUAGE_SERBIAN_CYRILLIC, "sr_YU", LANG_SERBIAN , SUBLANG_SERBIAN_CYRILLIC , wxLayout_LeftToRight, "Serbian (Cyrillic)")
3884 LNG(wxLANGUAGE_SERBIAN_LATIN, "sr_YU@latin", LANG_SERBIAN , SUBLANG_SERBIAN_LATIN , wxLayout_LeftToRight, "Serbian (Latin)")
3885 LNG(wxLANGUAGE_SERBO_CROATIAN, "sh" , 0 , 0 , wxLayout_LeftToRight, "Serbo-Croatian")
3886 LNG(wxLANGUAGE_SESOTHO, "st" , 0 , 0 , wxLayout_LeftToRight, "Sesotho")
3887 LNG(wxLANGUAGE_SETSWANA, "tn" , 0 , 0 , wxLayout_LeftToRight, "Setswana")
3888 LNG(wxLANGUAGE_SHONA, "sn" , 0 , 0 , wxLayout_LeftToRight, "Shona")
3889 LNG(wxLANGUAGE_SINDHI, "sd" , LANG_SINDHI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Sindhi")
3890 LNG(wxLANGUAGE_SINHALESE, "si" , 0 , 0 , wxLayout_LeftToRight, "Sinhalese")
3891 LNG(wxLANGUAGE_SISWATI, "ss" , 0 , 0 , wxLayout_LeftToRight, "Siswati")
3892 LNG(wxLANGUAGE_SLOVAK, "sk_SK", LANG_SLOVAK , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Slovak")
3893 LNG(wxLANGUAGE_SLOVENIAN, "sl_SI", LANG_SLOVENIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Slovenian")
3894 LNG(wxLANGUAGE_SOMALI, "so" , 0 , 0 , wxLayout_LeftToRight, "Somali")
3895 LNG(wxLANGUAGE_SPANISH, "es_ES", LANG_SPANISH , SUBLANG_SPANISH , wxLayout_LeftToRight, "Spanish")
3896 LNG(wxLANGUAGE_SPANISH_ARGENTINA, "es_AR", LANG_SPANISH , SUBLANG_SPANISH_ARGENTINA , wxLayout_LeftToRight, "Spanish (Argentina)")
3897 LNG(wxLANGUAGE_SPANISH_BOLIVIA, "es_BO", LANG_SPANISH , SUBLANG_SPANISH_BOLIVIA , wxLayout_LeftToRight, "Spanish (Bolivia)")
3898 LNG(wxLANGUAGE_SPANISH_CHILE, "es_CL", LANG_SPANISH , SUBLANG_SPANISH_CHILE , wxLayout_LeftToRight, "Spanish (Chile)")
3899 LNG(wxLANGUAGE_SPANISH_COLOMBIA, "es_CO", LANG_SPANISH , SUBLANG_SPANISH_COLOMBIA , wxLayout_LeftToRight, "Spanish (Colombia)")
3900 LNG(wxLANGUAGE_SPANISH_COSTA_RICA, "es_CR", LANG_SPANISH , SUBLANG_SPANISH_COSTA_RICA , wxLayout_LeftToRight, "Spanish (Costa Rica)")
3901 LNG(wxLANGUAGE_SPANISH_DOMINICAN_REPUBLIC, "es_DO", LANG_SPANISH , SUBLANG_SPANISH_DOMINICAN_REPUBLIC, wxLayout_LeftToRight, "Spanish (Dominican republic)")
3902 LNG(wxLANGUAGE_SPANISH_ECUADOR, "es_EC", LANG_SPANISH , SUBLANG_SPANISH_ECUADOR , wxLayout_LeftToRight, "Spanish (Ecuador)")
3903 LNG(wxLANGUAGE_SPANISH_EL_SALVADOR, "es_SV", LANG_SPANISH , SUBLANG_SPANISH_EL_SALVADOR , wxLayout_LeftToRight, "Spanish (El Salvador)")
3904 LNG(wxLANGUAGE_SPANISH_GUATEMALA, "es_GT", LANG_SPANISH , SUBLANG_SPANISH_GUATEMALA , wxLayout_LeftToRight, "Spanish (Guatemala)")
3905 LNG(wxLANGUAGE_SPANISH_HONDURAS, "es_HN", LANG_SPANISH , SUBLANG_SPANISH_HONDURAS , wxLayout_LeftToRight, "Spanish (Honduras)")
3906 LNG(wxLANGUAGE_SPANISH_MEXICAN, "es_MX", LANG_SPANISH , SUBLANG_SPANISH_MEXICAN , wxLayout_LeftToRight, "Spanish (Mexican)")
3907 LNG(wxLANGUAGE_SPANISH_MODERN, "es_ES", LANG_SPANISH , SUBLANG_SPANISH_MODERN , wxLayout_LeftToRight, "Spanish (Modern)")
3908 LNG(wxLANGUAGE_SPANISH_NICARAGUA, "es_NI", LANG_SPANISH , SUBLANG_SPANISH_NICARAGUA , wxLayout_LeftToRight, "Spanish (Nicaragua)")
3909 LNG(wxLANGUAGE_SPANISH_PANAMA, "es_PA", LANG_SPANISH , SUBLANG_SPANISH_PANAMA , wxLayout_LeftToRight, "Spanish (Panama)")
3910 LNG(wxLANGUAGE_SPANISH_PARAGUAY, "es_PY", LANG_SPANISH , SUBLANG_SPANISH_PARAGUAY , wxLayout_LeftToRight, "Spanish (Paraguay)")
3911 LNG(wxLANGUAGE_SPANISH_PERU, "es_PE", LANG_SPANISH , SUBLANG_SPANISH_PERU , wxLayout_LeftToRight, "Spanish (Peru)")
3912 LNG(wxLANGUAGE_SPANISH_PUERTO_RICO, "es_PR", LANG_SPANISH , SUBLANG_SPANISH_PUERTO_RICO , wxLayout_LeftToRight, "Spanish (Puerto Rico)")
3913 LNG(wxLANGUAGE_SPANISH_URUGUAY, "es_UY", LANG_SPANISH , SUBLANG_SPANISH_URUGUAY , wxLayout_LeftToRight, "Spanish (Uruguay)")
3914 LNG(wxLANGUAGE_SPANISH_US, "es_US", 0 , 0 , wxLayout_LeftToRight, "Spanish (U.S.)")
3915 LNG(wxLANGUAGE_SPANISH_VENEZUELA, "es_VE", LANG_SPANISH , SUBLANG_SPANISH_VENEZUELA , wxLayout_LeftToRight, "Spanish (Venezuela)")
3916 LNG(wxLANGUAGE_SUNDANESE, "su" , 0 , 0 , wxLayout_LeftToRight, "Sundanese")
3917 LNG(wxLANGUAGE_SWAHILI, "sw_KE", LANG_SWAHILI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Swahili")
3918 LNG(wxLANGUAGE_SWEDISH, "sv_SE", LANG_SWEDISH , SUBLANG_SWEDISH , wxLayout_LeftToRight, "Swedish")
3919 LNG(wxLANGUAGE_SWEDISH_FINLAND, "sv_FI", LANG_SWEDISH , SUBLANG_SWEDISH_FINLAND , wxLayout_LeftToRight, "Swedish (Finland)")
3920 LNG(wxLANGUAGE_TAGALOG, "tl_PH", 0 , 0 , wxLayout_LeftToRight, "Tagalog")
3921 LNG(wxLANGUAGE_TAJIK, "tg" , 0 , 0 , wxLayout_LeftToRight, "Tajik")
3922 LNG(wxLANGUAGE_TAMIL, "ta" , LANG_TAMIL , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Tamil")
3923 LNG(wxLANGUAGE_TATAR, "tt" , LANG_TATAR , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Tatar")
3924 LNG(wxLANGUAGE_TELUGU, "te" , LANG_TELUGU , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Telugu")
3925 LNG(wxLANGUAGE_THAI, "th_TH", LANG_THAI , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Thai")
3926 LNG(wxLANGUAGE_TIBETAN, "bo" , 0 , 0 , wxLayout_LeftToRight, "Tibetan")
3927 LNG(wxLANGUAGE_TIGRINYA, "ti" , 0 , 0 , wxLayout_LeftToRight, "Tigrinya")
3928 LNG(wxLANGUAGE_TONGA, "to" , 0 , 0 , wxLayout_LeftToRight, "Tonga")
3929 LNG(wxLANGUAGE_TSONGA, "ts" , 0 , 0 , wxLayout_LeftToRight, "Tsonga")
3930 LNG(wxLANGUAGE_TURKISH, "tr_TR", LANG_TURKISH , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Turkish")
3931 LNG(wxLANGUAGE_TURKMEN, "tk" , 0 , 0 , wxLayout_LeftToRight, "Turkmen")
3932 LNG(wxLANGUAGE_TWI, "tw" , 0 , 0 , wxLayout_LeftToRight, "Twi")
3933 LNG(wxLANGUAGE_UIGHUR, "ug" , 0 , 0 , wxLayout_LeftToRight, "Uighur")
3934 LNG(wxLANGUAGE_UKRAINIAN, "uk_UA", LANG_UKRAINIAN , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Ukrainian")
3935 LNG(wxLANGUAGE_URDU, "ur" , LANG_URDU , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Urdu")
3936 LNG(wxLANGUAGE_URDU_INDIA, "ur_IN", LANG_URDU , SUBLANG_URDU_INDIA , wxLayout_LeftToRight, "Urdu (India)")
3937 LNG(wxLANGUAGE_URDU_PAKISTAN, "ur_PK", LANG_URDU , SUBLANG_URDU_PAKISTAN , wxLayout_LeftToRight, "Urdu (Pakistan)")
3938 LNG(wxLANGUAGE_UZBEK, "uz" , LANG_UZBEK , SUBLANG_DEFAULT , wxLayout_LeftToRight, "Uzbek")
3939 LNG(wxLANGUAGE_UZBEK_CYRILLIC, "uz" , LANG_UZBEK , SUBLANG_UZBEK_CYRILLIC , wxLayout_LeftToRight, "Uzbek (Cyrillic)")
3940 LNG(wxLANGUAGE_UZBEK_LATIN, "uz" , LANG_UZBEK , SUBLANG_UZBEK_LATIN , wxLayout_LeftToRight, "Uzbek (Latin)")
3941 LNG(wxLANGUAGE_VALENCIAN, "ca_ES@valencia", 0 , 0 , wxLayout_LeftToRight, "Valencian (Southern Catalan)")
3942 LNG(wxLANGUAGE_VIETNAMESE, "vi_VN", LANG_VIETNAMESE, SUBLANG_DEFAULT , wxLayout_LeftToRight, "Vietnamese")
3943 LNG(wxLANGUAGE_VOLAPUK, "vo" , 0 , 0 , wxLayout_LeftToRight, "Volapuk")
3944 LNG(wxLANGUAGE_WELSH, "cy" , 0 , 0 , wxLayout_LeftToRight, "Welsh")
3945 LNG(wxLANGUAGE_WOLOF, "wo" , 0 , 0 , wxLayout_LeftToRight, "Wolof")
3946 LNG(wxLANGUAGE_XHOSA, "xh" , 0 , 0 , wxLayout_LeftToRight, "Xhosa")
3947 LNG(wxLANGUAGE_YIDDISH, "yi" , 0 , 0 , wxLayout_LeftToRight, "Yiddish")
3948 LNG(wxLANGUAGE_YORUBA, "yo" , 0 , 0 , wxLayout_LeftToRight, "Yoruba")
3949 LNG(wxLANGUAGE_ZHUANG, "za" , 0 , 0 , wxLayout_LeftToRight, "Zhuang")
3950 LNG(wxLANGUAGE_ZULU, "zu" , 0 , 0 , wxLayout_LeftToRight, "Zulu")
3951
4115960d 3952}
d3f3e35f
VS
3953#undef LNG
3954
41780009
VS
3955// --- --- --- generated code ends here --- --- ---
3956
d427503c 3957#endif // wxUSE_INTL