Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable localization in Android application

Is there any way to disable localization in an Android application? It must use only English strings. We have library projects with French localized strings. Some apps that use these libraries must be in English only, some not.

like image 922
user1031477 Avatar asked Jun 13 '12 11:06

user1031477


People also ask

What is localization in Android app?

Localization of Android apps is the process of adapting a mobile app for people who speak different languages or live in different countries. You probably want your app to grow and be used by more people than just those in your local area. You want it to reach people on other continents and eventually go global.

How do I change localization in Android?

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.

What is localization in mobile application?

App localization is the process of adapting your app and its app store listing to appeal to different geographic target markets. It's absolutely necessary if you want to take your mobile app or game global.

What is localization and why is it essential in Android?

Language Localization is a process to change the application context into multiple languages based on the requirements. Android is an overall operating system that runs on millions of devices worldwide and among various groups.


1 Answers

2019 - Gradle-based approach

As pointed out by Nidhin in their answer, this is easier and less error prone now than it was in 2012. In the defaultConfig section of the android section of your build.gradle file, you can set resConfigs to the single language you support. For example:

android {
    defaultConfig {
        resConfigs "en"
    }
}

This isn't just for disabling localization—resConfigs simply tells the build system which resources to keep. It can be set to a single language, or ideally to many, and it can be used to filter resources by something other than language, like screen density, as well. As such, saying "only include the English resources" effectively forces the app to always be in that language.

The programmatic way of loading the resources for a specific language is still sometimes useful, so my 2012 answer is still provided:

2012 - Programmatic approach

Doing the following before calling setContentView() or anything else that loads locale-specific resources should ensure that you always load only the English strings.

Resources res = getApplicationContext().getResources();

Locale locale = new Locale("en");
Locale.setDefault(locale);

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

res.updateConfiguration(config, res.getDisplayMetrics());
like image 162
Darshan Rivka Whittle Avatar answered Sep 20 '22 20:09

Darshan Rivka Whittle