]> git.saurik.com Git - wxWidgets.git/blob - misc/languages/genlang.py
added wxICON_NONE and implement support for it in wxGTK (closes #2897)
[wxWidgets.git] / misc / languages / genlang.py
1 #!/usr/bin/env python
2
3 #
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)
8 #
9
10 import string
11
12 def ReadTable():
13 table = []
14 f = open('langtabl.txt')
15 for i in f.readlines():
16 ispl = i.split()
17 table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:])))
18 f.close()
19 return table
20
21
22 def GenEnum(table):
23 f = open('_wxlang.h', 'wt')
24 f.write("""
25
26 // --- --- --- generated code begins here --- --- ---
27
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 */
34 enum wxLanguage
35 {
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
42 """);
43 knownLangs = []
44 for i in table:
45 if i[0] not in knownLangs:
46 f.write(' %s,\n' % i[0])
47 knownLangs.append(i[0])
48 f.write("""
49 /// For custom, user-defined languages.
50 wxLANGUAGE_USER_DEFINED
51 };
52
53 // --- --- --- generated code ends here --- --- ---
54
55 """)
56 f.close()
57
58
59 def GenTable(table):
60 all_langs = []
61 all_sublangs = []
62
63 lngtable = ''
64 ifdefs = ''
65
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'
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])
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:
88 if s != '0' and s != 'SUBLANG_DEFAULT':
89 ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
90
91 f = open('_wxlang.cpp', 'wt')
92 f.write("""
93 // --- --- --- generated code begins here --- --- ---
94
95 // This table is generated by misc/languages/genlang.py
96 // When making changes, please put them into misc/languages/langtabl.txt
97
98 #if !defined(__WIN32__) || defined(__WXMICROWIN__)
99
100 #define SETWINLANG(info,lang,sublang)
101
102 #else
103
104 #define SETWINLANG(info,lang,sublang) \\
105 info.WinLang = lang, info.WinSublang = sublang;
106
107 %s
108
109 #endif // __WIN32__
110
111 #define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
112 info.Language = wxlang; \\
113 info.CanonicalName = wxT(canonical); \\
114 info.LayoutDirection = layout; \\
115 info.Description = wxT(desc); \\
116 SETWINLANG(info, winlang, winsublang) \\
117 AddLanguage(info);
118
119 void wxLocale::InitLanguagesDB()
120 {
121 wxLanguageInfo info;
122 wxStringTokenizer tkn;
123
124 %s
125 }
126 #undef LNG
127
128 // --- --- --- generated code ends here --- --- ---
129
130 """ % (ifdefs, lngtable))
131 f.close()
132
133
134
135
136
137 table = ReadTable()
138 GenEnum(table) # the enum is used also (thanks to doxygen) in the docs
139 GenTable(table)