Match DatePickerDialog button order to device locale on Android - android

The button order on all DatePickerDialog in my app isn't affected by the device's locale. If, for example, I change my locale to a right-to-left aligned language, such as Hebrew or Arabic, the button order on all other apps on my device automatically changes but remains the same on my own app! Why is that? And how can I tell my app to "adapt" to the newly selected locale and change the button order accordingly?
This is driving me crazy. Any help or hint you can provide will be greatly appreciated. Thanks...

You can use getDefault() to get an appropriate locale for the user of the device you're running on. Then try to apply the locale to the config.
Locale locale = Locale.getDefault();
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
I don't know if the code snippet above works on your case. But you might give it a try.

Related

Locale: App's Current Language

How to programatically find the language the app is using. For example the device Locale is set to es_MX but my app supports only en_US and hence the app displays text only in English.
How to programatically find that app is using English and not Spanish in this case?
All the below code returns ex_MX
Locale locale = getResources().getConfiguration().getLocales().get(0);
Locale l = Resources.getSystem().getConfiguration().getLocales().get(0);
Locale l1 = Locale.getDefault();
Please Refer this given link's answer as you must get locale at the time of starting the app. If you will set your locale once in whole life cycle, you will get only the language as default as you set in the locale.
https://stackoverflow.com/a/23556454/6549856
You can get the system language.
Resources.getSystem().getConfiguration().locale.getLanguage();
for app default language
String CurrentLanguage = Locale.getDefault().getLanguage();

how to change supportsRtl value inside the app

as i know if we set android:supportsRtl="true" in manifest the app will change it's direction based on default language of the phone ..my problem is that lot's of people in my country set their default language to English whereas they know a little about English an if they open app and see the application language is English they will definetly remove the app .. so my question is is there any way to change the value inside the app . and i give them the option to change language at the beggening of the app or in setting .. ty
you can use below code to set language for app, this is for english, replace the en with you language:
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
in manifest file write android:configChanges="locale".
You can give them to choose language at any time, but remember all activities language are change except current activity, you have to restart current activity.

Is possible to set only default English language of application in android

I only want set only default English language of application in android.
After Supporting Different Languages, I also use values/strings.xml to store characters in that file.
If in English language mode of System Settings, I can show correct words.
If in Chinese language mode of System Settings, The English words was translated to Chinese.
I don't want it translate automatically.
People who know how to set only default English language,
Please help me.
Thanks,
I can get correct answer now via the codes in below :
public static void setDefaultLanguage(Context context, String lang) {
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
In that, what is lang value? You should get correct Language System to pass this value to lang parameter.
Thanks,
Are you storing all the strings for both languages in one .xml? If so that is probably your issue…
res/values/strings.xml
Contains English text for all the strings that the application uses,
res/values-ja/strings.xml - for japanese, but I am sure you can find one for the language you are looking for! Android looks for the "values-ja" tag.

Regarding Android Application Language

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

How can I change between language in a single IME?

I am trying to make a Korean IME, but I can't find a good example.
How can I change between languages in a single IME?
I mean, like in Apple's IME, which uses a globe icon to switch between languages.
You can do it one of two ways. The first way is to just change the keyboard layout. There's no rule that says the language on the keyboard has to match the onscreen language. An example of this is Swype- it allows you to chang the language of the keyboard without changing the language of the rest of the UI, useful for bilingual typers. This is totally internal to your app, so you just need to track the keyboard language and show the correct key layout.
The other way is to set the phone's locale. The disadvantage to this is that it will change the language used inside of the app, and all other apps. To do this, use
Locale locale = new Locale(languageCode);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());

Categories

Resources