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