]> git.saurik.com Git - wxWidgets.git/blob - misc/languages/genlang.py
Minor clarification
[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], ispl[4], string.join(ispl[5:])))
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 knownLangs = []
37 for i in table:
38 if i[0] not in knownLangs:
39 f.write(' %s,\n' % i[0])
40 knownLangs.append(i[0])
41 f.write("""
42 // for custom, user-defined languages:
43 wxLANGUAGE_USER_DEFINED
44 };
45
46 // --- --- --- generated code ends here --- --- ---
47
48 """)
49 f.close()
50
51
52 def GenDocs(table):
53 f = open('_wxlang.tex', 'wt')
54 f.write("""
55
56 %% --- --- --- generated code begins here --- --- ---
57
58 %% This enum is generated by misc/languages/genlang.py
59 %% When making changes, please put them into misc/languages/langtabl.txt
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}
64 """);
65 knownLangs = []
66 for i in table:
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
71
72 %% --- --- --- generated code ends here --- --- ---
73
74 """)
75 f.close()
76
77
78
79
80 def GenTable(table):
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'
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])
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
112 f = open('_wxlang.cpp', 'wt')
113 f.write("""
114 // --- --- --- generated code begins here --- --- ---
115
116 // This table is generated by misc/languages/genlang.py
117 // When making changes, please put them into misc/languages/langtabl.txt
118
119 #if !defined(__WIN32__) || defined(__WXMICROWIN__)
120
121 #define SETWINLANG(info,lang,sublang)
122
123 #else
124
125 #define SETWINLANG(info,lang,sublang) \\
126 info.WinLang = lang, info.WinSublang = sublang;
127
128 %s
129
130 #endif // __WIN32__
131
132 #define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
133 info.Language = wxlang; \\
134 info.CanonicalName = wxT(canonical); \\
135 info.LayoutDirection = layout; \\
136 info.Description = wxT(desc); \\
137 SETWINLANG(info, winlang, winsublang) \\
138 AddLanguage(info);
139
140 void wxLocale::InitLanguagesDB()
141 {
142 wxLanguageInfo info;
143 wxStringTokenizer tkn;
144
145 %s
146 }
147 #undef LNG
148
149 // --- --- --- generated code ends here --- --- ---
150
151 """ % (ifdefs, lngtable))
152 f.close()
153
154
155
156
157
158 table = ReadTable()
159 GenEnum(table)
160 GenTable(table)
161 GenDocs(table)