Ste*_*veo 36 android translation localization lint android-lint
是否有可能在没有Lint抱怨MissingTranslation的单独资源文件中翻译某些字符串,而不是全部?
例如:我的应用程序的字符串都在res/values/strings.xml中.其中一个字符串是
<string name="postal_code">Postal Code</string>
由于"邮政编码"在美国通常被称为"邮政编码",我想在内容中添加另一个资源res/values-en-rUS/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="postal_code">Zip Code</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
但是,Lint在values/strings.xml中抱怨其他字符串,但在values-en-rUS/strings.xml中没有
我意识到你可以通过tools:ignore在values/strings.xml中指定来抑制警告.但这是不可取的,因为Lint警告在翻译成另一种语言时实际上很有用.
相反,是否可以在values-en-rUS/strings.xml文件中禁止警告,如在查找缺少的翻译时告诉Lint不要将该文件用作标准?
Nic*_*cks 60
禁用MissingTranslations检查的一种好方法是在模块特定build.gradle文件中添加选项.
android {
lintOptions{
disable 'MissingTranslation'
}
//other build tags
}
Run Code Online (Sandbox Code Playgroud)
如果特定于语言环境的字符串文件中不存在字符串,则它将从默认文件中获取字符串 strings.xml.
ant*_*afe 36
根据这个答案,我找到了一个更好的解决方案:https://stackoverflow.com/a/13797364/190309
只需添加ignore="MissingTranslation"到您的string.xml,例如:
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation" >
<!-- your strings here; no need now for the translatable attribute -->
</resources>
Run Code Online (Sandbox Code Playgroud)
bla*_*lah 18
Lint支持部分区域翻译,但需要知道默认字符串是什么语言.这样,它可以将部分区域翻译与不同语言环境中的缺失翻译区分开来.
要在values/strings.xml以下位置指定区域设置:
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
Run Code Online (Sandbox Code Playgroud)
来自lint:
默认情况下,此检测器允许语言区域仅提供字符串的子集并回退到标准语言字符串.[...]
您可以通过为资源文件中的根元素指定工具:locale ="languageCode"来告诉lint(和其他工具)res/values /文件夹中的哪种语言是默认语言.(工具前缀是指名称空间声明http://schemas.android.com/tools.)
将语言环境规范添加到默认语言文件中,您不应该收到该错误en-rUS,但仍会通知任何其他缺少的翻译.
pro*_*m85 14
这似乎还没有回答,所以我给你看一个解决方案:
在您的DEFAULT xml文件中,您可以定义不需要如下所示的翻译的字符串:
<string name="developer" translatable="false">Developer Name</string>
Run Code Online (Sandbox Code Playgroud)
这个字符串不需要翻译,lint也不会抱怨它...
这是瑞士刀的答案,因此根据您所处的情况,您可以忽略缺少的翻译消息:
忽略所有MissingTranslation消息:
编辑build.gradle文件:
android {
lintOptions{
disable 'MissingTranslation'
}
}
Run Code Online (Sandbox Code Playgroud)忽略MissingTranslation具体resources.xml文件中的所有消息:
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation">
<!-- your strings here; no need now for the translatable attribute -->
</resources>
Run Code Online (Sandbox Code Playgroud)忽略MissingTranslation仅一个字符串的消息:
<string name="developer" translatable="false">Developer Name</string>
Run Code Online (Sandbox Code Playgroud)如果您使用的是 Eclipse,请查看 Lint 警告视图的工具栏按钮。其中之一称为“忽略文件”。这应该会有所帮助,但前提是 Lint 将错误分配给您的“US”文件。该按钮只是修改项目中的 lint.xml 文件,因此您可以轻松地进行调查(和撤消)。
有关该文件特定抑制的更多详细信息,请访问http://tools.android.com/tips/lint/suppressing-lint-warnings