Commit 556df29c authored by Holger Kaelberer's avatar Holger Kaelberer
Browse files

core: fix locale handling for voices

For voices we need to be more specific with locale-names as we provide
some voices-packages that are territory/country-specific. So far we
used pt for pt_BR and could not resolve zh_CN correctly.

Therefore we added a new helper, ApplicationInfo::getVoicesLocale()
that returns a correct voices locale name and expects as input a
locale of the form <language>_<country>.

This is used then for voices-downloads as well as for
getAudioFilePath().
parent 8217eef6
......@@ -143,7 +143,7 @@ function initLevel() {
if (GCompris.ApplicationSettings.isAudioVoicesEnabled &&
GCompris.DownloadManager.haveLocalResource(
GCompris.DownloadManager.getVoicesResourceForLocale(
GCompris.ApplicationInfo.localeShort))) {
GCompris.ApplicationSettings.locale))) {
items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices/$LOCALE/misc/click_on_letter.ogg"));
items.audioVoices.silence(100)
playLetter(currentLetter)
......
......@@ -140,10 +140,10 @@ QString ApplicationInfo::getFilePath(const QString &file)
QString ApplicationInfo::getAudioFilePath(const QString &file)
{
QString localeShortName = localeShort();
QString localeName = getVoicesLocale(ApplicationSettings::getInstance()->locale());
QString filename = file;
filename.replace("$LOCALE", localeShortName);
filename.replace("$LOCALE", localeName);
return getResourceDataPath() + "/" + filename;
}
......@@ -206,9 +206,19 @@ void ApplicationInfo::notifyFullscreenChanged()
m_window->showNormal();
}
// return the short locale name for the given locale
QString ApplicationInfo::getLocaleShort(const QString &locale) {
return localeShort(locale);
// return the shortest possible locale name for the given locale, describing
// a unique voices dataset
QString ApplicationInfo::getVoicesLocale(const QString &locale)
{
QString _locale = locale;
if(_locale == GC_DEFAULT_LOCALE) {
_locale = QLocale::system().name();
}
// locales we have country-specific voices for:
if (_locale.startsWith("pt_BR") || _locale.startsWith("zh_CN"))
return QLocale(_locale).name();
// short locale for all the rest:
return localeShort(_locale);
}
QObject *ApplicationInfo::systeminfoProvider(QQmlEngine *engine,
......
......@@ -139,13 +139,14 @@ public:
static QString GCVersion() { return VERSION; }
static QString QTVersion() { return qVersion(); }
Q_INVOKABLE QString getVoicesLocale(const QString &locale);
protected slots:
void notifyPortraitMode();
QString getResourceDataPath();
Q_INVOKABLE QString getAudioFilePath(const QString &file);
Q_INVOKABLE QString getLocaleFilePath(const QString &file);
Q_INVOKABLE QString getLocaleShort(const QString &locale);
Q_INVOKABLE QStringList getSystemExcludedFonts();
Q_INVOKABLE QStringList getFontsFromRcc();
Q_INVOKABLE void notifyFullscreenChanged();
......
......@@ -321,12 +321,11 @@ Rectangle {
property bool haveLocalResource: false
function localeChanged() {
var localeShort =
ApplicationInfo.getLocaleShort(dialogConfig.languages[languageBox.currentIndex].locale);
var language = dialogConfig.languages[languageBox.currentIndex].text;
voicesText.text = language;
voicesRow.haveLocalResource = DownloadManager.haveLocalResource(
DownloadManager.getVoicesResourceForLocale(localeShort));
DownloadManager.getVoicesResourceForLocale(
dialogConfig.languages[languageBox.currentIndex].locale));
}
Connections {
......@@ -364,10 +363,8 @@ Rectangle {
style: GCButtonStyle {}
onClicked: {
var localeShort =
ApplicationInfo.getLocaleShort(dialogConfig.languages[languageBox.currentIndex].locale);
if (DownloadManager.downloadResource(
DownloadManager.getVoicesResourceForLocale(localeShort)))
DownloadManager.getVoicesResourceForLocale(dialogConfig.languages[languageBox.currentIndex].locale)))
{
var downloadDialog = Core.showDownloadDialog(dialogConfig, {});
}
......@@ -579,8 +576,7 @@ Rectangle {
if (ApplicationSettings.locale != dialogConfig.languages[languageBox.currentIndex].locale) {
ApplicationSettings.locale = dialogConfig.languages[languageBox.currentIndex].locale
if (!DownloadManager.haveLocalResource(
DownloadManager.getVoicesResourceForLocale(
ApplicationInfo.localeShort)))
DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale)))
{
// ask for downloading new voices
var buttonHandler = new Array();
......@@ -589,7 +585,7 @@ Rectangle {
buttonHandler[StandardButton.Yes] = function() {
// yes -> start download
if (DownloadManager.downloadResource(
DownloadManager.getVoicesResourceForLocale(ApplicationInfo.localeShort)))
DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale)))
var downloadDialog = Core.showDownloadDialog(main, {});
};
dialog = Core.showMessageDialog(dialogConfig,
......@@ -600,7 +596,8 @@ Rectangle {
buttonHandler
);
} else // check for udpates or/and register new voices
DownloadManager.updateResource(DownloadManager.getVoicesResourceForLocale(ApplicationInfo.localeShort))
DownloadManager.updateResource(
DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale))
}
}
......
......@@ -112,10 +112,13 @@ void DownloadManager::abortDownloads()
}
}
/** Helper generating a relative voices resources file-path for a given locale*/
/** Helper generating a relative voices resources file-path for a given locale
*
* @param locale Locale name string of the form <language>_<country>. */
QString DownloadManager::getVoicesResourceForLocale(const QString& locale) const
{
return QString("data/voices/voices-%1.rcc").arg(locale);
return QString("data/voices/voices-%1.rcc").arg(
ApplicationInfo::getInstance()->getVoicesLocale(locale));
}
/** Transform the passed relative path to an absolute resource path of an
......@@ -511,7 +514,7 @@ bool DownloadManager::registerResource(const QString& filename)
emit resourceRegistered(relPath);
QString v = getVoicesResourceForLocale(
ApplicationInfo::getInstance()->localeShort());
ApplicationSettings::getInstance()->locale());
if (v == relPath)
emit voicesRegistered();
return false;
......@@ -529,7 +532,7 @@ bool DownloadManager::isResourceRegistered(const QString& resource) const
bool DownloadManager::areVoicesRegistered() const
{
QString relFilename = getVoicesResourceForLocale(
ApplicationInfo::getInstance()->localeShort());
ApplicationSettings::getInstance()->locale());
return isResourceRegistered(relFilename);
}
......
......@@ -198,7 +198,7 @@ function checkForVoices(parent)
{
if (!GCompris.DownloadManager.haveLocalResource(
GCompris.DownloadManager.getVoicesResourceForLocale(
GCompris.ApplicationInfo.localeShort))) {
GCompris.ApplicationSettings.locale))) {
var buttonHandler = new Array();
var dialog;
buttonHandler[Dialog.StandardButton.Ok] = function() {};
......
......@@ -141,7 +141,7 @@ int main(int argc, char *argv[])
if(!loadAndroidTranslation(translator, locale))
loadAndroidTranslation(translator, ApplicationInfo::localeShort(locale));
#else
if(!translator.load("gcompris_" + locale, QString("%1/%2/translations").arg(QCoreApplication::applicationDirPath(), GCOMPRIS_DATA_FOLDER))) {
qDebug() << "Unable to load translation for locale " <<
locale << ", use en_US by default";
......@@ -157,7 +157,7 @@ int main(int argc, char *argv[])
// Register voices-resources for current locale, updates/downloads only if
// not prohibited by the settings
DownloadManager::getInstance()->updateResource(DownloadManager::getInstance()
->getVoicesResourceForLocale(ApplicationInfo::localeShort(locale)));
->getVoicesResourceForLocale(locale));
QQmlApplicationEngine engine(QUrl("qrc:/gcompris/src/core/main.qml"));
QObject::connect(&engine, SIGNAL(quit()), DownloadManager::getInstance(),
......
......@@ -102,7 +102,7 @@ Window {
buttonHandler[StandardButton.Yes] = function() {
// yes -> start download
if (DownloadManager.downloadResource(
DownloadManager.getVoicesResourceForLocale(ApplicationInfo.localeShort)))
DownloadManager.getVoicesResourceForLocale(ApplicationSettings.locale)))
var downloadDialog = Core.showDownloadDialog(main, {});
};
buttonHandler[StandardButton.No] = function() {};
......@@ -113,8 +113,8 @@ Window {
qsTr("Have Fun!") +
"\n" +
qsTr("Your current language is %1 (%2).")
.arg(Qt.locale(ApplicationInfo.localeShort).nativeLanguageName)
.arg(ApplicationInfo.localeShort) +
.arg(Qt.locale(ApplicationSettings.locale).nativeLanguageName)
.arg(ApplicationSettings.locale) +
"\n" +
qsTr("Do you want to download the corresponding sound files now?"),
StandardIcon.Information,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment