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);
Related
i was trying to localize my app with different languages everything works but the items on the drawer layout wont update to the new language unless the app is restarted heres the code i used to change the language.
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
c.getResources().updateConfiguration(config,c.getResources().getDisplayMetrics());
the variable lang being the language thats being set.
so is there any way i can refresh the drawer layout after the language is set?
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.
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
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 am developing an app with english and french language support.
If user change language , textview texts are changed.
But images in ImageView does not change.
If user selects language=='fr' image should be displayed from drawable-fr.
How to achieve this?
I am changing locale like:
Locale myLocale = new Locale(language);
// set the new locale
Locale.setDefault(myLocale);
Configuration config = new Configuration();
config.locale = myLocale;
getApplicationContext().getResources().updateConfiguration(config,
getApplicationContext().getResources().getDisplayMetrics());
I solved problem.
As user changes language,i was resetting image like iv.setImageResouse(R.drawable.asdf); in onRestart() method of previous activity.
But then i replaced this with iv.setImageDrawable(getResources().getDrawable(R.drawable.asdf));
This worked.