optimize:translator refactor

This commit is contained in:
yifang 2022-03-03 23:02:15 +08:00
parent 2a08b6290e
commit c8284297dd
2 changed files with 26 additions and 21 deletions

View file

@ -460,6 +460,6 @@ QString localizedStringForId( Id langId )
if( iconId.isEmpty() )
return name;
else
return QString( "<img src=\":/flags/%1.png\"> %2" ).arg( iconId ).arg( name );
return QString( "<img src=\":/flags/%1.png\"> %2" ).arg( iconId , name );
}
}

45
main.cc
View file

@ -328,23 +328,8 @@ int main( int argc, char ** argv )
#endif
// Load translations for system locale
QTranslator qtTranslator;
QString localeName = QLocale::system().name();
if ( !qtTranslator.load( "qt_" + localeName, Config::getLocDir() ) )
qtTranslator.load( "qt_" + localeName,
QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
app.installTranslator( &qtTranslator );
QTranslator translator;
translator.load( Config::getLocDir() + "/" + localeName );
app.installTranslator( &translator );
Config::Class cfg;
for( ; ; )
{
@ -395,16 +380,36 @@ int main( int argc, char ** argv )
}
// Reload translations for user selected locale is nesessary
QTranslator qtTranslator;
QTranslator translator;
if( !cfg.preferences.interfaceLanguage.isEmpty() && localeName != cfg.preferences.interfaceLanguage )
{
localeName = cfg.preferences.interfaceLanguage;
if ( !qtTranslator.load( "qt_" + localeName, Config::getLocDir() ) )
qtTranslator.load( "qt_" + localeName,
QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
QLocale locale( localeName );
QLocale::setDefault( locale );
if( !qtTranslator.load( "qt_" + localeName, Config::getLocDir() ) )
{
qtTranslator.load( "qt_" + localeName, QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
app.installTranslator( &qtTranslator );
}
translator.load( Config::getLocDir() + "/" + localeName );
app.installTranslator( &translator );
}
else
{
QString localeName = QLocale::system().name();
if( !qtTranslator.load( "qt_" + localeName, Config::getLocDir() ) )
{
qtTranslator.load( "qt_" + localeName, QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
app.installTranslator( &qtTranslator );
}
translator.load( Config::getLocDir() + "/" + localeName );
app.installTranslator( &translator );
}
// Prevent app from quitting spontaneously when it works with scan popup