Vedprakash Wagh
Vedprakash Wagh

Reputation: 3732

Adding a library with more translations than the app has gives errors in string.xml

So I added GDPR dialog library in my Android app, which is translated in 10 languages. And my app currently has translations in 7 languages.

Now, the problem is, it shows error for all the strings in my app like below:

enter image description here

The error says,

"load_next" is not translated in "cs"(Czech), etc (names of languages which library has but my app doesn't)

My app is in 7 different languages, when I added GDPR library by using implementation 'com.github.MFlisar:GDPRDialog:LATEST-VERSION', this error isn't shown, but as I wanted to make some changes of my own, I downloaded the library and added it as a java module in my app, and then this error started showing up.

App compiles and runs without error (if I've added the translations for all the languages that I've used), but it's a huge inconvenience as I can't just glance at string.xml and find out if I missed any translations(as it shows this error for all the text).

So is there any way I can correct this thing without having to:

  1. Delete the extra languages in the library
  2. Or without suppressing the warning for missing translation, as that's the important thing for me as I have to manage translations for 7 different languages.

Maybe something with which I can suppress this warning only for selected languages?

Upvotes: 3

Views: 114

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364085

You can use in the build.gradle

resConfigs "en", "de", "it", "fr"

You can check the official doc:

Specifies a list of alternative resources to keep.
For example, if you are using a library that includes language resources (such as AppCompat or Google Play Services), then your APK 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 resConfigs property, as shown in the sample below. Any resources for languages not specified are removed.

android {
    defaultConfig {
        ...
        // Keeps language resources for only the locales specified below.
        resConfigs "en", "fr"
    }
}

Upvotes: 4

Related Questions