Reputation: 1469
I am developing one android application,
In that application i need to use 5 languages,
application lets user to choice different language. according to user select the language
for that what i have to do?
give me any suggestion for this.....
Upvotes: 3
Views: 16127
Reputation: 4063
I encountered the same problem: I needed to set my language to a language chosen in my app.
My fix was this:
Example:
String languageInitials = MyAppconfig.currentLanguageInitials();
if (languageInitials.equals("NL")) {
view = inflater.inflate(R.layout.mylayout_nl, container, false);
} else {
view = inflater.inflate(R.layout.fragment_mylayout_fr, container, false);
}
From these XML's, you can still extract the needed strings to resources.
Upvotes: 0
Reputation: 11
This is easy to do.. for example using spinner to select a language. See the following code...
public void onCreate(Bundle savedInstanceState) {
mTts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
}
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
ttsIsInit = true;
}
}
});
read.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mTts != null && ttsIsInit) {
mTts.speak(exitTextFound, TextToSpeech.QUEUE_FLUSH, null);
}
}
});
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
language = language_array[spinner.getSelectedItemPosition()];
if (language.equals("English US")) {
mTts.setLanguage(Locale.US);
} else if (language.equals("Francais")) {
mTts.setLanguage(Locale.FRANCE);
} else if (language.equals("Espanol")) {
mTts.setLanguage(new Locale("es"));
}
}
Upvotes: 1
Reputation: 2475
I think you should go for menus in your app in order to change (i.e to select) the languages.
On click of that menu buttons you have change corresponding strings.xml of that particular language.
For this please refer to my answer of following that thread. I think menu is best option to go for this.
Upvotes: 0