3

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.....

dilipkaklotar
  • 1,469
  • 3
  • 20
  • 28

4 Answers4

1

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"));
        }
    }
wattostudios
  • 8,666
  • 13
  • 43
  • 57
Hassan
  • 11
  • 1
0

I encountered the same problem: I needed to set my language to a language chosen in my app.

My fix was this:

  1. Keep your strings in your XML file, don't extract it to resources
  2. Make an exact copy of your XML and rename it to _languagecode, like _fr (use lowercase!)
  3. Fix your translations in your XML copy
  4. In code you check your app-level language and inflate the relevant XML

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.

TomCB
  • 3,983
  • 9
  • 40
  • 66
0

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.

Community
  • 1
  • 1
Shashank_Itmaster
  • 2,465
  • 5
  • 30
  • 56
0

You may provide localization. Please refer the site

Anju
  • 9,379
  • 14
  • 55
  • 94
  • yes Mathew i got it. but it will take more size when we use the 50 languages. at that time we have to create 50 different string.xml file and we have to create different drawable folder for each language this is not feasible solution when we want to use more language – dilipkaklotar Mar 07 '11 at 09:39
  • ok..will have to search then..in ur question, it was 5 languages.. :) – Anju Mar 07 '11 at 09:51
  • how did u do it?Please comment. – Anju Mar 07 '11 at 11:57
  • if we create different string.xml file for different different language then the problem will solve. use common image for drawable folder? – dilipkaklotar Mar 07 '11 at 12:08
  • 1
    if u have drawables for different languages, then u should put it into different folders like u did for strings. Default location is drawable. So if no image matches for the particular language, it takes the default image from drawable folder. You may refer the link which I have given in the answer too for more help. – Anju Mar 07 '11 at 12:23