开发者

android Application language change

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


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"));
        }
    }


You may provide localization. Please refer the site


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜