]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | ||
3 | # | |
4 | # Generates wxLanguage enum (to be cut&pasted to include/wx/intl.h) | |
5 | # and convertion tables (ditto to src/common/intl.cpp) | |
6 | # | |
7 | ||
8 | import string | |
9 | ||
10 | def ReadTable(): | |
11 | table = [] | |
12 | f = open('langtabl.txt') | |
13 | for i in f.readlines(): | |
14 | ispl = i.split() | |
15 | table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:]))) | |
16 | f.close() | |
17 | return table | |
18 | ||
19 | ||
20 | def GenEnum(table): | |
21 | f = open('_wxlang.h', 'wt') | |
22 | f.write(""" | |
23 | ||
24 | // --- --- --- generated code begins here --- --- --- | |
25 | ||
26 | /** | |
27 | The languages supported by wxLocale. | |
28 | ||
29 | This enum is generated by misc/languages/genlang.py | |
30 | When making changes, please put them into misc/languages/langtabl.txt | |
31 | */ | |
32 | enum wxLanguage | |
33 | { | |
34 | /// User's default/preffered language as got from OS. | |
35 | wxLANGUAGE_DEFAULT, | |
36 | ||
37 | /// Unknown language, returned if wxLocale::GetSystemLanguage fails. | |
38 | wxLANGUAGE_UNKNOWN, | |
39 | ||
40 | """); | |
41 | knownLangs = [] | |
42 | for i in table: | |
43 | if i[0] not in knownLangs: | |
44 | f.write(' %s,\n' % i[0]) | |
45 | knownLangs.append(i[0]) | |
46 | f.write(""" | |
47 | /// For custom, user-defined languages. | |
48 | wxLANGUAGE_USER_DEFINED | |
49 | }; | |
50 | ||
51 | // --- --- --- generated code ends here --- --- --- | |
52 | ||
53 | """) | |
54 | f.close() | |
55 | ||
56 | ||
57 | def GenTable(table): | |
58 | all_langs = [] | |
59 | all_sublangs = [] | |
60 | ||
61 | lngtable = '' | |
62 | ifdefs = '' | |
63 | ||
64 | for i in table: | |
65 | ican = '"%s"' % i[1] | |
66 | if ican == '"-"': ican = '""' | |
67 | ilang = i[2] | |
68 | if ilang == '-': ilang = '0' | |
69 | isublang = i[3] | |
70 | if isublang == '-': isublang = '0' | |
71 | if (i[4] == "LTR") : | |
72 | ilayout = "wxLayout_LeftToRight" | |
73 | elif (i[4] == "RTL"): | |
74 | ilayout = "wxLayout_RightToLeft" | |
75 | else: | |
76 | print "ERROR: Invalid value for the layout direction"; | |
77 | lngtable += ' LNG(%-38s %-7s, %-15s, %-34s, %s, %s)\n' % \ | |
78 | ((i[0]+','), ican, ilang, isublang, ilayout, i[5]) | |
79 | if ilang not in all_langs: all_langs.append(ilang) | |
80 | if isublang not in all_sublangs: all_sublangs.append(isublang) | |
81 | ||
82 | for s in all_langs: | |
83 | if s != '0': | |
84 | ifdefs += '#ifndef %s\n#define %s (0)\n#endif\n' % (s, s) | |
85 | for s in all_sublangs: | |
86 | if s != '0' and s != 'SUBLANG_DEFAULT': | |
87 | ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s) | |
88 | ||
89 | f = open('_wxlang.cpp', 'wt') | |
90 | f.write(""" | |
91 | // --- --- --- generated code begins here --- --- --- | |
92 | ||
93 | // This table is generated by misc/languages/genlang.py | |
94 | // When making changes, please put them into misc/languages/langtabl.txt | |
95 | ||
96 | #if !defined(__WIN32__) || defined(__WXMICROWIN__) | |
97 | ||
98 | #define SETWINLANG(info,lang,sublang) | |
99 | ||
100 | #else | |
101 | ||
102 | #define SETWINLANG(info,lang,sublang) \\ | |
103 | info.WinLang = lang, info.WinSublang = sublang; | |
104 | ||
105 | %s | |
106 | ||
107 | #endif // __WIN32__ | |
108 | ||
109 | #define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\ | |
110 | info.Language = wxlang; \\ | |
111 | info.CanonicalName = wxT(canonical); \\ | |
112 | info.LayoutDirection = layout; \\ | |
113 | info.Description = wxT(desc); \\ | |
114 | SETWINLANG(info, winlang, winsublang) \\ | |
115 | AddLanguage(info); | |
116 | ||
117 | void wxLocale::InitLanguagesDB() | |
118 | { | |
119 | wxLanguageInfo info; | |
120 | wxStringTokenizer tkn; | |
121 | ||
122 | %s | |
123 | } | |
124 | #undef LNG | |
125 | ||
126 | // --- --- --- generated code ends here --- --- --- | |
127 | ||
128 | """ % (ifdefs, lngtable)) | |
129 | f.close() | |
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | table = ReadTable() | |
136 | GenEnum(table) # the enum is used also (thanks to doxygen) in the docs | |
137 | GenTable(table) |