Enable per-app language preference for your project

New feature in Android 13+

This week I've been working on a course I'm preparing for a famous online academy in English (I'll be able to tell you more about it in a few weeks).

The course is about localization in Jetpack Compose, and one of the sections (which doesn't really have anything to do with Compose) involves activating app-specific localization settings.

You might not be aware, but since Android 13 (API 33), it's possible to select a language for each individual app, which can differ from the device's set language.

This allows users not to use the same language for every app. You might prefer using certain apps in one language, but choose a different one for others.

It's an unusual scenario, I know, and as of now, I can't think of many reasons to use it, but if it exists, there must be a reason for it 😄

This feature comes with a slight hitch: it's not enabled by default, the app has to activate it.

The good news is that it's very straightforward, and I'm going to show you how. It only requires two simple steps.

Step 1: Modify the build.gradle(.kts)

Add the following inside the android block:

androidResources {
    generateLocaleConfig = true
}

This will help the Android plugin generate the necessary configuration to enable this feature. There's a manual way to configure it, but I wouldn't recommend it.

Step 2: Create the resources.properties file

In the res folder, create a file with that name and add the following content:

unqualifiedResLocale=en

Actually, here you need to specify which language you have in the folder without language qualifiers (in values). It's typically English, but if you have another language, mention it here.

Now you can run the app, and if you go to the app's settings in Settings/Apps, you'll see the language option:

If you click on it, you'll be able to select a language that will only apply to this app:

I hope this content helped you learn something new today, and I'll see you next week.

See you!

Reply

or to participate.