]> git.saurik.com Git - wxWidgets.git/blob - misc/languages/genlang.py
Script updates
[wxWidgets.git] / misc / languages / genlang.py
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
24 // --- --- --- generated code begins here --- --- ---
25
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 """);
36 for i in table:
37 f.write(' %s,\n' % i[0])
38 f.write("""
39 // for custom, user-defined languages:
40 wxLANGUAGE_USER_DEFINED
41 };
42
43 // --- --- --- generated code ends here --- --- ---
44
45 """)
46 f.close()
47
48
49 def GenDocs(table):
50 f = open('_wxlang.tex', 'wt')
51 f.write("""
52
53 %% --- --- --- generated code begins here --- --- ---
54
55 %% This enum is generated by misc/languages/genlang.py
56 %% When making changes, please put them into misc/languages/langtabl.txt
57 \\begin{itemize}\\itemsep=0pt
58 \\item wxLANGUAGE_DEFAULT -- user's default language as obtained from the operating system
59 \\item wxLANGUAGE_UNKNOWN -- returned by \\helpref{GetSystemLanguage}{wxlocalegetsystemlanguage}
60 if it fails to detect the default language
61 \\item wxLANGUAGE_USER_DEFINED -- user defined languages' integer identifiers should start from
62 this
63 """);
64 for i in table:
65 f.write('\\item %s\n' % (i[0].replace('_','\\_')))
66 f.write("""\\end{itemize}
67
68 %% --- --- --- generated code ends here --- --- ---
69
70 """)
71 f.close()
72
73
74
75
76 def GenTable(table):
77 all_langs = []
78 all_sublangs = []
79
80 lngtable = ''
81 ifdefs = ''
82
83 for i in table:
84 ican = '"%s"' % i[1]
85 if ican == '"-"': ican = '""'
86 ilang = i[2]
87 if ilang == '-': ilang = '0'
88 isublang = i[3]
89 if isublang == '-': isublang = '0'
90 lngtable += ' LNG(%-38s %-7s, %-15s, %-34s, %s)\n' % \
91 ((i[0]+','), ican, ilang, isublang, i[4])
92 if ilang not in all_langs: all_langs.append(ilang)
93 if isublang not in all_sublangs: all_sublangs.append(isublang)
94
95 for s in all_langs:
96 if s != '0':
97 ifdefs += '#ifndef %s\n#define %s (0)\n#endif\n' % (s, s)
98 for s in all_sublangs:
99 if s != '0' and s != 'SUBLANG_DEFAULT':
100 ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
101
102 f = open('_wxlang.cpp', 'wt')
103 f.write("""
104 // --- --- --- generated code begins here --- --- ---
105
106 // This table is generated by misc/languages/genlang.py
107 // When making changes, please put them into misc/languages/langtabl.txt
108
109 #ifndef __WIN32__
110
111 #define SETWINLANG(info,lang,sublang)
112
113 #else
114
115 #define SETWINLANG(info,lang,sublang) \\
116 info.WinLang = lang, info.WinSublang = sublang;
117
118 %s
119
120 #endif // __WIN32__
121
122 #define LNG(wxlang, canonical, winlang, winsublang, desc) \\
123 info.Language = wxlang; \\
124 info.CanonicalName = wxT(canonical); \\
125 info.Description = desc; \\
126 SETWINLANG(info, winlang, winsublang) \\
127 AddLanguage(info);
128
129 void wxLocale::InitLanguagesDB()
130 {
131 wxLanguageInfo info;
132 wxStringTokenizer tkn;
133
134 %s
135 };
136 #undef LNG
137
138 // --- --- --- generated code ends here --- --- ---
139
140 """ % (ifdefs, lngtable))
141 f.close()
142
143
144
145
146
147 table = ReadTable()
148 GenEnum(table)
149 GenTable(table)
150 GenDocs(table)