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