Domanda

I have an Android application which I wrote for english language now I want to convert it to farsi/persian language. I want to know how can i type persian text for the TextView text.How can i maintain both the english and persian String.xml.please help.

cheers Zolf

Locale locale = new Locale("fa-IR"); 
    Locale.setDefault(locale); 
    Configuration config = new Configuration(); 
    config.locale = locale; 
    getBaseContext().getApplicationContext().getResources().updateConfiguration(config, null); 

where do i put this code,now i put this code in the OnCreate and it does not change the text of the TextView to persian

È stato utile?

Soluzione

For showing correct form of Persian characters use this solution.

Update

And for changing current resources that is loaded in your UI:

tf = Farsi.GetFarsiFont(this);

tvTitle01 = (TextView) findViewById(R.id.tvTitle01);
tvTitle01.setTypeface(tf);
tvTitle01.setText(Farsi.Convert(tvTitle01.getText().toString()));

Altri suggerimenti

Android has built-in mechanism of localization.

http://developer.android.com/guide/topics/resources/localization.html

you can create the different folder of values as per language and can keep different string.xml file for each language. Example:

res/values/strings.xml Contains English text for all the strings that the application uses, including text for a string named title.

res/values-fr/strings.xml Contain French text for all the strings, including title.

res/values-ja/strings.xml Contain Japanese text for all the strings except title.

If your Java code refers to R.string.title, here is what will happen at runtime:

If the device is set to any language other than French, Android will load title from the res/values/strings.xml file.

If the device is set to French, Android will load title from the res/values-fr/strings.xml file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top