]> git.saurik.com Git - wxWidgets.git/blame - misc/languages/genlang.py
[ 1602455 ] [docs] Fix docs for event used by pickers & collapsiblepane
[wxWidgets.git] / misc / languages / genlang.py
CommitLineData
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
8import string
9
10def ReadTable():
11 table = []
12 f = open('langtabl.txt')
13 for i in f.readlines():
14 ispl = i.split()
978af864 15 table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:])))
d3f3e35f
VS
16 f.close()
17 return table
18
19
20def GenEnum(table):
21 f = open('_wxlang.h', 'wt')
22 f.write("""
323af196
VS
23
24// --- --- --- generated code begins here --- --- ---
25
d3f3e35f
VS
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};
323af196
VS
42
43// --- --- --- generated code ends here --- --- ---
44
d3f3e35f
VS
45""")
46 f.close()
47
48
3321fc55
VS
49def GenDocs(table):
50 f = open('_wxlang.tex', 'wt')
51 f.write("""
323af196
VS
52
53%% --- --- --- generated code begins here --- --- ---
54
3321fc55
VS
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}
323af196
VS
67
68%% --- --- --- generated code ends here --- --- ---
69
3321fc55
VS
70""")
71 f.close()
72
73
d3f3e35f
VS
74
75
76def GenTable(table):
63986ba6
VS
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'
978af864
VZ
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])
63986ba6
VS
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
d3f3e35f
VS
108 f = open('_wxlang.cpp', 'wt')
109 f.write("""
323af196
VS
110// --- --- --- generated code begins here --- --- ---
111
d3f3e35f
VS
112// This table is generated by misc/languages/genlang.py
113// When making changes, please put them into misc/languages/langtabl.txt
114
63986ba6
VS
115#ifndef __WIN32__
116
117#define SETWINLANG(info,lang,sublang)
118
119#else
120
d3f3e35f
VS
121#define SETWINLANG(info,lang,sublang) \\
122 info.WinLang = lang, info.WinSublang = sublang;
63986ba6
VS
123
124%s
125
126#endif // __WIN32__
d3f3e35f 127
978af864 128#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
d3f3e35f
VS
129 info.Language = wxlang; \\
130 info.CanonicalName = wxT(canonical); \\
978af864
VZ
131 info.LayoutDirection = layout; \\
132 info.Description = wxT(desc); \\
d3f3e35f
VS
133 SETWINLANG(info, winlang, winsublang) \\
134 AddLanguage(info);
135
136void wxLocale::InitLanguagesDB()
137{
138 wxLanguageInfo info;
139 wxStringTokenizer tkn;
d3f3e35f 140
63986ba6
VS
141 %s
142};
d3f3e35f 143#undef LNG
323af196
VS
144
145// --- --- --- generated code ends here --- --- ---
146
63986ba6 147""" % (ifdefs, lngtable))
d3f3e35f
VS
148 f.close()
149
150
151
152
153
154table = ReadTable()
155GenEnum(table)
156GenTable(table)
3321fc55 157GenDocs(table)