Generate much smaller code for language database initialization

The initialization function has become too huge to be compiled by some
compilers (notably MinGW-TDM 9.2) after the changes of deef116a09
(Update language database and move support for it to wxUILocale,
2021-11-23), so change the script generating this code to output just an
array element rather than code statements for each language.

This also makes this file much faster to compile with the other
compilers as a nice side effect.

Closes #22100, #22104.
This commit is contained in:
utelle 2022-02-07 13:05:21 +01:00 committed by Vadim Zeitlin
parent 685e3af613
commit e129c7149d
2 changed files with 1141 additions and 1077 deletions

View File

@ -95,7 +95,7 @@ def WriteTable(f, table, scripttable):
for i in scripttable:
scname = '"%s"' % i[0]
scalias = '"%s"' % i[1]
sctable += ' SCMAP(%s, %s)\n' % (scname, scalias)
sctable += ' { %s, %s },\n' % (scname, scalias)
lngtable = ''
@ -115,11 +115,11 @@ def WriteTable(f, table, scripttable):
ilayout = "wxLayout_RightToLeft"
else:
print "ERROR: Invalid value for the layout direction";
lngtable += ' LNG(%-60s %-17s, %-28s, %-15s, %-4s, %-4s, %s, %s)\n' % \
lngtable += ' { %-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
// The following data tables are generated by misc/languages/genlang.py
// When making changes, please put them into misc/languages/langtabl.txt
#if !defined(__WIN32__)
@ -129,36 +129,68 @@ def WriteTable(f, table, scripttable):
#else
#define SETWINLANG(info,lang,sublang) \\
info.WinLang = lang, info.WinSublang = sublang;
info.WinLang = tabLangData[j].lang; \\
info.WinSublang = tabLangData[j].sublang;
#endif // __WIN32__
#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);
// Data table for known languages
static const struct langData_t
{
int wxlang;
const char* bcp47tag;
const char* canonical;
const char* canonicalref;
wxUint32 winlang;
wxUint32 winsublang;
wxLayoutDirection layout;
const char* desc;
const char* descnative;
}
tabLangData[] =
{
%s
{ 0, NULL, NULL, NULL, 0, 0, wxLayout_Default, NULL, NULL }
};
#define SCMAP(scname, scalias) \\
gs_scmap_name2alias[wxT(scname)] = wxT(scalias); \\
gs_scmap_alias2name[wxT(scalias)] = wxT(scname);
// Data table for known language scripts
static const struct scriptData_t
{
const char* scname;
const char* scalias;
}
tabScriptData[] =
{
%s
{ NULL, NULL }
};
void wxUILocale::InitLanguagesDB()
{
wxLanguageInfo info;
int j;
// Known languages
%s
for (j = 0; tabLangData[j].wxlang != 0; ++j)
{
info.Language = tabLangData[j].wxlang;
info.LocaleTag = tabLangData[j].bcp47tag;
info.CanonicalName = tabLangData[j].canonical;
info.CanonicalRef = tabLangData[j].canonicalref;
info.LayoutDirection = tabLangData[j].layout;
info.Description = wxString::FromUTF8(tabLangData[j].desc);
info.DescriptionNative = wxString::FromUTF8(tabLangData[j].descnative);
SETWINLANG(info, winlang, winsublang)
AddLanguage(info);
}
// Known language scripts
%s
for (j = 0; tabScriptData[j].scname; ++j)
{
gs_scmap_name2alias[tabScriptData[j].scname] = tabScriptData[j].scalias;
gs_scmap_alias2name[tabScriptData[j].scalias] = tabScriptData[j].scname;
}
}
#undef LNG
#undef SCMAP
""" % (lngtable,sctable))

File diff suppressed because it is too large Load Diff