0

My problem is that i have a Diary application in which i am adding notes by selecting a particular date from Custom Calendar View. The problem starts when user changes his phone language from English to any other, If user has selected Japanese as his phone's new language, Month's name would be converted in Japanese language. Now i want that if user selects any other language other than English than also Month's name should be shown in English only. I searches a lot but could not find anything helpful.

Any positive response will be highly appreciated. Thanks.

Vaishali Sharma
  • 602
  • 3
  • 6
  • 24

1 Answers1

0

You should use custom calender and when you display your calendar change Locale(Language) to English programatically.

How to change Locale programatically in android.

Hope it helps you.

Edit :

You can change Language using following code :

public void changeLang(String lang)
{
    if (lang.equalsIgnoreCase(""))
     return;
    myLocale = new Locale(lang);
    saveLocale(lang);
    Locale.setDefault(myLocale);
    android.content.res.Configuration config = new android.content.res.Configuration();
    config.locale = myLocale;
    getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    updateTexts();
}

Call this method by passing your language Like :

changeLang("en");

Note : You must define your string in res/string.xml file for english language. And you should set your string from String.xml not static.

For example for your concern Your calendar Names are set like...

yourtextview.getResources().getString(R.string.january);
Community
  • 1
  • 1
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
  • Ok. i applied this code like this, Resources res = CalendarView.this.getResources(); // Change locale settings in the app. DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = new Locale("English"); res.updateConfiguration(conf, dm); This is my class for Custom Calendar, but still after selecting Chinese language from my phone setting, it's showing month's name in Chinese only. – Vaishali Sharma Nov 01 '13 at 11:35
  • No error, but Month's name aren't getting displayed in English – Vaishali Sharma Nov 01 '13 at 11:37
  • See this example : http://snowpard-android.blogspot.in/2013/03/programmatically-change-language-in.html – Hardik Joshi Nov 01 '13 at 11:44