Ignoring Android Lint “MissingTranslation” check for partial translations

こ雲淡風輕ζ 提交于 2019-12-06 10:51:34

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.

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

blahdiblah

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!