Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lint: how to ignore missing translation warnings in a regional locale string file that purposely only overrides some default translations?

Is it possible to translate some strings, but not all, in a separate resource file without Lint complaining about MissingTranslation?

For example: my app's strings are all in res/values/strings.xml. One of the strings is

<string name="postal_code">Postal Code</string>

Since "postal code" is usually called "zip code" in the US, I want to add another resource res/values-en-rUS/strings.xml with contents:

<?xml version="1.0" encoding="utf-8"?> <resources>     <string name="postal_code">Zip Code</string> </resources> 

However, Lint complains about other strings in values/strings.xml but not in values-en-rUS/strings.xml

I realize you can suppress the warnings by specifying tools:ignore in values/strings.xml. But this is undesirable because the Lint warning is actually useful when translating to another language.

Instead, is it possible to suppress the warning in the values-en-rUS/strings.xml file, as in, telling Lint not to use that file as criteria when looking for missing translations?

like image 571
Steveo Avatar asked Aug 14 '13 16:08

Steveo


2 Answers

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.

like image 134
Nicks Avatar answered Sep 28 '22 02:09

Nicks


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> 
like image 38
anticafe Avatar answered Sep 28 '22 04:09

anticafe