1

I have some label in the manifest file which has english text how can i have them in other languages also.for e.g.

<activity
        android:name=".activity.MainMenuActivity"
        android:label="Main Menu Options" 
        android:configChanges="locale" 
        >
    </activity>

I want to covert the lable to persian text.how can i do it.please help.

ZAJ
  • 793
  • 3
  • 23
  • 50

2 Answers2

1

Just add your label value in strings.xml for exemple:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- String Resources -->
    <string name="main_menu_activity">جرای برنامه نمی‌توان</string>

</resources>

and call in your manifest android:label="@string/main_menu_activity"

Edit: For menu item use it like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
   <item
      android:id="@+id/add"
      android:icon="@android:drawable/ic_menu_add"
      android:title="@string/mu_title_1"/>

   <item
      android:id="@+id/help"
      android:icon="@android:drawable/ic_menu_help"
      android:title="@string/mu_title_2"/>
</menu>
K_Anas
  • 31,226
  • 9
  • 68
  • 81
  • you see i have 2 folders values and values-fa. when i set the locale to fa,the app should go and read from the values-fa folder,but it does not. – ZAJ Jul 07 '12 at 06:27
  • @ZAJ I think farsi language is supported in api 4.1, if you are using a api below 4.1 you will not get it work – K_Anas Jul 07 '12 at 06:28
  • in the output of the code i posted before prints this when i run the app.which indicates it is understanding it is frsi06-28 10:12:27.933: I/System.out(3042): My locale::English 06-28 10:12:27.953: I/System.out(3042): My locale::فارسی – ZAJ Jul 07 '12 at 06:30
  • @ZAJ have you tried another language, like french for exemple? – K_Anas Jul 07 '12 at 06:37
  • can i show the title on the right side,nw it is on the left. something like this---android:layout_gravity="right – ZAJ Jul 07 '12 at 08:40
  • @ZAJ you can customize the title how you like see those links http://stackoverflow.com/questions/3438276/change-title-bar-text-in-android http://stackoverflow.com/questions/2416844/how-to-set-custom-title-bar-textview-value-dynamically-in-android – K_Anas Jul 07 '12 at 08:59
  • @ZAJ same way load your title menu from your resources and set it to your menu item – K_Anas Jul 07 '12 at 09:01
  • can you please give me e.g. i will appreciate it – ZAJ Jul 07 '12 at 09:06
  • @ZAJ and here a tutorial on OptionsMenu – K_Anas Jul 07 '12 at 09:15
  • where is the tutorial??i dont see any link.by the way i am using this to assign farsi text to my widgets. tvCusAddr = (TextView) findViewById(R.id.cusaddrTV); tvCusAddr.setTypeface(tf); tvCusAddr.setText(Farsi.Convert(tvCusAddr.getText().toString())); now when i use setTitle(R.string.mainmenuActivity); how do i assign its farsi text. the problem i have is that if i directly enter the farsi text in the String.xml,the text does not show properly.there is space in between each character – ZAJ Jul 07 '12 at 09:21
  • http://androidresearch.wordpress.com/2012/03/06/android-optionsmenu-tutorial/ sorry – K_Anas Jul 07 '12 at 09:24
  • i know how to create optionmenu.i have it now whichis working.what i am looking for is to change the text of the option menu from english to farsi.i have two option menu in my activity which i want to change its text to farsi. – ZAJ Jul 07 '12 at 09:30
0

Put the label in String.xml in values folder and use the string like app name

android:label="@string/my_label"

Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
  • i do that but it is not reading from my values-fa folder's String.xml.any idea why – ZAJ Jul 07 '12 at 06:16
  • Because, you have to set locale to make it read from particular lang file – AAnkit Jul 07 '12 at 06:19
  • 'System.out.println("My locale::"+Locale.getDefault().getDisplayLanguage()); Locale locale = new Locale("fa"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); Toast.makeText(this, "Locale in Persian !", Toast.LENGTH_LONG).show(); System.out.println("My locale::"+Locale.getDefault().getDisplayLanguage());' – ZAJ Jul 07 '12 at 06:24