Android Lint:如何忽略故意仅覆盖某些默认翻译的区域语言环境字符串文件中缺少的翻译警告? [英] Android Lint: how to ignore missing translation warnings in a regional locale string file that purposely only overrides some default translations?
问题描述
是否可以在一个单独的资源文件中翻译一些字符串,但不是全部,而不用 Lint 抱怨 MissingTranslation?
Is it possible to translate some strings, but not all, in a separate resource file without Lint complaining about MissingTranslation?
例如:我的应用的字符串都在res/values/strings.xml中.其中一个字符串是
For example: my app's strings are all in res/values/strings.xml. One of the strings is
<string name="postal_code">邮政编码</string>
由于邮政编码"在美国通常称为邮政编码",我想添加另一个资源 res/values-en-rUS/strings.xml,其内容为:
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>
但是,Lint 抱怨 values/strings.xml 中的其他字符串,但 values-en-rUS/strings.xml
However, Lint complains about other strings in values/strings.xml but not in values-en-rUS/strings.xml
我知道您可以通过在 values/strings.xml 中指定 tools:ignore
来抑制警告.但这是不可取的,因为 Lint 警告在翻译成另一种语言时实际上很有用.
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.
相反,是否可以抑制 values-en-rUS/strings.xml 文件中的警告,例如告诉 Lint 在查找丢失的翻译时不要使用该文件作为标准?
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?
推荐答案
禁用 MissingTranslations 检查的好方法是在模块特定的 build.gradle
文件中添加选项.
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
}
如果字符串不存在于特定于语言环境的字符串文件中,它将从默认文件中获取字符串,该文件通常是 strings.xml
.
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
.
这篇关于Android Lint:如何忽略故意仅覆盖某些默认翻译的区域语言环境字符串文件中缺少的翻译警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!