]> git.saurik.com Git - wxWidgets.git/blame_incremental - misc/languages/genlang.py
probable typo
[wxWidgets.git] / misc / languages / genlang.py
... / ...
CommitLineData
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
8import string
9
10def 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
20def 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
28enum 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
49def 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}
60if it fails to detect the default language
61\\item wxLANGUAGE_USER_DEFINED -- user defined languages' integer identifiers should start from
62this
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
76def 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 if (i[4] == "LTR") :
91 ilayout = "wxLayout_LeftToRight"
92 elif (i[4] == "RTL"):
93 ilayout = "wxLayout_RightToLeft"
94 else:
95 print "ERROR: Invalid value for the layout direction";
96 lngtable += ' LNG(%-38s %-7s, %-15s, %-34s, %s, %s)\n' % \
97 ((i[0]+','), ican, ilang, isublang, ilayout, i[5])
98 if ilang not in all_langs: all_langs.append(ilang)
99 if isublang not in all_sublangs: all_sublangs.append(isublang)
100
101 for s in all_langs:
102 if s != '0':
103 ifdefs += '#ifndef %s\n#define %s (0)\n#endif\n' % (s, s)
104 for s in all_sublangs:
105 if s != '0' and s != 'SUBLANG_DEFAULT':
106 ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
107
108 f = open('_wxlang.cpp', 'wt')
109 f.write("""
110// --- --- --- generated code begins here --- --- ---
111
112// This table is generated by misc/languages/genlang.py
113// When making changes, please put them into misc/languages/langtabl.txt
114
115#ifndef __WIN32__
116
117#define SETWINLANG(info,lang,sublang)
118
119#else
120
121#define SETWINLANG(info,lang,sublang) \\
122 info.WinLang = lang, info.WinSublang = sublang;
123
124%s
125
126#endif // __WIN32__
127
128#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
129 info.Language = wxlang; \\
130 info.CanonicalName = wxT(canonical); \\
131 info.LayoutDirection = layout; \\
132 info.Description = wxT(desc); \\
133 SETWINLANG(info, winlang, winsublang) \\
134 AddLanguage(info);
135
136void wxLocale::InitLanguagesDB()
137{
138 wxLanguageInfo info;
139 wxStringTokenizer tkn;
140
141 %s
142};
143#undef LNG
144
145// --- --- --- generated code ends here --- --- ---
146
147""" % (ifdefs, lngtable))
148 f.close()
149
150
151
152
153
154table = ReadTable()
155GenEnum(table)
156GenTable(table)
157GenDocs(table)