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