]> git.saurik.com Git - wxWidgets.git/blame - misc/languages/genlang.py
Ticket #10108 (bitmap from wxImage depth regression)
[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
969daeea
FM
26/**
27 The languages supported by wxLocale.
28
29 This enum is generated by misc/languages/genlang.py
30 When making changes, please put them into misc/languages/langtabl.txt
31*/
d3f3e35f
VS
32enum wxLanguage
33{
969daeea
FM
34 /// User's default/preffered language as got from OS.
35 wxLANGUAGE_DEFAULT,
36
37 /// Unknown language, returned if wxLocale::GetSystemLanguage fails.
38 wxLANGUAGE_UNKNOWN,
39
d3f3e35f 40""");
b5e2a450 41 knownLangs = []
d3f3e35f 42 for i in table:
b5e2a450
VZ
43 if i[0] not in knownLangs:
44 f.write(' %s,\n' % i[0])
45 knownLangs.append(i[0])
d3f3e35f 46 f.write("""
969daeea 47 /// For custom, user-defined languages.
d3f3e35f
VS
48 wxLANGUAGE_USER_DEFINED
49};
323af196
VS
50
51// --- --- --- generated code ends here --- --- ---
52
d3f3e35f
VS
53""")
54 f.close()
55
56
d3f3e35f 57def GenTable(table):
63986ba6
VS
58 all_langs = []
59 all_sublangs = []
969daeea 60
63986ba6 61 lngtable = ''
969daeea
FM
62 ifdefs = ''
63
63986ba6
VS
64 for i in table:
65 ican = '"%s"' % i[1]
66 if ican == '"-"': ican = '""'
67 ilang = i[2]
68 if ilang == '-': ilang = '0'
69 isublang = i[3]
70 if isublang == '-': isublang = '0'
978af864
VZ
71 if (i[4] == "LTR") :
72 ilayout = "wxLayout_LeftToRight"
73 elif (i[4] == "RTL"):
74 ilayout = "wxLayout_RightToLeft"
75 else:
76 print "ERROR: Invalid value for the layout direction";
77 lngtable += ' LNG(%-38s %-7s, %-15s, %-34s, %s, %s)\n' % \
78 ((i[0]+','), ican, ilang, isublang, ilayout, i[5])
63986ba6
VS
79 if ilang not in all_langs: all_langs.append(ilang)
80 if isublang not in all_sublangs: all_sublangs.append(isublang)
81
82 for s in all_langs:
83 if s != '0':
84 ifdefs += '#ifndef %s\n#define %s (0)\n#endif\n' % (s, s)
85 for s in all_sublangs:
969daeea 86 if s != '0' and s != 'SUBLANG_DEFAULT':
63986ba6
VS
87 ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
88
d3f3e35f
VS
89 f = open('_wxlang.cpp', 'wt')
90 f.write("""
323af196
VS
91// --- --- --- generated code begins here --- --- ---
92
d3f3e35f
VS
93// This table is generated by misc/languages/genlang.py
94// When making changes, please put them into misc/languages/langtabl.txt
95
b5e2a450 96#if !defined(__WIN32__) || defined(__WXMICROWIN__)
63986ba6
VS
97
98#define SETWINLANG(info,lang,sublang)
99
100#else
101
d3f3e35f
VS
102#define SETWINLANG(info,lang,sublang) \\
103 info.WinLang = lang, info.WinSublang = sublang;
63986ba6
VS
104
105%s
106
107#endif // __WIN32__
d3f3e35f 108
978af864 109#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
d3f3e35f
VS
110 info.Language = wxlang; \\
111 info.CanonicalName = wxT(canonical); \\
978af864
VZ
112 info.LayoutDirection = layout; \\
113 info.Description = wxT(desc); \\
d3f3e35f
VS
114 SETWINLANG(info, winlang, winsublang) \\
115 AddLanguage(info);
116
117void wxLocale::InitLanguagesDB()
118{
119 wxLanguageInfo info;
120 wxStringTokenizer tkn;
d3f3e35f 121
b5e2a450
VZ
122%s
123}
d3f3e35f 124#undef LNG
323af196
VS
125
126// --- --- --- generated code ends here --- --- ---
127
63986ba6 128""" % (ifdefs, lngtable))
d3f3e35f
VS
129 f.close()
130
131
132
133
134
135table = ReadTable()
969daeea 136GenEnum(table) # the enum is used also (thanks to doxygen) in the docs
d3f3e35f 137GenTable(table)