문제

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()

도움이 되었습니까?

해결책

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top