Improved detection of default language: Each language file can now have a country id in addition to the language id. This is required, because some languages (e.g. Chinese) have country-specific variants.

This commit is contained in:
LoRd_MuldeR 2011-12-19 17:26:20 +01:00
parent d1803f1a3b
commit 3141ebf2ee
6 changed files with 31 additions and 14 deletions

View File

@ -1 +1 @@
25,6,繁体中文 25,208,繁体中文

View File

@ -1 +1 @@
25,5,简体中文 25,44,简体中文

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_MINOR_LO 4
#define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 10 #define VER_LAMEXP_PATCH 10
#define VER_LAMEXP_BUILD 819 #define VER_LAMEXP_BUILD 820
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!) // Tool versions (minimum expected versions!)

View File

@ -186,7 +186,7 @@ static struct
QMap<QString, QString> files; QMap<QString, QString> files;
QMap<QString, QString> names; QMap<QString, QString> names;
QMap<QString, unsigned int> sysid; QMap<QString, unsigned int> sysid;
QMap<QString, unsigned int> scrpt; QMap<QString, unsigned int> cntry;
} }
g_lamexp_translation; g_lamexp_translation;
@ -1252,7 +1252,7 @@ const QString lamexp_version2string(const QString &pattern, unsigned int version
/* /*
* Register a new translation * Register a new translation
*/ */
bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &script) bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country)
{ {
if(qmFile.isEmpty() || langName.isEmpty() || systemId < 1) if(qmFile.isEmpty() || langName.isEmpty() || systemId < 1)
{ {
@ -1262,7 +1262,7 @@ bool lamexp_translation_register(const QString &langId, const QString &qmFile, c
g_lamexp_translation.files.insert(langId, qmFile); g_lamexp_translation.files.insert(langId, qmFile);
g_lamexp_translation.names.insert(langId, langName); g_lamexp_translation.names.insert(langId, langName);
g_lamexp_translation.sysid.insert(langId, systemId); g_lamexp_translation.sysid.insert(langId, systemId);
g_lamexp_translation.scrpt.insert(langId, script); g_lamexp_translation.cntry.insert(langId, country);
return true; return true;
} }
@ -1294,9 +1294,9 @@ unsigned int lamexp_translation_sysid(const QString &langId)
/* /*
* Get translation script id * Get translation script id
*/ */
unsigned int lamexp_translation_script(const QString &langId) unsigned int lamexp_translation_country(const QString &langId)
{ {
return g_lamexp_translation.scrpt.value(langId.toLower(), 0); return g_lamexp_translation.cntry.value(langId.toLower(), 0);
} }
/* /*

View File

@ -111,10 +111,10 @@ bool lamexp_is_hibernation_supported(void);
//Translation support //Translation support
QStringList lamexp_query_translations(void); QStringList lamexp_query_translations(void);
bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &script); bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country);
QString lamexp_translation_name(const QString &language); QString lamexp_translation_name(const QString &language);
unsigned int lamexp_translation_sysid(const QString &langId); unsigned int lamexp_translation_sysid(const QString &langId);
unsigned int lamexp_translation_script(const QString &langId); unsigned int lamexp_translation_country(const QString &langId);
bool lamexp_install_translator_from_file(const QString &qmFile); bool lamexp_install_translator_from_file(const QString &qmFile);
bool lamexp_install_translator(const QString &language); bool lamexp_install_translator(const QString &language);
QStringList lamexp_available_codepages(bool noAliases = true); QStringList lamexp_available_codepages(bool noAliases = true);

View File

@ -271,23 +271,28 @@ QString SettingsModel::defaultLanguage(void)
return *m_defaultLanguage; return *m_defaultLanguage;
} }
//Check if we can use the default translation //Detect system langauge
QLocale systemLanguage= QLocale::system(); QLocale systemLanguage= QLocale::system();
qDebug("[Locale]");
qDebug("Language: %s (%d)", QLocale::languageToString(systemLanguage.language()).toUtf8().constData(), systemLanguage.language());
qDebug("Country is: %s (%d)", QLocale::countryToString(systemLanguage.country()).toUtf8().constData(), systemLanguage.country());
qDebug("Script is: %s (%d)\n", QLocale::scriptToString(systemLanguage.script()).toUtf8().constData(), systemLanguage.script());
//Check if we can use the default translation
if(systemLanguage.language() == QLocale::English /*|| systemLanguage.language() == QLocale::C*/) if(systemLanguage.language() == QLocale::English /*|| systemLanguage.language() == QLocale::C*/)
{ {
m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID); m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
return LAMEXP_DEFAULT_LANGID; return LAMEXP_DEFAULT_LANGID;
} }
//Try to find a suitable translation for the user's system language //Try to find a suitable translation for the user's system language *and* country
QStringList languages = lamexp_query_translations(); QStringList languages = lamexp_query_translations();
while(!languages.isEmpty()) while(!languages.isEmpty())
{ {
QString currentLangId = languages.takeFirst(); QString currentLangId = languages.takeFirst();
if(lamexp_translation_sysid(currentLangId) == systemLanguage.language()) if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
{ {
unsigned int script = lamexp_translation_script(currentLangId); if(lamexp_translation_country(currentLangId) == systemLanguage.country())
if((script == 0) || (systemLanguage.script() == 0) || (script == systemLanguage.script()))
{ {
m_defaultLanguage = new QString(currentLangId); m_defaultLanguage = new QString(currentLangId);
return currentLangId; return currentLangId;
@ -295,6 +300,18 @@ QString SettingsModel::defaultLanguage(void)
} }
} }
//Try to find a suitable translation for the user's system language
languages = lamexp_query_translations();
while(!languages.isEmpty())
{
QString currentLangId = languages.takeFirst();
if(lamexp_translation_sysid(currentLangId) == systemLanguage.language())
{
m_defaultLanguage = new QString(currentLangId);
return currentLangId;
}
}
//Fall back to the default translation //Fall back to the default translation
m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID); m_defaultLanguage = new QString(LAMEXP_DEFAULT_LANGID);
return LAMEXP_DEFAULT_LANGID; return LAMEXP_DEFAULT_LANGID;