2001-01-10 18:31:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2009-07-07 10:52:44 +00:00
|
|
|
# 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
|
2001-01-10 18:31:26 +00:00
|
|
|
#
|
2009-07-07 10:52:44 +00:00
|
|
|
# Warning: error detection and reporting here is rudimentary, check if the
|
2015-02-21 03:07:15 +00:00
|
|
|
# files were updated correctly with "git diff" before committing them!
|
2001-01-10 18:31:26 +00:00
|
|
|
|
2009-07-07 10:52:44 +00:00
|
|
|
import os
|
2001-01-10 18:31:26 +00:00
|
|
|
import string
|
2009-07-07 10:52:44 +00:00
|
|
|
import sys
|
2001-01-10 18:31:26 +00:00
|
|
|
|
|
|
|
def ReadTable():
|
|
|
|
table = []
|
2009-07-07 10:52:44 +00:00
|
|
|
try:
|
|
|
|
f = open('misc/languages/langtabl.txt')
|
|
|
|
except:
|
|
|
|
print "Did you run the script from top-level wxWidgets directory?"
|
|
|
|
raise
|
|
|
|
|
2001-01-10 18:31:26 +00:00
|
|
|
for i in f.readlines():
|
|
|
|
ispl = i.split()
|
2006-09-04 13:35:13 +00:00
|
|
|
table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:])))
|
2001-01-10 18:31:26 +00:00
|
|
|
f.close()
|
|
|
|
return table
|
|
|
|
|
|
|
|
|
2009-07-07 10:52:44 +00:00
|
|
|
def WriteEnum(f, table):
|
2001-01-10 18:31:26 +00:00
|
|
|
f.write("""
|
2008-10-17 20:27:36 +00:00
|
|
|
/**
|
|
|
|
The languages supported by wxLocale.
|
|
|
|
|
|
|
|
This enum is generated by misc/languages/genlang.py
|
|
|
|
When making changes, please put them into misc/languages/langtabl.txt
|
|
|
|
*/
|
2001-01-10 18:31:26 +00:00
|
|
|
enum wxLanguage
|
|
|
|
{
|
2014-01-11 02:52:13 +00:00
|
|
|
/// User's default/preferred language as got from OS.
|
2008-10-17 20:27:36 +00:00
|
|
|
wxLANGUAGE_DEFAULT,
|
|
|
|
|
|
|
|
/// Unknown language, returned if wxLocale::GetSystemLanguage fails.
|
|
|
|
wxLANGUAGE_UNKNOWN,
|
|
|
|
|
2001-01-10 18:31:26 +00:00
|
|
|
""");
|
2008-02-17 20:11:17 +00:00
|
|
|
knownLangs = []
|
2001-01-10 18:31:26 +00:00
|
|
|
for i in table:
|
2008-02-17 20:11:17 +00:00
|
|
|
if i[0] not in knownLangs:
|
|
|
|
f.write(' %s,\n' % i[0])
|
|
|
|
knownLangs.append(i[0])
|
2001-01-10 18:31:26 +00:00
|
|
|
f.write("""
|
2008-10-17 20:27:36 +00:00
|
|
|
/// For custom, user-defined languages.
|
2014-04-20 12:44:57 +00:00
|
|
|
wxLANGUAGE_USER_DEFINED,
|
|
|
|
|
|
|
|
|
|
|
|
/// Obsolete synonym.
|
|
|
|
wxLANGUAGE_CAMBODIAN = wxLANGUAGE_KHMER
|
2001-01-10 18:31:26 +00:00
|
|
|
};
|
2001-03-25 22:19:13 +00:00
|
|
|
|
2001-01-10 18:31:26 +00:00
|
|
|
""")
|
|
|
|
|
|
|
|
|
2009-07-07 10:52:44 +00:00
|
|
|
def WriteTable(f, table):
|
2001-02-07 21:47:55 +00:00
|
|
|
all_langs = []
|
|
|
|
all_sublangs = []
|
2008-10-17 20:27:36 +00:00
|
|
|
|
2001-02-07 21:47:55 +00:00
|
|
|
lngtable = ''
|
2008-10-17 20:27:36 +00:00
|
|
|
ifdefs = ''
|
|
|
|
|
2001-02-07 21:47:55 +00:00
|
|
|
for i in table:
|
|
|
|
ican = '"%s"' % i[1]
|
|
|
|
if ican == '"-"': ican = '""'
|
|
|
|
ilang = i[2]
|
|
|
|
if ilang == '-': ilang = '0'
|
|
|
|
isublang = i[3]
|
|
|
|
if isublang == '-': isublang = '0'
|
2006-09-04 13:35:13 +00:00
|
|
|
if (i[4] == "LTR") :
|
|
|
|
ilayout = "wxLayout_LeftToRight"
|
|
|
|
elif (i[4] == "RTL"):
|
|
|
|
ilayout = "wxLayout_RightToLeft"
|
|
|
|
else:
|
|
|
|
print "ERROR: Invalid value for the layout direction";
|
|
|
|
lngtable += ' LNG(%-38s %-7s, %-15s, %-34s, %s, %s)\n' % \
|
|
|
|
((i[0]+','), ican, ilang, isublang, ilayout, i[5])
|
2001-02-07 21:47:55 +00:00
|
|
|
if ilang not in all_langs: all_langs.append(ilang)
|
|
|
|
if isublang not in all_sublangs: all_sublangs.append(isublang)
|
|
|
|
|
|
|
|
for s in all_langs:
|
|
|
|
if s != '0':
|
|
|
|
ifdefs += '#ifndef %s\n#define %s (0)\n#endif\n' % (s, s)
|
|
|
|
for s in all_sublangs:
|
2008-10-17 20:27:36 +00:00
|
|
|
if s != '0' and s != 'SUBLANG_DEFAULT':
|
2001-02-07 21:47:55 +00:00
|
|
|
ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
|
|
|
|
|
2001-01-10 18:31:26 +00:00
|
|
|
f.write("""
|
|
|
|
// This table is generated by misc/languages/genlang.py
|
|
|
|
// When making changes, please put them into misc/languages/langtabl.txt
|
|
|
|
|
2015-08-27 08:17:32 +00:00
|
|
|
#if !defined(__WIN32__)
|
2001-02-07 21:47:55 +00:00
|
|
|
|
|
|
|
#define SETWINLANG(info,lang,sublang)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-01-10 18:31:26 +00:00
|
|
|
#define SETWINLANG(info,lang,sublang) \\
|
|
|
|
info.WinLang = lang, info.WinSublang = sublang;
|
2001-02-07 21:47:55 +00:00
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
#endif // __WIN32__
|
2001-01-10 18:31:26 +00:00
|
|
|
|
2006-09-04 13:35:13 +00:00
|
|
|
#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
|
2001-01-10 18:31:26 +00:00
|
|
|
info.Language = wxlang; \\
|
|
|
|
info.CanonicalName = wxT(canonical); \\
|
2006-09-04 13:35:13 +00:00
|
|
|
info.LayoutDirection = layout; \\
|
|
|
|
info.Description = wxT(desc); \\
|
2001-01-10 18:31:26 +00:00
|
|
|
SETWINLANG(info, winlang, winsublang) \\
|
|
|
|
AddLanguage(info);
|
|
|
|
|
|
|
|
void wxLocale::InitLanguagesDB()
|
|
|
|
{
|
|
|
|
wxLanguageInfo info;
|
|
|
|
|
2008-02-17 20:11:17 +00:00
|
|
|
%s
|
|
|
|
}
|
2001-01-10 18:31:26 +00:00
|
|
|
#undef LNG
|
2001-03-25 22:19:13 +00:00
|
|
|
|
2001-02-07 21:47:55 +00:00
|
|
|
""" % (ifdefs, lngtable))
|
2001-01-10 18:31:26 +00:00
|
|
|
|
|
|
|
|
2009-07-07 10:52:44 +00:00
|
|
|
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)
|
2001-01-10 18:31:26 +00:00
|
|
|
|
|
|
|
table = ReadTable()
|
2010-04-24 07:06:32 +00:00
|
|
|
ReplaceGeneratedPartOfFile('include/wx/language.h', WriteEnum)
|
|
|
|
ReplaceGeneratedPartOfFile('interface/wx/language.h', WriteEnum)
|
|
|
|
ReplaceGeneratedPartOfFile('src/common/languageinfo.cpp', WriteTable)
|