避免Android Lint抱怨未翻译的string

是否有可能指定value-*目录中的文件中的string有意不被翻译成其他语言? 我有一堆所有语言通用的string,不需要翻译,所以我在values目录中创build了一个unlocalized-strings.xml文件。运行Android Lint检查是否存在一些问题,说有些翻译缺失..我不想禁用整个项目的这个检查,我想只在一些XML文件中禁用它..是否有可能?

 "title_widget_updater_service" is not translated in de, en, en-rUS, it Issue: Checks for incomplete translations where not all strings are translated Id: MissingTranslation If an application has more than one locale, then all the strings declared in one language should also be translated in all other languages. By default this detector allows regions of a language to just provide a subset of the strings and fall back to the standard language strings. You can require all regions to provide a full translation by setting the environment variable ANDROID_LINT_COMPLETE_REGIONS. 

如何定义这个区域的非本地化的string?

我不知道如何忽略所有的文件,但你可以使用string来完成:

 <string name="hello" translatable="false">hello</string> 

祝你好运

这是string文件中tools名称空间的ignore属性,如下所示:

 <?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> 

添加到build.gradle

 android { lintOptions { disable 'MissingTranslation' } } 

我知道有三种方法:

按值应用修改值:在<string>定义上设置translatable="false"属性:

 <string name="account_setup_imap" translatable="false">IMAP</string> 

如果你有很多不应该被翻译的资源,你可以把它们放在一个名为donottranslate.xml的文件中,lint会考虑所有这些资源。

浏览黑客键盘项目来源时发现的另一种方式:
您可以将前缀donottranslate-添加到您的资源文件。 和前面的例子一样,lint会考虑所有的不可翻译的资源。
在你的情况下,你可以用unlocalized-strings.xmlreplacedonottranslate-strings.xml 。 它似乎工作,但我还没有发现任何文档的这个提示。

请参阅: Android工具项目网站:不可翻译的string

这里有一个Android Studio解决scheme来禁用这个致命的Lint错误:

在这里输入图像说明

我认为你所需要的而不是禁用lint是用属性标记它们

 translatable="false" 

如果你想检查翻译错误,你可以去

“项目属性 – > Android Lint首选项 – >selectMissingTranslation – >忽略严重性的开关”,

希望这可以帮助别人,因为我只是遇到这个问题:)

创build一个文件名为“ donottranslate ”(例如donottranslate.xmldonottranslate_urls.xml等)的资源文件,当检查缺失的翻译时,lint会忽略它的string。

要避免在Android Studio中发出警告,请打开首选项==>检查,取消选中“不完整的翻译”。 但它不会影响Gradle构build。

另一种方法是使用resValuebuildConfigField将您的string添加到gradle文件中。 类似的东西:

 buildTypes { debug { buildConfigField "string", "app_name1", "App Name" resValue "string", "app_name2", "App Name" } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "string", "app_name1", "App Name" resValue "string", "app_name2", "App Name" } } 

用途:

 // buildConfigField BuildConfig.APP_NAME1 // resValue getString(R.string.app_name2)