2001-01-10 18:31:26 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
#
|
2009-05-19 10:51:11 +00:00
|
|
|
# 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)
|
2001-01-10 18:31:26 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
def ReadTable():
|
|
|
|
table = []
|
|
|
|
f = open('langtabl.txt')
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def GenEnum(table):
|
|
|
|
f = open('_wxlang.h', 'wt')
|
|
|
|
f.write("""
|
2001-03-25 22:19:13 +00:00
|
|
|
|
|
|
|
// --- --- --- generated code begins here --- --- ---
|
|
|
|
|
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
|
|
|
|
{
|
2008-10-17 20:27:36 +00:00
|
|
|
/// User's default/preffered language as got from OS.
|
|
|
|
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.
|
2001-01-10 18:31:26 +00:00
|
|
|
wxLANGUAGE_USER_DEFINED
|
|
|
|
};
|
2001-03-25 22:19:13 +00:00
|
|
|
|
|
|
|
// --- --- --- generated code ends here --- --- ---
|
|
|
|
|
2001-01-10 18:31:26 +00:00
|
|
|
""")
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
def GenTable(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 = open('_wxlang.cpp', 'wt')
|
|
|
|
f.write("""
|
2001-03-25 22:19:13 +00:00
|
|
|
// --- --- --- generated code begins here --- --- ---
|
|
|
|
|
2001-01-10 18:31:26 +00:00
|
|
|
// This table is generated by misc/languages/genlang.py
|
|
|
|
// When making changes, please put them into misc/languages/langtabl.txt
|
|
|
|
|
2008-02-17 20:11:17 +00:00
|
|
|
#if !defined(__WIN32__) || defined(__WXMICROWIN__)
|
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;
|
|
|
|
wxStringTokenizer tkn;
|
|
|
|
|
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
|
|
|
|
|
|
|
// --- --- --- generated code ends here --- --- ---
|
|
|
|
|
2001-02-07 21:47:55 +00:00
|
|
|
""" % (ifdefs, lngtable))
|
2001-01-10 18:31:26 +00:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table = ReadTable()
|
2008-10-17 20:27:36 +00:00
|
|
|
GenEnum(table) # the enum is used also (thanks to doxygen) in the docs
|
2001-01-10 18:31:26 +00:00
|
|
|
GenTable(table)
|