Update language database and move support for it to wxUILocale

Update the language database from the canonical sources:

- It now includes most locales supported by Windows 10.
- It now also has the following attributes for each entry:
 - BCP 47-like locale tag.
 - Reference to canonical name for generic language entries.
 - Language name in this language itself.
- Also add data file with list of language script identifiers and
  aliases based on ISO 15924.
- And update genlang.py to handle all the new attributes and data.

Also move database-related methods of wxLocale to wxUILocale and
just redirect wxLocale methods to the new wxUILocale ones (they are
still preserved for compatibility).

Closes https://github.com/wxWidgets/wxWidgets/pull/2594
This commit is contained in:
utelle
2021-11-23 00:20:10 +01:00
committed by Vadim Zeitlin
parent 1a4a0eee48
commit deef116a09
13 changed files with 4117 additions and 1411 deletions

View File

@@ -10,22 +10,37 @@ import os
import string
import sys
def ReadScriptTable():
scripttable = []
try:
f = open('misc/languages/scripttabl.txt')
except:
print("Did you run the script from top-level wxWidgets directory?")
raise
for i in f.readlines():
ispl = i.split()
scripttable.append((ispl[0], ispl[1]))
f.close()
return scripttable
def ReadTable():
table = []
try:
f = open('misc/languages/langtabl.txt')
except:
print "Did you run the script from top-level wxWidgets directory?"
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:])))
table.append((ispl[0], ispl[1], ispl[2], ispl[3], ispl[4], ispl[5], ispl[6], string.join(ispl[7:])))
f.close()
return table
def WriteEnum(f, table):
def WriteEnum(f, table, scripttable):
f.write("""
/**
The languages supported by wxLocale.
@@ -51,6 +66,22 @@ enum wxLanguage
/// For custom, user-defined languages.
wxLANGUAGE_USER_DEFINED,
/// Synonyms.
wxLANGUAGE_AZERI = wxLANGUAGE_AZERBAIJANI,
wxLANGUAGE_AZERI_CYRILLIC = wxLANGUAGE_AZERBAIJANI_CYRILLIC,
wxLANGUAGE_AZERI_LATIN = wxLANGUAGE_AZERBAIJANI_LATIN,
wxLANGUAGE_BENGALI = wxLANGUAGE_BANGLA,
wxLANGUAGE_BENGALI_BANGLADESH = wxLANGUAGE_BANGLA_BANGLADESH,
wxLANGUAGE_BENGALI_INDIA = wxLANGUAGE_BANGLA_INDIA,
wxLANGUAGE_BHUTANI = wxLANGUAGE_DZONGKHA,
wxLANGUAGE_CHINESE_SIMPLIFIED = wxLANGUAGE_CHINESE_CHINA,
wxLANGUAGE_CHINESE_TRADITIONAL = wxLANGUAGE_CHINESE_TAIWAN,
wxLANGUAGE_CHINESE_MACAU = wxLANGUAGE_CHINESE_MACAO,
wxLANGUAGE_KERNEWEK = wxLANGUAGE_CORNISH,
wxLANGUAGE_MALAY_BRUNEI_DARUSSALAM = wxLANGUAGE_MALAY_BRUNEI,
wxLANGUAGE_ORIYA = wxLANGUAGE_ODIA,
wxLANGUAGE_ORIYA_INDIA = wxLANGUAGE_ODIA_INDIA,
wxLANGUAGE_SPANISH_MODERN = wxLANGUAGE_SPANISH,
/// Obsolete synonym.
wxLANGUAGE_CAMBODIAN = wxLANGUAGE_KHMER
@@ -59,37 +90,33 @@ enum wxLanguage
""")
def WriteTable(f, table):
all_langs = []
all_sublangs = []
def WriteTable(f, table, scripttable):
sctable = ''
for i in scripttable:
scname = '"%s"' % i[0]
scalias = '"%s"' % i[1]
sctable += ' SCMAP(%s, %s)\n' % (scname, scalias)
lngtable = ''
ifdefs = ''
for i in table:
ican = '"%s"' % i[1]
ibcp47 = '"%s"' % i[1]
ican = '"%s"' % i[2]
if ican == '"-"': ican = '""'
ilang = i[2]
icanbase = '"%s"' % i[3]
if icanbase == '"-"': icanbase = '""'
ilang = i[4]
if ilang == '-': ilang = '0'
isublang = i[3]
isublang = i[5]
if isublang == '-': isublang = '0'
if (i[4] == "LTR") :
if (i[6] == "LTR") :
ilayout = "wxLayout_LeftToRight"
elif (i[4] == "RTL"):
elif (i[6] == "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])
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)
lngtable += ' LNG(%-60s %-17s, %-28s, %-15s, %-4s, %-4s, %s, %s)\n' % \
((i[0]+','), ibcp47, ican, icanbase, ilang, isublang, ilayout, i[7])
f.write("""
// This table is generated by misc/languages/genlang.py
@@ -104,27 +131,36 @@ def WriteTable(f, table):
#define SETWINLANG(info,lang,sublang) \\
info.WinLang = lang, info.WinSublang = sublang;
%s
#endif // __WIN32__
#define LNG(wxlang, canonical, winlang, winsublang, layout, desc) \\
info.Language = wxlang; \\
info.CanonicalName = wxT(canonical); \\
info.LayoutDirection = layout; \\
info.Description = wxT(desc); \\
SETWINLANG(info, winlang, winsublang) \\
#define LNG(wxlang, bcp47tag, canonical, canonicalref, winlang, winsublang, layout, desc, descnative) \\
info.Language = wxlang; \\
info.LocaleTag = wxT(bcp47tag); \\
info.CanonicalName = wxT(canonical); \\
info.CanonicalRef = wxT(canonicalref); \\
info.LayoutDirection = layout; \\
info.Description = wxString::FromUTF8(desc); \\
info.DescriptionNative = wxString::FromUTF8(descnative); \\
SETWINLANG(info, winlang, winsublang) \\
AddLanguage(info);
void wxLocale::InitLanguagesDB()
{
wxLanguageInfo info;
#define SCMAP(scname, scalias) \\
gs_scmap_name2alias[wxT(scname)] = wxT(scalias); \\
gs_scmap_alias2name[wxT(scalias)] = wxT(scname);
void wxUILocale::InitLanguagesDB()
{
wxLanguageInfo info;
// Known languages
%s
// Known language scripts
%s
}
#undef LNG
#undef SCMAP
""" % (ifdefs, lngtable))
""" % (lngtable,sctable))
def ReplaceGeneratedPartOfFile(fname, func):
@@ -147,7 +183,7 @@ def ReplaceGeneratedPartOfFile(fname, func):
print 'Unexpected starting comment.'
betweenBeginAndEnd = 1
fout.write(l)
func(fout, table)
func(fout, table, scripttable)
elif l == '// --- --- --- generated code ends here --- --- ---\n':
if not betweenBeginAndEnd:
print 'End comment found before the starting one?'
@@ -164,10 +200,13 @@ def ReplaceGeneratedPartOfFile(fname, func):
os.remove(fnameNew)
sys.exit(1)
fout.close()
fin.close()
os.remove(fname)
os.rename(fnameNew, fname)
table = ReadTable()
scripttable = ReadScriptTable()
ReplaceGeneratedPartOfFile('include/wx/language.h', WriteEnum)
ReplaceGeneratedPartOfFile('interface/wx/language.h', WriteEnum)
ReplaceGeneratedPartOfFile('src/common/languageinfo.cpp', WriteTable)