Android: Change number format for the whole application? - android

In Android we can change the applications locale like this:
Locale locale = new Locale("ar","EG");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
and we can format the number to display digits according to a certaub locale like this:
NumberFormat nf=NumberFormat.getInstance(new Locale("ar","EG"));
nf.format(numberString);
I'm wondering if there is a way to just change the locale for the number format for the whole application without changing the application's locale? in other words is there a way to set the application's locale to "en-US" while set the number format only to "ar-EG"? is that possible?

Related

android Google Map language as Locale language

As Google-Map App in our phone shows the different languages as per region with English.
I want to implement same in my app also.
But i can not do this in android.
can you please help me to get out of it.
Set Google Map language as Locale language
https://developers.google.com/maps/documentation/javascript/basics?csw=1#Localization
https://developers.google.com/maps/documentation/javascript/localization
Please check this link What is the list of supported languages/locales on Android? for supported language.
&
you can do this by simply changing the Locale of your application like this in your Splash or where you loading the maps.
String languageToLoad = "ar";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
Hope this may help you.

Ignore phone's locale and always use English as locale

Is there a way to force using english as the locale for my android app even if the phone's locale is something other that english? The reason I want to do this is that I don't want my UI to change orientatoin from ltr to rtl.
this line
mStrLocale = Locale.getDefault().getLanguage();
will return your current language, lets say EN-US
and with this you can hardcode your locale
Locale locale = new Locale("ru");
Locale.setDefault(locale);
Configuration config = getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
and we use Configuration because of this
This class describes all device configuration information that can
impact the resources the application retrieves. This includes both
user-specified configuration options (locale list and scaling) as well
as device configurations (such as input modes, screen size and screen
orientation).
is stated at this doc https://developer.android.com/reference/android/content/res/Configuration.html

Android time picker dialog language changed from Locale setting

I am using two languages in app, English and Swedish.
I have used below code for managing language change by user,
final Locale locale;
if (languagecode == 1)
{
locale = new Locale("sv");
}
else
{
locale = new Locale("en");
}
Locale.setDefault(locale);
final Configuration config = new Configuration();
config.locale = locale;
mContext.getResources().updateConfiguration(config, mContext.getResources().getDisplayMetrics());
Now when I show Time picker dialog with Swedish language selected as default, it shows swedish translation in dialog, it also changes the AM/PM text. Is there any way to put custom text over there or it comes as system default? Please check the image below for reference. Thanx.
There is a tutorial here for customizing time pickers. You can define the title for example as a string resource and then create separate resource folders for translations (more info on localization here).

How to change device locale language setting of device?

I want to convert my android project to multiple language. I have created a list view where different languages are going to be shown. I want to change the device language when I select any item from this list. How can I do this?
You can change the the Language like this
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);

EditText in Spanish

I have the following EditText:
EditText et1 = (EditText) findViewById(R.id.txtSp);
When user types in this EditText, it should display text in Spanish instead of English.
How can I achieve this?
Note: My application's language is English.
You can change the locale at runtime using that code:
Resources res = getApplicationContext().getResources();
Locale locale = new Locale("en"); //<--- use your locale code here
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
I assume you need to reset your layout afterwards too.
According to this post, it is not possible to change the locale for a currently running app.
Google Groups -> Android Developers
The "DH" that Richard mentions in this post is an Android Framework Engineer. Look at Richard's previous post for a link to her comments.

Categories

Resources