2

In my app I have a set of languages with complete translations, and another set of languages with translations for only a few strings.

For the languages with complete translations, I want Lint to warn me about MissingTranslations.

For the languages with partial translations, I want to Lint to ignore the MissingTranslations.

I can't figure out how to achieve both of these goals at the same time.

Frank Harper
  • 3,027
  • 3
  • 30
  • 41
  • Related: [Android Lint: how to ignore missing translation warnings in a specific file](http://stackoverflow.com/questions/18237845/android-lint-how-to-ignore-missing-translation-warnings-in-a-specific-file) – blahdiblah Apr 28 '15 at 23:06

3 Answers3

1

You can do this by ignoring based on a regular expression against the error message in your lint.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="MissingTranslation">
        <ignore regexp='^".*" is not translated in "ru" \(Russian\)$'/>
    </issue>
</lint>

This will suppress the MissingTranslation error for Russian, but not for any other languages. Basing the ignore on the error message is a bit gross—everything might break if they change the wording—but it's the only solution currently working that I know of.

Note that while the regex is documented as matching against "the error message," it's actually only applied to a portion of the text printed to the screen. The regex anchors in the above example show the bounds.

Some reasonable approaches that did not work for me are:

  • Adding tools:ignore="MissingTranslation" to a partially translated locale's <resources> element.
  • Adding <ignore path="src/main/res/values-ru/strings.xml"/> to the MissingTranslation issue block in lint.xml.

If you happen to be the very particular situation of wanting to suppress MissingTranslation errors for a region-specific strings file that only partially overrides your defaults strings file (e.g., default file is English, and you want some overrides in values-en-rUS/strings.xml), see this answer for a solution.

Community
  • 1
  • 1
blahdiblah
  • 33,069
  • 21
  • 98
  • 152
  • That is not a good way to do it. Your solution relies on an error message string that can change at any time. – Eduard Apr 29 '15 at 20:45
  • 1
    @EduardK. I agree wholeheartedly. On the other hand, this is the only way I know of that actually works. Maybe future versions of lint will add support for the other (more) reasonable approaches that don't currently work. – blahdiblah Apr 29 '15 at 22:38
  • 1
    That's the best answer considering the limitations of the current tool. – mbonnin Oct 22 '19 at 16:47
0

On the warning marker, press Ctrl-1 to show the available quickfixes. You can choose to ignore the warning for a certain file in the quickfix resolution selection.

You still have to choose whether it is a partial or complete translation by yourself.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
-1

For the languages with partial translations you can use annotations. Since you say you only have a few strings there, you can suppress those specific strings in the xml file like this:

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>    

    <!--suppress MissingTranslation -->
    <string name="some_string">ignore my translation</string>
    ...

</resources>

http://tools.android.com/tips/lint/suppressing-lint-warnings

Eduard
  • 3,482
  • 2
  • 27
  • 45
  • This won't work. The strings are **missing** in some files, so the only place that you can add an annotation is in the default strings file, and that will suppress the warning across all locales, instead of only the partial ones. – blahdiblah Apr 28 '15 at 22:47
  • So how do you mark that a certain language is a 'complete' translation or a 'partial'? – Eduard Apr 29 '15 at 17:39
  • Yes. That is the core of the question. – blahdiblah Apr 29 '15 at 17:47