Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change language of whole application by only single click?

I have a Spinner with three language choice on login page. I want when user choose one language suppose "Persian" language the language of whole application should change. I am able to change language of current Activity only. How can I change the language of whole application.

like image 248
Abhishek Bhardwaj Avatar asked Apr 08 '17 08:04

Abhishek Bhardwaj


People also ask

Can I change the language of a single app Android?

Check into the modules, you will get to see all apps list that is installed on your Android phone. Step 4: Select one of the app which you want to edit the language. With the help of the app interface, choose the desired language from the given options and click on the confirm button.

How do I change the default language in Android Studio?

In the Preferences menu -> Editor -> Spelling : You can add a custom dictionary. Your language.

How do I add a second language to my Windows system?

First things first; add a second language to your Windows system. On Windows 10, you can add a second language from the Settings app. Go to the Time & Language group of settings and select the Region & Language tab. Click Add language and select the one you want to add. You may have to restart Windows to complete the process.

How do I change the language of an application?

In order to change the language of a given application independently of the operating system language you need to edit its resources. Just go through the following steps: Go to C:\Program Files or C:\Program Files (x86) on Vista. Locate and open the directory of the application you want to change the language of.

How to add a new language to your Android app?

Now, we are ready to add a new language to our app. Follow the below steps to do so: 1 Right Click on res > New > Android Resource File 2 Put the file name as strings.xml 3 Select the option of Locale More ...

How do I switch between languages in Windows 7?

Long before Windows 7, users could add multiple languages and easily switch between them. Switching between a language, or toggling between languages if you have more than 2 configured is pretty easy. You can use the Left Alt + Shift keyboard shortcut to change languages on the fly.


1 Answers

Change Language Programmatically in Android

Here is the appropriate way of changing the locale of the application:

There are some difficulties which you have to overcome to change the language programmatically.

1.)Your application will not remember your language change after it is closed or recreated during the configuration change.

2.)You should update currently visible UI properly according to the selected language.

Solution

LocaleHelper” is the solution all you need. You just have to initialize locale on your application’s main class. After that all your language changes will persist.

After the recent changes in Android API Version 24(Nougat) we need to override attachBaseContext to reflect changes.

Below method used to change language for application :

private static boolean updateResources(Context context, String language) {
    Locale locale = new Locale(language);
    Locale.setDefault(locale);

    Resources resources = context.getResources();

    Configuration configuration = resources.getConfiguration();
    configuration.locale = locale;

    resources.updateConfiguration(configuration, resources.getDisplayMetrics());

    return true;
}

find more details in below link :

Changing Android’s Locale Programmatically

like image 174
Chetan Joshi Avatar answered Oct 17 '22 00:10

Chetan Joshi