]> git.saurik.com Git - wxWidgets.git/blame - misc/languages/genlang.py
post wxUniv merge fixes
[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()
15 table.append((ispl[0], ispl[1], ispl[2], ispl[3], string.join(ispl[4:])))
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'
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
d3f3e35f
VS
102 f = open('_wxlang.cpp', 'wt')
103 f.write("""
323af196
VS
104// --- --- --- generated code begins here --- --- ---
105
d3f3e35f
VS
106// This table is generated by misc/languages/genlang.py
107// When making changes, please put them into misc/languages/langtabl.txt
108
63986ba6
VS
109#ifndef __WIN32__
110
111#define SETWINLANG(info,lang,sublang)
112
113#else
114
d3f3e35f
VS
115#define SETWINLANG(info,lang,sublang) \\
116 info.WinLang = lang, info.WinSublang = sublang;
63986ba6
VS
117
118%s
119
120#endif // __WIN32__
d3f3e35f
VS
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
129void wxLocale::InitLanguagesDB()
130{
131 wxLanguageInfo info;
132 wxStringTokenizer tkn;
d3f3e35f 133
63986ba6
VS
134 %s
135};
d3f3e35f 136#undef LNG
323af196
VS
137
138// --- --- --- generated code ends here --- --- ---
139
63986ba6 140""" % (ifdefs, lngtable))
d3f3e35f
VS
141 f.close()
142
143
144
145
146
147table = ReadTable()
148GenEnum(table)
149GenTable(table)
3321fc55 150GenDocs(table)