Ignoring Android Lint “MissingTranslation” check for partial translations

夙愿已清 提交于 2019-12-22 13:02:01

问题


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.


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/12019282/ignoring-android-lint-missingtranslation-check-for-partial-translations

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