Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Multi Language support

Tags:

android

I am aware of Creating a new values directory for the language with the suffix of the language code. For german: values-de or french: values-fr then copy our string.xml into that and translate each entry. And this works based on the Phone Localization settings

I wanted to know if we can bypass the phone setting and and make the user select his required language inside the app?

My requirement is, i want to give a language selection option inside my app, and make the user select the language he wants for the app.. how to dynamically switch between the string.xml (for different languages) ???

thanks in advance

like image 749
amithgc Avatar asked Oct 26 '10 09:10

amithgc


People also ask

What is multiple language support?

Multilingual support extends the customer support experience to people who don't speak English, or who are more comfortable conversing in another language. The service works by offering your customers a language choice when they call your support line or browse to your company website.

What is multi language in Android?

In android, Localization is a process to change the string into multiple languages based on our requirements.

How can I add multiple languages to my website?

Google Translate It is by far the easiest and more common way to add multiple language support to your website. To add Google Translate to your site, you simply sign up for an account and then paste a small bit of code to the HTML.


2 Answers

Create method which sets your basic Locale.Lets say

public static void setDefaultLocale(Context context,String locale) {
        Locale locJa = new Locale(locale);
        Locale.setDefault(locJa);

        Configuration config = new Configuration();
        config.locale = locJa;

        context.getResources().updateConfiguration(config, context.getResources()
                .getDisplayMetrics());

        locJa = null;
        config = null;
    }

Now check when user selected Locale.(Here basically I have used menu for language selection).

Configuration config = new Configuration();
String newLocale = config.locale.getLanguage().substring(0, 2)
    .toLowerCase();
if ("ja".equalsIgnoreCase(newLocale)) {
// Call above method with context & newLocale
} 
// Sequentially you check for Locale & change that.
like image 55
Shashank_Itmaster Avatar answered Oct 21 '22 13:10

Shashank_Itmaster


Check out this post... It is the same thing basically.

Changing Locale within the app itself

Locale appLoc = new Locale("en");
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
getBaseContext().getResources().updateConfiguration(appConfig,
    getBaseContext().getResources().getDisplayMetrics());
like image 43
Anthony Graglia Avatar answered Oct 21 '22 15:10

Anthony Graglia