]>
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 | ||
43 | ||
44 | ||
45 | def GenTable(table): | |
46 | f = open('_wxlang.cpp', 'wt') | |
47 | f.write(""" | |
48 | // This table is generated by misc/languages/genlang.py | |
49 | // When making changes, please put them into misc/languages/langtabl.txt | |
50 | ||
51 | #ifdef __WXMSW__ | |
52 | #define SETWINLANG(info,lang,sublang) \\ | |
53 | info.WinLang = lang, info.WinSublang = sublang; | |
54 | #else | |
55 | #define SETWINLANG(info,lang,sublang) | |
56 | #endif | |
57 | ||
58 | #define LNG(wxlang, canonical, winlang, winsublang, desc) \\ | |
59 | info.Language = wxlang; \\ | |
60 | info.CanonicalName = wxT(canonical); \\ | |
61 | info.Description = desc; \\ | |
62 | SETWINLANG(info, winlang, winsublang) \\ | |
63 | AddLanguage(info); | |
64 | ||
65 | void wxLocale::InitLanguagesDB() | |
66 | { | |
67 | wxLanguageInfo info; | |
68 | wxStringTokenizer tkn; | |
69 | ||
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 | f.write(' LNG(%-38s %-7s, %-15s, %-34s, %s)\n' % \ | |
79 | ((i[0]+','), ican, ilang, isublang, i[4])) | |
80 | ||
81 | f.write("""}; | |
82 | #undef LNG | |
83 | """) | |
84 | f.close() | |
85 | ||
86 | ||
87 | ||
88 | ||
89 | ||
90 | table = ReadTable() | |
91 | GenEnum(table) | |
92 | GenTable(table) |