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">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屋!