0

I have localized my ap. I'm also using TextToSpeech to read some localized strings.

        speech.setLanguage(Locale.getDefault());

My problem is that if the user speaks for example italian, since the app is not localized to italian the interface falls back to english however TextToSpeech still uses the italian voice and pronunciation.

So basically:

  • If the user locale is US_en, UK_en or any other supported he needs to listen the corresponding voice or Locale.getDefault()
  • If the user locale is not supported the app interface will fall back to the strings.xml (which is in english) and I need TextToSpeak to use an English voice too

Any ideas how to do this?


I haven't found a way to know what language the app is currently using but I figured out I can get the language with Locale.getDefault().getLanguage() and compare it with AssetManager.getLocales(), but I haven't managed to call getLocales()

1
  • I think you are saving the user preferred locale in a SaredPreference, do you? If so, you can then re-read the preference key, say "lang" - which I suppose being "en" or "es" - on load. Finally, you can set your locale to that value. After setting you language by a PreferenceScreen you will have to restart your Activity, in order to reload the new locale Mar 22, 2014 at 19:27

1 Answer 1

0

This is what I'm doing now:

    String deviceLang = Locale.getDefault().getLanguage();
    speech.setLanguage(deviceLang.equals("en") || deviceLang.equals("es") ? Locale.getDefault() : Locale.US);

However I'm not happy with the fact that I have to keep it updated with the languages I'm supporting. A better solution would be to get app supported languages and compare it with deviceLang (this might be possible with AssetManager.getLocales() but I haven't managed to prove it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.