Runtime display image from french drawable if language changed to french - android

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.

Related

How to refresh a DrawerLayout after language change?

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?

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.

Language change on button click

stucked with one problem that in my application i have one button which is having text SPANISH on it. On the click of this button i want to change the whole application to Spanish language.
Locale mLocale = new Locale("es");
Locale.setDefault(mLocale);
Configuration config = getBaseContext().getResources().getConfiguration();
if (!config.locale.equals(mLocale))
{
config.locale = mLocale;
getBaseContext().getResources().updateConfiguration(config, null);
}
I also have created two separate Strings.xml file. but not got success.
I want to change the application language on button click.
Thanks
you have to call setContentView() after you change the locale

Categories

Resources