Blog Infos
Author
Published
Topics
, , , ,
Author
Published

As part of this article, I will explain the recent experience I had with the resource configurations that broke localization support in our application.

Here is a sample of what was broken in the French translation

Screenshots of Alert messages in left [correct French version ] and right [broken French version ]

Our client applications are exposed to this UI using a library.

Following are the files that library developers have put the string resources in 👇

  • strings.xml
  • 🇨🇦 strings.xml (fr-rCA)

Screenshot of res folder

You can see 👆 that they’ve put the French strings in a file that targets the Canadian region.

We have strings for the French language in our application that are not region-specific and stored in a common file👇

Screenshot for res folder

Before adding the following configuration to our app-level build.gradle, it was working as expected

Kotlin

android {
    defaultConfig {
        ...
        resourceConfigurations.addAll(listOf("en", "fr"))
    }
}

Groovy

android {
    defaultConfig {
        ...
        resConfigs "en", "fr"
         // Or
        resourceConfigurations += ["en", "fr"] 
    }
}
So what does this config do:
Definition from Android developer’s documentation

Remove unused alternative resources 👇

The Gradle resource shrinker removes only resources that are not referenced by your app code, which means it will not remove alternative resources for different device configurations. If necessary, you can use the Android Gradle plugin’s resConfigs property to remove alternative resource files that your app does not need.

For example, if you are using a library that includes language resources (such as AppCompat or Google Play Services), then your app includes all translated language strings for the messages in those libraries whether the rest of your app is translated to the same languages or not. If you’d like to keep only the languages that your app officially supports, you can specify those languages using the resConfig property. Any resources for languages not specified are removed.

The main advantage of this is that it helps us remove all of the resources that we do not need for our application

At this point, I hope you understand why localization support for French is broken in our case.

For our application, we added the configuration to specify that we only need the Two following resources:👇

resConfigs "en", "fr"
         // Or
resourceConfigurations += ["en", "fr"]

Therefore, Resource Shrinker removes thefr-rCA 🇨🇦 resources and we only have [“en”, “fr”] resources available for our application.

It’s time to fix it
  • To resolve this issue quickly, there are a few options:

1st

  • Update the build.gradle to not remove fr-rCA 🇨🇦 resources
android {
    defaultConfig {
        ...
        resConfigs "en", "fr", "fr-rCA"
         // Or
        resourceConfigurations += ["en", "fr", "fr-rCA"] 
    }
}

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

, ,

Migrating to Jetpack Compose – an interop love story

Most of you are familiar with Jetpack Compose and its benefits. If you’re able to start anew and create a Compose-only app, you’re on the right track. But this talk might not be for you…
Watch Video

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer for Jetpack Compose
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engin ...
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer f ...
Google

Jobs

It’s time to fix it
  • To resolve this issue quickly, there are a few options:

1st

  • Update the build.gradle to not remove fr-rCA 🇨🇦 resources
android {
    defaultConfig {
        ...
        resConfigs "en", "fr", "fr-rCA"
         // Or
        resourceConfigurations += ["en", "fr", "fr-rCA"] 
    }
}

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Using annotations in Kotlin has some nuances that are useful to know
READ MORE
blog
One of the latest trends in UI design is blurring the background content behind the foreground elements. This creates a sense of depth, transparency, and focus,…
READ MORE
blog
Now that Android Studio Iguana is out and stable, I wanted to write about…
READ MORE
blog
The suspension capability is the most essential feature upon which all other Kotlin Coroutines…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu