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.
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.
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).
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.
I'm trying to change the language of the whole system of Android Phone on my application, cause our goal is to customized a Settings application.
I've tried this, but didn't work:
Configuration conf = Resources.getSystem().getConfiguration();
conf.locale = toSet; //toSet is a Locale which I want to set to the system
conf.setToDefaults();
the other try didn't work either:
Locale.setDefault(toSet)
There are ways to change the language of application, but not systems.
Is there any ways that I can reach the goal?
Will getting the root permissions works for me?
Or is there any ways to modify the UI interface of the Intent-Activity?
I've found that, in the source code, "platform/packages/apps/Settings/src/com/android/settings/LocalePicker.java", "com.android.internal.app.LocalePicker" might help, and in the "platform/frameworks/base/core/java/com/android/internal/app", there is a function which named "updateLocale", I guess it might help, but the class such as "IActivityManager" cause compile error in the Eclipse.
Does anyone have any ideas? Thanks!
try this
String languageToLoad = "zh";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, null);
AndroidManifest:
add android:configChanges="locale"
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