]>
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): | |
65 | f = open('_wxlang.cpp', 'wt') | |
66 | f.write(""" | |
67 | // This table is generated by misc/languages/genlang.py | |
68 | // When making changes, please put them into misc/languages/langtabl.txt | |
69 | ||
70 | #ifdef __WXMSW__ | |
71 | #define SETWINLANG(info,lang,sublang) \\ | |
72 | info.WinLang = lang, info.WinSublang = sublang; | |
73 | #else | |
74 | #define SETWINLANG(info,lang,sublang) | |
75 | #endif | |
76 | ||
77 | #define LNG(wxlang, canonical, winlang, winsublang, desc) \\ | |
78 | info.Language = wxlang; \\ | |
79 | info.CanonicalName = wxT(canonical); \\ | |
80 | info.Description = desc; \\ | |
81 | SETWINLANG(info, winlang, winsublang) \\ | |
82 | AddLanguage(info); | |
83 | ||
84 | void wxLocale::InitLanguagesDB() | |
85 | { | |
86 | wxLanguageInfo info; | |
87 | wxStringTokenizer tkn; | |
88 | ||
89 | """); | |
90 | for i in table: | |
91 | ican = '"%s"' % i[1] | |
92 | if ican == '"-"': ican = '""' | |
93 | ilang = i[2] | |
94 | if ilang == '-': ilang = '0' | |
95 | isublang = i[3] | |
96 | if isublang == '-': isublang = '0' | |
97 | f.write(' LNG(%-38s %-7s, %-15s, %-34s, %s)\n' % \ | |
98 | ((i[0]+','), ican, ilang, isublang, i[4])) | |
99 | ||
100 | f.write("""}; | |
101 | #undef LNG | |
102 | """) | |
103 | f.close() | |
104 | ||
105 | ||
106 | ||
107 | ||
108 | ||
109 | table = ReadTable() | |
110 | GenEnum(table) | |
111 | GenTable(table) | |
3321fc55 | 112 | GenDocs(table) |