update the intl.* files directly from genlang.py script instead of generating snippets which had then to be manually pasted in
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61342 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Run this script from top-level wxWidgets directory to update the contents of
|
||||
# include/wx/intl.h and src/common/intl.cpp using information from langtabl.txt
|
||||
#
|
||||
# This script must be ran from misc/languages subdirectory.
|
||||
#
|
||||
# It generates wxLanguage enum (to be cut&pasted to include/wx/intl.h)
|
||||
# and conversion tables (ditto to src/common/intl.cpp)
|
||||
#
|
||||
# Warning: error detection and reporting here is rudimentary, check if the
|
||||
# files were updated correctly with "svn diff" before committing them!
|
||||
|
||||
import os
|
||||
import string
|
||||
import sys
|
||||
|
||||
def ReadTable():
|
||||
table = []
|
||||
f = open('langtabl.txt')
|
||||
try:
|
||||
f = open('misc/languages/langtabl.txt')
|
||||
except:
|
||||
print "Did you run the script from top-level wxWidgets directory?"
|
||||
raise
|
||||
|
||||
for i in f.readlines():
|
||||
ispl = i.split()
|
||||
table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:])))
|
||||
@@ -19,12 +25,8 @@ def ReadTable():
|
||||
return table
|
||||
|
||||
|
||||
def GenEnum(table):
|
||||
f = open('_wxlang.h', 'wt')
|
||||
def WriteEnum(f, table):
|
||||
f.write("""
|
||||
|
||||
// --- --- --- generated code begins here --- --- ---
|
||||
|
||||
/**
|
||||
The languages supported by wxLocale.
|
||||
|
||||
@@ -50,13 +52,10 @@ enum wxLanguage
|
||||
wxLANGUAGE_USER_DEFINED
|
||||
};
|
||||
|
||||
// --- --- --- generated code ends here --- --- ---
|
||||
|
||||
""")
|
||||
f.close()
|
||||
|
||||
|
||||
def GenTable(table):
|
||||
def WriteTable(f, table):
|
||||
all_langs = []
|
||||
all_sublangs = []
|
||||
|
||||
@@ -88,10 +87,7 @@ def GenTable(table):
|
||||
if s != '0' and s != 'SUBLANG_DEFAULT':
|
||||
ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
|
||||
|
||||
f = open('_wxlang.cpp', 'wt')
|
||||
f.write("""
|
||||
// --- --- --- generated code begins here --- --- ---
|
||||
|
||||
// This table is generated by misc/languages/genlang.py
|
||||
// When making changes, please put them into misc/languages/langtabl.txt
|
||||
|
||||
@@ -125,15 +121,50 @@ void wxLocale::InitLanguagesDB()
|
||||
}
|
||||
#undef LNG
|
||||
|
||||
// --- --- --- generated code ends here --- --- ---
|
||||
|
||||
""" % (ifdefs, lngtable))
|
||||
f.close()
|
||||
|
||||
|
||||
def ReplaceGeneratedPartOfFile(fname, func):
|
||||
"""
|
||||
Replaces the part of file marked with the special comments with the
|
||||
output of func.
|
||||
|
||||
fname is the name of the input file and func must be a function taking
|
||||
a file and language table on input and writing the appropriate chunk to
|
||||
this file, e.g. WriteEnum or WriteTable.
|
||||
"""
|
||||
fin = open(fname, 'rt')
|
||||
fnameNew = fname + '.new'
|
||||
fout = open(fnameNew, 'wt')
|
||||
betweenBeginAndEnd = 0
|
||||
afterEnd = 0
|
||||
for l in fin.readlines():
|
||||
if l == '// --- --- --- generated code begins here --- --- ---\n':
|
||||
if betweenBeginAndEnd or afterEnd:
|
||||
print 'Unexpected starting comment.'
|
||||
betweenBeginAndEnd = 1
|
||||
fout.write(l)
|
||||
func(fout, table)
|
||||
elif l == '// --- --- --- generated code ends here --- --- ---\n':
|
||||
if not betweenBeginAndEnd:
|
||||
print 'End comment found before the starting one?'
|
||||
break
|
||||
|
||||
betweenBeginAndEnd = 0
|
||||
afterEnd = 1
|
||||
|
||||
if not betweenBeginAndEnd:
|
||||
fout.write(l)
|
||||
|
||||
if not afterEnd:
|
||||
print 'Failed to process %s.' % fname
|
||||
os.remove(fnameNew)
|
||||
sys.exit(1)
|
||||
|
||||
os.remove(fname)
|
||||
os.rename(fnameNew, fname)
|
||||
|
||||
table = ReadTable()
|
||||
GenEnum(table) # the enum is used also (thanks to doxygen) in the docs
|
||||
GenTable(table)
|
||||
ReplaceGeneratedPartOfFile('include/wx/intl.h', WriteEnum)
|
||||
ReplaceGeneratedPartOfFile('interface/wx/intl.h', WriteEnum)
|
||||
ReplaceGeneratedPartOfFile('src/common/intl.cpp', WriteTable)
|
||||
|
Reference in New Issue
Block a user