Android Lint: how to ignore missing translation warnings in a regional locale string file that purposely only overrides some default translations?
A nice way to disable MissingTranslations check is to add the option in module specific build.gradle
file .
android { lintOptions{ disable 'MissingTranslation' } //other build tags}
If the strings are not present in locale specific Strings file, it will take the strings from the default file which generally is strings.xml
.
I found a better solution according to this answer: https://stackoverflow.com/a/13797364/190309
Just add ignore="MissingTranslation"
to your string.xml
, for example:
<?xml version="1.0" encoding="utf-8"?><resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation" > <!-- your strings here; no need now for the translatable attribute --></resources>
Lint supports partial regional translations, but needs to know what language the default strings are. That way, it can distinguish a partial regional translation from missing translations in a different locale.
To specify the locale in values/strings.xml
:
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
Quote from the lint command-line tool, when running lint --show
:
By default this detector allows regions of a language to just provide asubset of the strings and fall back to the standard language strings. [...]You can tell lint (and other tools) which language is the default languagein your res/values/ folder by specifying tools:locale="languageCode" forthe root <resources> element in your resource file. (The tools prefixrefers to the namespace declaration http://schemas.android.com/tools.)
Add the locale specification to your default language file, and you shouldn't get that error for en-rUS
, but will still be informed of any other missing translations.