2001-01-10 13:31:26 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generates wxLanguage enum (to be cut&pasted to include/wx/intl.h)
|
|
|
|
# and convertion tables (ditto to src/common/intl.cpp)
|
|
|
|
#
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
|
|
|
def ReadTable():
|
|
|
|
table = []
|
|
|
|
f = open('langtabl.txt')
|
|
|
|
for i in f.readlines():
|
|
|
|
ispl = i.split()
|
2006-09-04 09:35:13 -04:00
|
|
|
table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], string.join(ispl[5:])))
|
2001-01-10 13:31:26 -05:00
|
|
|
f.close()
|
|
|
|
return table
|
|
|
|
|
|
|
|
|
|
|
|
def GenEnum(table):
|
|
|
|
f = open('_wxlang.h', 'wt')
|
|
|
|
f.write("""
|
2001-03-25 17:19:13 -05:00
|
|
|
|
|
|
|
// --- --- --- generated code begins here --- --- ---
|
|
|
|
|
2001-01-10 13:31:26 -05:00
|
|
|
// This enum is generated by misc/languages/genlang.py
|
|
|
|
// When making changes, please put them into misc/languages/langtabl.txt
|
|
|
|
enum wxLanguage
|
|
|
|
{
|
|
|
|
// user's default/preffered language as got from OS:
|
|
|
|
wxLANGUAGE_DEFAULT,
|
|
|
|
// unknown language, if wxLocale::GetSystemLanguage fails:
|
|
|
|
wxLANGUAGE_UNKNOWN,
|
|
|
|
|
|
|
|
""");
|
|
|
|
for i in table:
|
|
|
|
f.write(' %s,\n' % i[0])
|
|
|
|
f.write("""
|
|
|
|
// for custom, user-defined languages:
|
|
|
|
wxLANGUAGE_USER_DEFINED
|
|
|
|
};
|
2001-03-25 17:19:13 -05:00
|
|
|
|
|
|
|
// --- --- --- generated code ends here --- --- ---
|
|
|
|
|
2001-01-10 13:31:26 -05:00
|
|
|
""")
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
2001-01-18 19:18:43 -05:00
|
|
|
def GenDocs(table):
|
|
|
|
f = open('_wxlang.tex', 'wt')
|
|
|
|
f.write("""
|
2001-03-25 17:19:13 -05:00
|
|
|
|
|
|
|
%% --- --- --- generated code begins here --- --- ---
|
|
|
|
|
2001-01-18 19:18:43 -05:00
|
|
|
%% This enum is generated by misc/languages/genlang.py
|
|
|
|
%% When making changes, please put them into misc/languages/langtabl.txt
|
|
|
|
\\begin{itemize}\\itemsep=0pt
|
|
|
|
\\item wxLANGUAGE_DEFAULT -- user's default language as obtained from the operating system
|
|
|
|
\\item wxLANGUAGE_UNKNOWN -- returned by \\helpref{GetSystemLanguage}{wxlocalegetsystemlanguage}
|
|
|
|
if it fails to detect the default language
|
|
|
|
\\item wxLANGUAGE_USER_DEFINED -- user defined languages' integer identifiers should start from
|
|
|
|
this
|
|
|
|
""");
|
|
|
|
for i in table:
|
|
|
|
f.write('\\item %s\n' % (i[0].replace('_','\\_')))
|
|
|
|
f.write("""\\end{itemize}
|
2001-03-25 17:19:13 -05:00
|
|
|
|
|
|
|
%% --- --- --- generated code ends here --- --- ---
|
|
|
|
|
2001-01-18 19:18:43 -05:00
|
|
|
""")
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
2001-01-10 13:31:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
def GenTable(table):
|
2001-02-07 16:47:55 -05:00
|
|
|
all_langs = []
|
|
|
|
all_sublangs = []
|
|
|
|
|
|
|
|
lngtable = ''
|
|
|
|
ifdefs = ''
|
|
|
|
|
|
|
|
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 09:35:13 -04: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 16:47:55 -05: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:
|
|
|
|
if s != '0' and s != 'SUBLANG_DEFAULT':
|
|
|
|
ifdefs += '#ifndef %s\n#define %s SUBLANG_DEFAULT\n#endif\n' % (s, s)
|
|
|
|
|
2001-01-10 13:31:26 -05:00
|
|
|
f = open('_wxlang.cpp', 'wt')
|
|
|
|
f.write("""
|
2001-03-25 17:19:13 -05:00
|
|
|
// --- --- --- generated code begins here --- --- ---
|
|
|
|
|
2001-01-10 13:31:26 -05:00
|
|
|
// This table is generated by misc/languages/genlang.py
|
|
|
|
// When making changes, please put them into misc/languages/langtabl.txt
|
|
|
|
|
2001-02-07 16:47:55 -05:00
|
|
|
#ifndef __WIN32__
|
|
|
|
|
|
|
|
#define SETWINLANG(info,lang,sublang)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-01-10 13:31:26 -05:00
|
|
|
#define SETWINLANG(info,lang,sublang) \\
|
|
|
|
info.WinLang = lang, info.WinSublang = sublang;
|
2001-02-07 16:47:55 -05:00
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
#endif // __WIN32__
|
2001-01-10 13:31:26 -05:00
|
|
|
|
2006-09-04 09:35:13 -04:00
|
|
|
#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
|
2001-01-10 13:31:26 -05:00
|
|
|
info.Language = wxlang; \\
|
|
|
|
info.CanonicalName = wxT(canonical); \\
|
2006-09-04 09:35:13 -04:00
|
|
|
info.LayoutDirection = layout; \\
|
|
|
|
info.Description = wxT(desc); \\
|
2001-01-10 13:31:26 -05:00
|
|
|
SETWINLANG(info, winlang, winsublang) \\
|
|
|
|
AddLanguage(info);
|
|
|
|
|
|
|
|
void wxLocale::InitLanguagesDB()
|
|
|
|
{
|
|
|
|
wxLanguageInfo info;
|
|
|
|
wxStringTokenizer tkn;
|
|
|
|
|
2001-02-07 16:47:55 -05:00
|
|
|
%s
|
|
|
|
};
|
2001-01-10 13:31:26 -05:00
|
|
|
#undef LNG
|
2001-03-25 17:19:13 -05:00
|
|
|
|
|
|
|
// --- --- --- generated code ends here --- --- ---
|
|
|
|
|
2001-02-07 16:47:55 -05:00
|
|
|
""" % (ifdefs, lngtable))
|
2001-01-10 13:31:26 -05:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table = ReadTable()
|
|
|
|
GenEnum(table)
|
|
|
|
GenTable(table)
|
2001-01-18 19:18:43 -05:00
|
|
|
GenDocs(table)
|