]>
git.saurik.com Git - wxWidgets.git/blob - misc/languages/genlang.py
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
6 # Warning: error detection and reporting here is rudimentary, check if the
7 # files were updated correctly with "svn diff" before committing them!
16 f
= open('misc/languages/langtabl.txt')
18 print "Did you run the script from top-level wxWidgets directory?"
21 for i
in f
.readlines():
23 table
.append((ispl
[0], ispl
[1], ispl
[2], ispl
[3], ispl
[4], string
.join(ispl
[5:])))
28 def WriteEnum(f
, table
):
31 The languages supported by wxLocale.
33 This enum is generated by misc/languages/genlang.py
34 When making changes, please put them into misc/languages/langtabl.txt
38 /// User's default/preffered language as got from OS.
41 /// Unknown language, returned if wxLocale::GetSystemLanguage fails.
47 if i
[0] not in knownLangs
:
48 f
.write(' %s,\n' % i
[0])
49 knownLangs
.append(i
[0])
51 /// For custom, user-defined languages.
52 wxLANGUAGE_USER_DEFINED
58 def WriteTable(f
, table
):
67 if ican
== '"-"': ican
= '""'
69 if ilang
== '-': ilang
= '0'
71 if isublang
== '-': isublang
= '0'
73 ilayout
= "wxLayout_LeftToRight"
75 ilayout
= "wxLayout_RightToLeft"
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])
80 if ilang
not in all_langs
: all_langs
.append(ilang
)
81 if isublang
not in all_sublangs
: all_sublangs
.append(isublang
)
85 ifdefs
+= '#ifndef %s\n#define %s (0)\n#endif\n' % (s
, s
)
86 for s
in all_sublangs
:
87 if s
!= '0' and s
!= 'SUBLANG_DEFAULT':
88 ifdefs
+= '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s
, s
)
91 // This table is generated by misc/languages/genlang.py
92 // When making changes, please put them into misc/languages/langtabl.txt
94 #if !defined(__WIN32__) || defined(__WXMICROWIN__)
96 #define SETWINLANG(info,lang,sublang)
100 #define SETWINLANG(info,lang,sublang) \\
101 info.WinLang = lang, info.WinSublang = sublang;
107 #define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
108 info.Language = wxlang; \\
109 info.CanonicalName = wxT(canonical); \\
110 info.LayoutDirection = layout; \\
111 info.Description = wxT(desc); \\
112 SETWINLANG(info, winlang, winsublang) \\
115 void wxLocale::InitLanguagesDB()
123 """ % (ifdefs
, lngtable
))
126 def ReplaceGeneratedPartOfFile(fname
, func
):
128 Replaces the part of file marked with the special comments with the
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.
135 fin
= open(fname
, 'rt')
136 fnameNew
= fname
+ '.new'
137 fout
= open(fnameNew
, 'wt')
138 betweenBeginAndEnd
= 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
147 elif l
== '// --- --- --- generated code ends here --- --- ---\n':
148 if not betweenBeginAndEnd
:
149 print 'End comment found before the starting one?'
152 betweenBeginAndEnd
= 0
155 if not betweenBeginAndEnd
:
159 print 'Failed to process %s.' % fname
164 os
.rename(fnameNew
, fname
)
167 ReplaceGeneratedPartOfFile('include/wx/language.h', WriteEnum
)
168 ReplaceGeneratedPartOfFile('interface/wx/language.h', WriteEnum
)
169 ReplaceGeneratedPartOfFile('src/common/languageinfo.cpp', WriteTable
)