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
Related
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.
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?
I have a localized string resource A. I noticed that after I clear app data/cache (under setting), and open my activity (which belongs to that app), I always see resource A in en locale regardless of the current device language. If I go to setting again, change device language manually to whatever, and go back to my activity, then resource A is localized properly again.
I wondering why locale is set to default after app data/cache is cleared and is there a way to fix this? Thanks.
This is a hacky solution but you could set the locale in the launcher activity like this:
Configuration config = res.getConfiguration();
Configuration configuration = new Configuration();
config.locale = config.locale;
getBaseContext().getResources().updateConfiguration(configuration,
getBaseContext().getResources().getDisplayMetrics());
You can also check the device locale to be absolutely sure that the device locale has changed.
When I use
locale = new Locale("ar");
the screen is mirrored in the right way.
In order to give the option to set the numeric system, i have to use the Locale.Builder() inserted with lollipop.
locale = new Locale.Builder().setLanguage("ar").setRegion("MA").setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-latn").build();
The problem is that in this way the screen is not mirrored properly.
There is a way, like an Extension, to set the rtl attribute?
SOLUTION:
In order to mirror the screen properly, you have to use the Configuration.
Configuration config = new Configuration();
config.locale = locale;
config.setLayoutDirection(new Locale("ar"));
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);