summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Falsini <falsinsoft@gmail.com>2020-08-27 22:51:24 +0200
committerFabio Falsini <falsinsoft@gmail.com>2020-09-08 12:52:36 +0200
commitdd3639ae14b2956186e1131e7c772e2956434379 (patch)
treebeeb88436c53516a811506faa69787c5049fdf2d
parent2151f3715c4f082fa32841a034d7cf3a2ae10533 (diff)
Wrong tts current language parsing on some Android devices
Current implementation for getting the current tts language selected in Android gets the output of toString() to create a QLocale object. However there is no guarantee that these calls will return two-digit codes as required by the QLocale constructor. For example, a Samsung s10e device returns three-digit codes ("eng" instead of "en") which causes the instantiated QLocale object to return a generic "C" language instead of the real locale. This patch checks if the language and country code is two-digit or three-digit and, in the second case, convert the three-digit code into two-digit code to allow QLocale to be initialized correctly. Pick-to: 5.15 Change-Id: I50163ffca57a031028e75a488d2b29ea7e9cdf4f Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-rw-r--r--src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java11
-rw-r--r--src/plugins/tts/android/src/qtexttospeech_android.cpp7
2 files changed, 15 insertions, 3 deletions
diff --git a/src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java b/src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java
index b50d748..f6f440c 100644
--- a/src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java
+++ b/src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java
@@ -253,7 +253,16 @@ public class QtTextToSpeech
public Locale getLocale()
{
//Log.d("QtTextToSpeech", "getLocale: " + mLocale);
- return mTts.getLanguage();
+ final Locale language = mTts.getLanguage();
+ String languageCode = language.getLanguage();
+ String countryCode = language.getCountry();
+
+ if (languageCode.equals(language.getISO3Language()))
+ languageCode = convertLanguageCodeThreeDigitToTwoDigit(languageCode);
+ if (countryCode.equals(language.getISO3Country()))
+ countryCode = convertCountryCodeThreeDigitToTwoDigit(countryCode);
+
+ return new Locale(languageCode, countryCode);
}
public Object getVoice()
diff --git a/src/plugins/tts/android/src/qtexttospeech_android.cpp b/src/plugins/tts/android/src/qtexttospeech_android.cpp
index aaed7f1..76d6573 100644
--- a/src/plugins/tts/android/src/qtexttospeech_android.cpp
+++ b/src/plugins/tts/android/src/qtexttospeech_android.cpp
@@ -286,8 +286,11 @@ QLocale QTextToSpeechEngineAndroid::locale() const
{
auto locale = m_speech.callObjectMethod("getLocale", "()Ljava/util/Locale;");
if (locale.isValid()) {
- auto localeName = locale.callObjectMethod<jstring>("toString").toString();
- return QLocale(localeName);
+ auto localeLanguage = locale.callObjectMethod<jstring>("getLanguage").toString();
+ auto localeCountry = locale.callObjectMethod<jstring>("getCountry").toString();
+ if (!localeCountry.isEmpty())
+ localeLanguage += QString("_%1").arg(localeCountry).toUpper();
+ return QLocale(localeLanguage);
}
return QLocale();
}