The following code is for changing app locale into Spanish is working fine in some devices, but in some devices it is enlarging (zooming) the views in the app. Does anyone have a the solution?
Configuration config = getResources().getConfiguration();
// change this to a different Locale than your device
Locale locale = new Locale("es", "es_ES");
config.locale = locale;
Locale.setDefault(locale);
getBaseContext().getResources().updateConfiguration(config, getResources().getDisplayMetrics());
Log.i("onSelected..", Locale.getDefault().getCountry());
startActivity(new Intent(getApplicationContext(), HomePage.class));
finish();
Android App Development for Beginners In order to make your application more interactive, your application should handle text,numbers,files e.t.c in ways appropriate to the locales where your application will be used. The way of changing string into different languages is called as localization.
You'll find this screen either in the System Settings app: Languages, or System Settings: System: Languages and input. The Language preference screen should contain one entry called “English (Europe)”. Click Add language and add a fallback language.
The default Locale is constructed statically at runtime for your application process from the system property settings, so it will represent the Locale selected on that device when the application was launched.
App localization is the process of changing and refining an app in order to appeal to a geographically specific target market. You want to make sure that your app is as appealing and easy to use outside your headquarters' country as it is within.
I use this method when i have to use different languages:
1) Set a int for all the languages supported. 2) Use a basic function to set Default Locale. 3) Use a function to launch in different languages.
This is the example:
2)
public static void setDefaultLocale(Context context,String locale)
{
Locale appLoc = new Locale(locale);
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
context.getResources().updateConfiguration(appConfig, context.getResources()
.getDisplayMetrics());
}
where locale follow the ISO 639-1
1)
private Language myLanguage;
public enum Language
{
Null,Spanish,English,Catalan
}
3)
private void launchApplication(int language)
{
// Set Language
switch (language)
{
case 1:
// Español
setDefaultLocale(getApplicationContext(),"es");
myLanguage = Language.Spanish;
break;
case 2:
// English
setDefaultLocale(getApplicationContext(),"en");
myLanguage = Language.English;
break;
default:
// Catalan
setDefaultLocale(getApplicationContext(),"ca");
myLanguage = Language.Catalan;
break;
}
Intent intent = new Intent(this, MyActivity.class);
startActivityForResult(intent, 2);
// Finish the Activity when return from the other Activity
finish();
}
Then, call launchApplication(int selected); and must be work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With