diff options
author | Fabio Falsini <falsinsoft@gmail.com> | 2020-08-27 22:51:24 +0200 |
---|---|---|
committer | Fabio Falsini <falsinsoft@gmail.com> | 2020-09-08 12:52:36 +0200 |
commit | dd3639ae14b2956186e1131e7c772e2956434379 (patch) | |
tree | beeb88436c53516a811506faa69787c5049fdf2d /src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java | |
parent | 2151f3715c4f082fa32841a034d7cf3a2ae10533 (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>
Diffstat (limited to 'src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java')
-rw-r--r-- | src/plugins/tts/android/jar/src/org/qtproject/qt5/android/speech/QtTextToSpeech.java | 11 |
1 files changed, 10 insertions, 1 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() |