Exploring Android 14 per-app language preferences dynamic updates

Maxime Dupierreux
3 min readFeb 13, 2023

--

With Android 13 Google introduced per-app language feature. Android 14 is going further by adding some new features to it.

One of them is dynamic updates which allows you to update the list of available languages in the device settings of your app.

In this post, I’m going to show you how to use this feature by creating an app with two buttons, one allowing you to navigate to the app’s settings and another one replacing the accessible languages for the app.

First, we need an app with with some different languages and configured to allow per-app language changes.

Create multiple locales using the Translations Editor.

The translations editor

For this sample app, we’ll just make one language available at first.

Create an XML file called locales_config.xml.

<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en"/>
</locale-config>

And add this line to your AndroidManifest.xml.

<application
...
android:localeConfig="@xml/locales_config">
...
</application>

This will tell the OS that your app supports English.

The app settings

Now let’s see how to change those supported languages.

First, we need to get the LocaleManager and to create a LocaleConfig :

//Get the LocaleManager
val localeManager = getSystemService(LocalContext.current, LocaleManager::class.java)
//Create LocaleConfig
val localeConfig = LocaleConfig(LocaleList(Locale.FRENCH, Locale.GERMAN))

In the snippet above, you can see how to get the LocaleManager. We also create a LocaleConfig with French and German as LocaleList.

Next, we just have to call setOverrideLocaleConfig (or use the accessor in Kotlin) and set our new LocaleConfig.

localeManager?.overrideLocaleConfig = localeConfig

Here’s the result :

As you can see, English is being replaced by French & German in the settings. setOverrideLocaleConfig replaces the existing Locales of your app. If we want to keep English available, we need to add it to the list too.

val localeConfig = LocaleConfig(LocaleList(Locale.FRENCH, Locale.GERMAN, Locale.ENGLISH))

When you go back to the app, you can see that all the labels are updated according to the selected language.

That’s it ! We just changed the list of languages available for our app. This can be useful when testing new languages integration or when pushing new languages to your app without republishing a new version of your app.

The complete source code can be found here.

Thanks for reading !

--

--