For the sake of this question, imagine my application helps users to practice foreign languages.
They press a button to start the Text to Speech introduction, which speaks:
<string name="repeat_after_me" translatable="true">Repeat after me</string>
This string will be localised in the normal way, fetching the string from the appropriate res/values-lang/strings.xml
file according to the device Locale.
After the introduction, the app needs to speak any one of a random number of strings, in the language/locale of which they are currently wishing to learn. Herein lies the problem.
Assuming the Text to Speech starts from a simple method such as:
private void startLearning(Locale learningLocale)
And the pseudo code of:
TTS.speak(getString(R.string.repeat_after_me)
followed by:
TTS.speak(getRandomLearningString(learningLocale))
Where:
String getRandomLearningString(Locale learningLocale) {
// return a random string here
}
The above is where I'm stuck on how to best reference the xml resource, that contains the 'string-array' of the language the user is learning (in order to pick one at random).
<string-array name="en_EN" translatable="false">
<item>"Where is the nearest hospital?"</item>
<item>"What's the time please?"</item>
<item>"Only if you promise to wear protection and we have a safe word"</item>
</string-array>
Assuming I have a large number of strings for each language and I support a vast number of languages, the question:
How should I store these strings to keep them manageable and readable in development? How should I 'dynamically' reference them from a method?
To clarify - the main problem is not only how I resolve:
getStringArray(R.array.(variableLocale);
But also how/where I store these string arrays so that the implementation is scalable and organised.
I thank you in advance.
Edit - The actually Text to Speech implementation of switching languages is not a problem, I have that covered.