]>
Commit | Line | Data |
---|---|---|
d3f3e35f VS |
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() | |
978af864 | 15 | table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:]))) |
d3f3e35f VS |
16 | f.close() |
17 | return table | |
18 | ||
19 | ||
20 | def GenEnum(table): | |
21 | f = open('_wxlang.h', 'wt') | |
22 | f.write(""" | |
323af196 VS |
23 | |
24 | // --- --- --- generated code begins here --- --- --- | |
25 | ||
d3f3e35f VS |
26 | // This enum is generated by misc/languages/genlang.py |
27 | // When making changes, please put them into misc/languages/langtabl.txt | |
28 | enum wxLanguage | |
29 | { | |
30 | // user's default/preffered language as got from OS: | |
31 | wxLANGUAGE_DEFAULT, | |
32 | // unknown language, if wxLocale::GetSystemLanguage fails: | |
33 | wxLANGUAGE_UNKNOWN, | |
34 | ||
35 | """); | |
b5e2a450 | 36 | knownLangs = [] |
d3f3e35f | 37 | for i in table: |
b5e2a450 VZ |
38 | if i[0] not in knownLangs: |
39 | f.write(' %s,\n' % i[0]) | |
40 | knownLangs.append(i[0]) | |
d3f3e35f VS |
41 | f.write(""" |
42 | // for custom, user-defined languages: | |
43 | wxLANGUAGE_USER_DEFINED | |
44 | }; | |
323af196 VS |
45 | |
46 | // --- --- --- generated code ends here --- --- --- | |
47 | ||
d3f3e35f VS |
48 | """) |
49 | f.close() | |
50 | ||
51 | ||
3321fc55 VS |
52 | def GenDocs(table): |
53 | f = open('_wxlang.tex', 'wt') | |
54 | f.write(""" | |
323af196 VS |
55 | |
56 | %% --- --- --- generated code begins here --- --- --- | |
57 | ||
3321fc55 VS |
58 | %% This enum is generated by misc/languages/genlang.py |
59 | %% When making changes, please put them into misc/languages/langtabl.txt | |
b5e2a450 VZ |
60 | \\begin{twocollist}\\itemsep=0pt |
61 | \\twocolitem{wxLANGUAGE\\_DEFAULT}{user's default language as obtained from the operating system} | |
62 | \\twocolitem{wxLANGUAGE\\_UNKNOWN}{returned by \\helpref{GetSystemLanguage}{wxlocalegetsystemlanguage} if it fails to detect the default language} | |
63 | \\twocolitem{wxLANGUAGE\\_USER\\_DEFINED}{user defined languages' integer identifiers should start from this} | |
3321fc55 | 64 | """); |
b5e2a450 | 65 | knownLangs = [] |
3321fc55 | 66 | for i in table: |
b5e2a450 VZ |
67 | if i[0] not in knownLangs: |
68 | f.write('\\twocolitem{%s}{}\n' % (i[0].replace('_','\\_'))) | |
69 | knownLangs.append(i[0]) | |
70 | f.write("""\\end{twocollist}\itemsep=0pt | |
323af196 VS |
71 | |
72 | %% --- --- --- generated code ends here --- --- --- | |
73 | ||
3321fc55 VS |
74 | """) |
75 | f.close() | |
76 | ||
77 | ||
d3f3e35f VS |
78 | |
79 | ||
80 | def GenTable(table): | |
63986ba6 VS |
81 | all_langs = [] |
82 | all_sublangs = [] | |
83 | ||
84 | lngtable = '' | |
85 | ifdefs = '' | |
86 | ||
87 | for i in table: | |
88 | ican = '"%s"' % i[1] | |
89 | if ican == '"-"': ican = '""' | |
90 | ilang = i[2] | |
91 | if ilang == '-': ilang = '0' | |
92 | isublang = i[3] | |
93 | if isublang == '-': isublang = '0' | |
978af864 VZ |
94 | if (i[4] == "LTR") : |
95 | ilayout = "wxLayout_LeftToRight" | |
96 | elif (i[4] == "RTL"): | |
97 | ilayout = "wxLayout_RightToLeft" | |
98 | else: | |
99 | print "ERROR: Invalid value for the layout direction"; | |
100 | lngtable += ' LNG(%-38s %-7s, %-15s, %-34s, %s, %s)\n' % \ | |
101 | ((i[0]+','), ican, ilang, isublang, ilayout, i[5]) | |
63986ba6 VS |
102 | if ilang not in all_langs: all_langs.append(ilang) |
103 | if isublang not in all_sublangs: all_sublangs.append(isublang) | |
104 | ||
105 | for s in all_langs: | |
106 | if s != '0': | |
107 | ifdefs += '#ifndef %s\n#define %s (0)\n#endif\n' % (s, s) | |
108 | for s in all_sublangs: | |
109 | if s != '0' and s != 'SUBLANG_DEFAULT': | |
110 | ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s) | |
111 | ||
d3f3e35f VS |
112 | f = open('_wxlang.cpp', 'wt') |
113 | f.write(""" | |
323af196 VS |
114 | // --- --- --- generated code begins here --- --- --- |
115 | ||
d3f3e35f VS |
116 | // This table is generated by misc/languages/genlang.py |
117 | // When making changes, please put them into misc/languages/langtabl.txt | |
118 | ||
b5e2a450 | 119 | #if !defined(__WIN32__) || defined(__WXMICROWIN__) |
63986ba6 VS |
120 | |
121 | #define SETWINLANG(info,lang,sublang) | |
122 | ||
123 | #else | |
124 | ||
d3f3e35f VS |
125 | #define SETWINLANG(info,lang,sublang) \\ |
126 | info.WinLang = lang, info.WinSublang = sublang; | |
63986ba6 VS |
127 | |
128 | %s | |
129 | ||
130 | #endif // __WIN32__ | |
d3f3e35f | 131 | |
978af864 | 132 | #define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\ |
d3f3e35f VS |
133 | info.Language = wxlang; \\ |
134 | info.CanonicalName = wxT(canonical); \\ | |
978af864 VZ |
135 | info.LayoutDirection = layout; \\ |
136 | info.Description = wxT(desc); \\ | |
d3f3e35f VS |
137 | SETWINLANG(info, winlang, winsublang) \\ |
138 | AddLanguage(info); | |
139 | ||
140 | void wxLocale::InitLanguagesDB() | |
141 | { | |
142 | wxLanguageInfo info; | |
143 | wxStringTokenizer tkn; | |
d3f3e35f | 144 | |
b5e2a450 VZ |
145 | %s |
146 | } | |
d3f3e35f | 147 | #undef LNG |
323af196 VS |
148 | |
149 | // --- --- --- generated code ends here --- --- --- | |
150 | ||
63986ba6 | 151 | """ % (ifdefs, lngtable)) |
d3f3e35f VS |
152 | f.close() |
153 | ||
154 | ||
155 | ||
156 | ||
157 | ||
158 | table = ReadTable() | |
159 | GenEnum(table) | |
160 | GenTable(table) | |
3321fc55 | 161 | GenDocs(table) |