]> git.saurik.com Git - wxWidgets.git/blame - misc/languages/genlang.py
Disable some wxWebView tests that fail on the buildbot but not locally.
[wxWidgets.git] / misc / languages / genlang.py
CommitLineData
d3f3e35f
VS
1#!/usr/bin/env python
2
741cca6b
VZ
3# Run this script from top-level wxWidgets directory to update the contents of
4# include/wx/intl.h and src/common/intl.cpp using information from langtabl.txt
d3f3e35f 5#
741cca6b
VZ
6# Warning: error detection and reporting here is rudimentary, check if the
7# files were updated correctly with "svn diff" before committing them!
d3f3e35f 8
741cca6b 9import os
d3f3e35f 10import string
741cca6b 11import sys
d3f3e35f
VS
12
13def ReadTable():
14 table = []
741cca6b
VZ
15 try:
16 f = open('misc/languages/langtabl.txt')
17 except:
18 print "Did you run the script from top-level wxWidgets directory?"
19 raise
20
d3f3e35f
VS
21 for i in f.readlines():
22 ispl = i.split()
978af864 23 table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:])))
d3f3e35f
VS
24 f.close()
25 return table
26
27
741cca6b 28def WriteEnum(f, table):
d3f3e35f 29 f.write("""
969daeea
FM
30/**
31 The languages supported by wxLocale.
32
33 This enum is generated by misc/languages/genlang.py
34 When making changes, please put them into misc/languages/langtabl.txt
35*/
d3f3e35f
VS
36enum wxLanguage
37{
969daeea
FM
38 /// User's default/preffered language as got from OS.
39 wxLANGUAGE_DEFAULT,
40
41 /// Unknown language, returned if wxLocale::GetSystemLanguage fails.
42 wxLANGUAGE_UNKNOWN,
43
d3f3e35f 44""");
b5e2a450 45 knownLangs = []
d3f3e35f 46 for i in table:
b5e2a450
VZ
47 if i[0] not in knownLangs:
48 f.write(' %s,\n' % i[0])
49 knownLangs.append(i[0])
d3f3e35f 50 f.write("""
969daeea 51 /// For custom, user-defined languages.
d3f3e35f
VS
52 wxLANGUAGE_USER_DEFINED
53};
323af196 54
d3f3e35f 55""")
d3f3e35f
VS
56
57
741cca6b 58def WriteTable(f, table):
63986ba6
VS
59 all_langs = []
60 all_sublangs = []
969daeea 61
63986ba6 62 lngtable = ''
969daeea
FM
63 ifdefs = ''
64
63986ba6
VS
65 for i in table:
66 ican = '"%s"' % i[1]
67 if ican == '"-"': ican = '""'
68 ilang = i[2]
69 if ilang == '-': ilang = '0'
70 isublang = i[3]
71 if isublang == '-': isublang = '0'
978af864
VZ
72 if (i[4] == "LTR") :
73 ilayout = "wxLayout_LeftToRight"
74 elif (i[4] == "RTL"):
75 ilayout = "wxLayout_RightToLeft"
76 else:
77 print "ERROR: Invalid value for the layout direction";
78 lngtable += ' LNG(%-38s %-7s, %-15s, %-34s, %s, %s)\n' % \
79 ((i[0]+','), ican, ilang, isublang, ilayout, i[5])
63986ba6
VS
80 if ilang not in all_langs: all_langs.append(ilang)
81 if isublang not in all_sublangs: all_sublangs.append(isublang)
82
83 for s in all_langs:
84 if s != '0':
85 ifdefs += '#ifndef %s\n#define %s (0)\n#endif\n' % (s, s)
86 for s in all_sublangs:
969daeea 87 if s != '0' and s != 'SUBLANG_DEFAULT':
63986ba6
VS
88 ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
89
d3f3e35f
VS
90 f.write("""
91// This table is generated by misc/languages/genlang.py
92// When making changes, please put them into misc/languages/langtabl.txt
93
b5e2a450 94#if !defined(__WIN32__) || defined(__WXMICROWIN__)
63986ba6
VS
95
96#define SETWINLANG(info,lang,sublang)
97
98#else
99
d3f3e35f
VS
100#define SETWINLANG(info,lang,sublang) \\
101 info.WinLang = lang, info.WinSublang = sublang;
63986ba6
VS
102
103%s
104
105#endif // __WIN32__
d3f3e35f 106
978af864 107#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
d3f3e35f
VS
108 info.Language = wxlang; \\
109 info.CanonicalName = wxT(canonical); \\
978af864
VZ
110 info.LayoutDirection = layout; \\
111 info.Description = wxT(desc); \\
d3f3e35f
VS
112 SETWINLANG(info, winlang, winsublang) \\
113 AddLanguage(info);
114
115void wxLocale::InitLanguagesDB()
116{
117 wxLanguageInfo info;
d3f3e35f 118
b5e2a450
VZ
119%s
120}
d3f3e35f 121#undef LNG
323af196 122
63986ba6 123""" % (ifdefs, lngtable))
d3f3e35f
VS
124
125
741cca6b
VZ
126def ReplaceGeneratedPartOfFile(fname, func):
127 """
128 Replaces the part of file marked with the special comments with the
129 output of func.
130
131 fname is the name of the input file and func must be a function taking
132 a file and language table on input and writing the appropriate chunk to
133 this file, e.g. WriteEnum or WriteTable.
134 """
135 fin = open(fname, 'rt')
136 fnameNew = fname + '.new'
137 fout = open(fnameNew, 'wt')
138 betweenBeginAndEnd = 0
139 afterEnd = 0
140 for l in fin.readlines():
141 if l == '// --- --- --- generated code begins here --- --- ---\n':
142 if betweenBeginAndEnd or afterEnd:
143 print 'Unexpected starting comment.'
144 betweenBeginAndEnd = 1
145 fout.write(l)
146 func(fout, table)
147 elif l == '// --- --- --- generated code ends here --- --- ---\n':
148 if not betweenBeginAndEnd:
149 print 'End comment found before the starting one?'
150 break
151
152 betweenBeginAndEnd = 0
153 afterEnd = 1
154
155 if not betweenBeginAndEnd:
156 fout.write(l)
157
158 if not afterEnd:
159 print 'Failed to process %s.' % fname
160 os.remove(fnameNew)
161 sys.exit(1)
162
163 os.remove(fname)
164 os.rename(fnameNew, fname)
d3f3e35f
VS
165
166table = ReadTable()
ea144923
VS
167ReplaceGeneratedPartOfFile('include/wx/language.h', WriteEnum)
168ReplaceGeneratedPartOfFile('interface/wx/language.h', WriteEnum)
169ReplaceGeneratedPartOfFile('src/common/languageinfo.cpp', WriteTable)