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