Initialize translation dictionary to default

Initializes the dictionary before potential messages are shown on the
screen.

Fixes https://gitlab.com/kicad/code/kicad/issues/7076
This commit is contained in:
Seth Hillbrand 2021-01-12 13:03:17 -08:00
parent ad97fabfd3
commit f303b07086
2 changed files with 54 additions and 8 deletions

View File

@ -236,12 +236,6 @@ bool PGM_BASE::InitPgm()
return false;
}
m_settings_manager = std::make_unique<SETTINGS_MANAGER>();
// Something got in the way of settings load: can't continue
if( !m_settings_manager->IsOK() )
return false;
// Init KiCad environment
// the environment variable KICAD (if exists) gives the kicad path:
// something like set KICAD=d:\kicad
@ -272,9 +266,16 @@ bool PGM_BASE::InitPgm()
wxFileSystem::AddHandler( new wxZipFSHandler );
// Analyze the command line & initialize the binary path
wxString tmp;
setExecutablePath();
SetLanguagePath();
SetDefaultLanguage( tmp );
m_settings_manager = std::make_unique<SETTINGS_MANAGER>();
// Something got in the way of settings load: can't continue
if( !m_settings_manager->IsOK() )
return false;
wxFileName baseSharePath;
#if defined( __WXMSW__ )
@ -438,7 +439,6 @@ bool PGM_BASE::InitPgm()
// Init user language *before* calling loadCommonSettings, because
// env vars could be incorrectly initialized on Linux
// (if the value contains some non ASCII7 chars, the env var is not initialized)
wxString tmp;
SetLanguage( tmp, true );
loadCommonSettings();
@ -681,6 +681,44 @@ bool PGM_BASE::SetLanguage( wxString& aErrMsg, bool first_time )
}
bool PGM_BASE::SetDefaultLanguage( wxString& aErrMsg )
{
setLanguageId( wxLANGUAGE_DEFAULT );
// dictionary file name without extend (full name is kicad.mo)
wxString dictionaryName( "kicad" );
delete m_locale;
m_locale = new wxLocale;
m_locale->Init();
// Try adding the dictionary if it is not currently loaded
if( !m_locale->IsLoaded( dictionaryName ) )
m_locale->AddCatalog( dictionaryName );
// Verify the Kicad dictionary was loaded properly
// However, for the English language, the dictionary is not mandatory, as
// all messages are already in English, just restricted to ASCII7 chars,
// the verification is skipped.
if( !m_locale->IsLoaded( dictionaryName ) && m_language_id != wxLANGUAGE_ENGLISH )
{
wxLogTrace( traceLocale, "Unable to load dictionary %s.mo in %s",
dictionaryName, m_locale->GetName() );
setLanguageId( wxLANGUAGE_DEFAULT );
delete m_locale;
m_locale = new wxLocale;
m_locale->Init();
aErrMsg = _( "The KiCad language file for this language is not installed." );
return false;
}
return true;
}
void PGM_BASE::SetLanguageIdentifier( int menu_id )
{
wxLogTrace( traceLocale, "Select language ID %d from %d possible languages.",

View File

@ -230,6 +230,14 @@ public:
*/
virtual bool SetLanguage( wxString& aErrMsg, bool first_time = false );
/**
* Set the default language without reference to any preferences. Can be used to set
* the language for dialogs that show before preferences are loaded
* @param aErrMsg String to return the error messsage(s) in
* @return false if the language could not be set
*/
bool SetDefaultLanguage( wxString& aErrMsg );
/**
* Set in .m_language_id member the wxWidgets language identifier ID fromthe KiCad
* menu id (internal menu identifier).