store language selection in settings file; add translation help functions in util.h/.cpp
This commit is contained in:
parent
335f14631f
commit
479ec6f1df
7 changed files with 118 additions and 54 deletions
|
@ -20,6 +20,9 @@
|
|||
- bug fix: grouping faders in the client should be proportional (see discussion in #202, #419)
|
||||
|
||||
|
||||
TODO add support to change language (#297)
|
||||
TODO add language selector also in the server GUI
|
||||
|
||||
TODO bug fix: incorrect selection of UI language (#408) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
-> note that for the 3.5.8 bug fix release we went back to the original translation code (e.g. no pt_BR!)
|
||||
|
||||
|
@ -28,6 +31,7 @@ TODO add new register message which contains version and, e.g., max number of cl
|
|||
TODO Inconsistency between Input meter and Audio mixer meter #423
|
||||
|
||||
TODO improve settings management -> move settings class in client/server classes, move actual settings variables
|
||||
TODO store recorder settings (#313)
|
||||
|
||||
|
||||
|
||||
|
|
31
src/main.cpp
31
src/main.cpp
|
@ -25,8 +25,6 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
#include <QTranslator>
|
||||
#include <QLibraryInfo>
|
||||
#include "global.h"
|
||||
#ifndef HEADLESS
|
||||
# include <QApplication>
|
||||
|
@ -582,23 +580,6 @@ int main ( int argc, char** argv )
|
|||
// init resources
|
||||
Q_INIT_RESOURCE(resources);
|
||||
|
||||
// load translations
|
||||
QTranslator myappTranslator, myqtTranslator;
|
||||
|
||||
if ( bUseGUI && bUseTranslation )
|
||||
{
|
||||
if ( myappTranslator.load ( QLocale(), "translation", "_", ":/translations" ) )
|
||||
{
|
||||
pApp->installTranslator ( &myappTranslator );
|
||||
}
|
||||
|
||||
// allows the Qt messages to be translated in the application
|
||||
if ( myqtTranslator.load ( QLocale(), "qt", "_", QLibraryInfo::location ( QLibraryInfo::TranslationsPath ) ) )
|
||||
{
|
||||
pApp->installTranslator ( &myqtTranslator );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TEST -> activate the following line to activate the test bench,
|
||||
//CTestbench Testbench ( "127.0.0.1", DEFAULT_PORT_NUMBER );
|
||||
|
@ -620,6 +601,12 @@ int main ( int argc, char** argv )
|
|||
CClientSettings Settings ( &Client, strIniFileName );
|
||||
Settings.Load();
|
||||
|
||||
// load translation
|
||||
if ( bUseGUI && bUseTranslation )
|
||||
{
|
||||
CLocale::LoadTranslation ( Settings.strLanguage, pApp );
|
||||
}
|
||||
|
||||
#ifndef HEADLESS
|
||||
if ( bUseGUI )
|
||||
{
|
||||
|
@ -673,6 +660,12 @@ int main ( int argc, char** argv )
|
|||
CServerSettings Settings ( &Server, strIniFileName );
|
||||
Settings.Load();
|
||||
|
||||
// load translation
|
||||
if ( bUseGUI && bUseTranslation )
|
||||
{
|
||||
CLocale::LoadTranslation ( Settings.strLanguage, pApp );
|
||||
}
|
||||
|
||||
// update server list AFTER restoring the settings from the
|
||||
// settings file
|
||||
Server.UpdateServerList();
|
||||
|
|
|
@ -1,54 +1,30 @@
|
|||
<RCC>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_de_DE.qm">res/translation/translation_de_DE.qm</file>
|
||||
<file alias="translation_de">res/translation/translation_de_DE.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_de.qm">res/translation/translation_de_DE.qm</file>
|
||||
<file alias="translation_fr">res/translation/translation_fr_FR.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_fr_FR.qm">res/translation/translation_fr_FR.qm</file>
|
||||
<file alias="translation_pt_PT">res/translation/translation_pt_PT.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_fr.qm">res/translation/translation_fr_FR.qm</file>
|
||||
<file alias="translation_pt">res/translation/translation_pt_BR.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_pt_PT.qm">res/translation/translation_pt_PT.qm</file>
|
||||
<file alias="translation_es">res/translation/translation_es_ES.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_pt_BR.qm">res/translation/translation_pt_BR.qm</file>
|
||||
<file alias="translation_nl">res/translation/translation_nl_NL.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_pt.qm">res/translation/translation_pt_PT.qm</file>
|
||||
<file alias="translation_it">res/translation/translation_it_IT.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_es_ES.qm">res/translation/translation_es_ES.qm</file>
|
||||
<file alias="translation_pl">res/translation/translation_pl_PL.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_es.qm">res/translation/translation_es_ES.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_nl_NL.qm">res/translation/translation_nl_NL.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_nl.qm">res/translation/translation_nl_NL.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_it_IT.qm">res/translation/translation_it_IT.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_it.qm">res/translation/translation_it_IT.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_pl_PL.qm">res/translation/translation_pl_PL.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_pl.qm">res/translation/translation_pl_PL.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_sv_SE.qm">res/translation/translation_sv_SE.qm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/translations">
|
||||
<file alias="translation_sv.qm">res/translation/translation_sv_SE.qm</file>
|
||||
<file alias="translation_sv">res/translation/translation_sv_SE.qm</file>
|
||||
</qresource>
|
||||
|
||||
<qresource prefix="/png/LEDs">
|
||||
|
|
|
@ -303,6 +303,10 @@ void CClientSettings::ReadFromXML ( const QDomDocument& IniXMLDocument )
|
|||
bConnectDlgShowAllMusicians = bValue;
|
||||
}
|
||||
|
||||
// language
|
||||
strLanguage = GetIniSetting ( IniXMLDocument, "client", "language",
|
||||
CLocale::FindSysLangTransFileName ( CLocale::GetAvailableTranslations() ).first );
|
||||
|
||||
// name
|
||||
pClient->ChannelInfo.strName = FromBase64ToString (
|
||||
GetIniSetting ( IniXMLDocument, "client", "name_base64",
|
||||
|
@ -613,6 +617,10 @@ void CClientSettings::WriteToXML ( QDomDocument& IniXMLDocument )
|
|||
SetFlagIniSet ( IniXMLDocument, "client", "connectdlgshowallmusicians",
|
||||
bConnectDlgShowAllMusicians );
|
||||
|
||||
// language
|
||||
PutIniSetting ( IniXMLDocument, "client", "language",
|
||||
strLanguage );
|
||||
|
||||
// name
|
||||
PutIniSetting ( IniXMLDocument, "client", "name_base64",
|
||||
ToBase64 ( pClient->ChannelInfo.strName ) );
|
||||
|
@ -787,6 +795,10 @@ if ( GetFlagIniSet ( IniXMLDocument, "server", "defcentservaddr", bValue ) )
|
|||
pServer->SetServerListEnabled ( bValue );
|
||||
}
|
||||
|
||||
// language
|
||||
strLanguage = GetIniSetting ( IniXMLDocument, "server", "language",
|
||||
CLocale::FindSysLangTransFileName ( CLocale::GetAvailableTranslations() ).first );
|
||||
|
||||
// name
|
||||
pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
|
||||
|
||||
|
@ -832,6 +844,10 @@ void CServerSettings::WriteToXML ( QDomDocument& IniXMLDocument )
|
|||
SetFlagIniSet ( IniXMLDocument, "server", "servlistenabled",
|
||||
pServer->GetServerListEnabled() );
|
||||
|
||||
// language
|
||||
PutIniSetting ( IniXMLDocument, "server", "language",
|
||||
strLanguage );
|
||||
|
||||
// name
|
||||
PutIniSetting ( IniXMLDocument, "server", "name",
|
||||
pServer->GetServerName() );
|
||||
|
|
|
@ -120,6 +120,7 @@ public:
|
|||
vstrIPAddress ( MAX_NUM_SERVER_ADDR_ITEMS, "" ),
|
||||
iNewClientFaderLevel ( 100 ),
|
||||
bConnectDlgShowAllMusicians ( true ),
|
||||
strLanguage ( "" ),
|
||||
vecWindowPosMain ( ), // empty array
|
||||
vecWindowPosSettings ( ), // empty array
|
||||
vecWindowPosChat ( ), // empty array
|
||||
|
@ -141,6 +142,7 @@ public:
|
|||
CVector<QString> vstrIPAddress;
|
||||
int iNewClientFaderLevel;
|
||||
bool bConnectDlgShowAllMusicians;
|
||||
QString strLanguage;
|
||||
|
||||
// window position/state settings
|
||||
QByteArray vecWindowPosMain;
|
||||
|
@ -165,10 +167,13 @@ class CServerSettings : public CSettings
|
|||
{
|
||||
public:
|
||||
CServerSettings ( CServer* pNSerP, const QString& sNFiName ) :
|
||||
strLanguage ( "" ),
|
||||
vecWindowPosMain ( ), // empty array
|
||||
pServer ( pNSerP )
|
||||
{ SetFileName ( sNFiName, DEFAULT_INI_FILE_NAME_SERVER); }
|
||||
|
||||
QString strLanguage;
|
||||
|
||||
// window position/state settings
|
||||
QByteArray vecWindowPosMain;
|
||||
|
||||
|
|
63
src/util.cpp
63
src/util.cpp
|
@ -1375,6 +1375,69 @@ ECSAddType CLocale::GetCentralServerAddressType ( const QLocale::Country eCountr
|
|||
}
|
||||
}
|
||||
|
||||
QMap<QString, QString> CLocale::GetAvailableTranslations()
|
||||
{
|
||||
QMap<QString, QString> TranslMap;
|
||||
QDirIterator DirIter ( ":/translations" );
|
||||
|
||||
while ( DirIter.hasNext() )
|
||||
{
|
||||
// get alias of translation file
|
||||
const QString strCurFileName = DirIter.next();
|
||||
|
||||
// extract only language code (must be at the end, separated with a "_")
|
||||
const QString strLoc = strCurFileName.right ( strCurFileName.length() - strCurFileName.indexOf ( "_" ) - 1 );
|
||||
|
||||
TranslMap[strLoc] = strCurFileName;
|
||||
}
|
||||
|
||||
return TranslMap;
|
||||
}
|
||||
|
||||
QPair<QString, QString> CLocale::FindSysLangTransFileName ( const QMap<QString, QString>& TranslMap )
|
||||
{
|
||||
QPair<QString, QString> PairSysLang ( "", "" );
|
||||
QStringList slUiLang = QLocale().uiLanguages();
|
||||
|
||||
if ( !slUiLang.isEmpty() )
|
||||
{
|
||||
// only extract two first characters to identify language (ignoring
|
||||
// location for getting a simpler implementation -> if the language
|
||||
// is not correct, the user can change it in the GUI anyway)
|
||||
const QString strUiLang = QLocale().uiLanguages().at ( 0 );
|
||||
|
||||
if ( strUiLang.length() >= 2 )
|
||||
{
|
||||
PairSysLang.first = strUiLang.left ( 2 );
|
||||
PairSysLang.second = TranslMap[PairSysLang.first];
|
||||
}
|
||||
}
|
||||
|
||||
return PairSysLang;
|
||||
}
|
||||
|
||||
void CLocale::LoadTranslation ( const QString strLanguage,
|
||||
QCoreApplication* pApp )
|
||||
{
|
||||
// The translator objects must be static!
|
||||
static QTranslator myappTranslator;
|
||||
static QTranslator myqtTranslator;
|
||||
|
||||
QMap<QString, QString> TranslMap = CLocale::GetAvailableTranslations();
|
||||
const QString strTranslationFileName = TranslMap[strLanguage];
|
||||
|
||||
if ( myappTranslator.load ( strTranslationFileName ) )
|
||||
{
|
||||
pApp->installTranslator ( &myappTranslator );
|
||||
}
|
||||
|
||||
// allows the Qt messages to be translated in the application
|
||||
if ( myqtTranslator.load ( QLocale ( strLanguage ), "qt", "_", QLibraryInfo::location ( QLibraryInfo::TranslationsPath ) ) )
|
||||
{
|
||||
pApp->installTranslator ( &myqtTranslator );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Console writer factory ------------------------------------------------------
|
||||
QTextStream* ConsoleWriterFactory::get()
|
||||
|
|
11
src/util.h
11
src/util.h
|
@ -41,6 +41,9 @@
|
|||
# include "ui_aboutdlgbase.h"
|
||||
#endif
|
||||
#include <QFile>
|
||||
#include <QDirIterator>
|
||||
#include <QTranslator>
|
||||
#include <QLibraryInfo>
|
||||
#include <QUrl>
|
||||
#include <QLocale>
|
||||
#include <QElapsedTimer>
|
||||
|
@ -870,8 +873,12 @@ protected:
|
|||
class CLocale
|
||||
{
|
||||
public:
|
||||
static QString GetCountryFlagIconsResourceReference ( const QLocale::Country eCountry );
|
||||
static ECSAddType GetCentralServerAddressType ( const QLocale::Country eCountry );
|
||||
static QString GetCountryFlagIconsResourceReference ( const QLocale::Country eCountry );
|
||||
static ECSAddType GetCentralServerAddressType ( const QLocale::Country eCountry );
|
||||
static QMap<QString, QString> GetAvailableTranslations();
|
||||
static QPair<QString, QString> FindSysLangTransFileName ( const QMap<QString, QString>& TranslMap );
|
||||
static void LoadTranslation ( const QString strLanguage,
|
||||
QCoreApplication* pApp );
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue