3

我有字符串资源:

  • values\strings.xml(包含默认英文字符串);
  • values-de\strings.xml(包含德语字符串);

一切都很好,直到我将 Android Studio 更新到最新版本 3.2。现在 lint 给了我很多关于默认字符串资源文件 (values\strings.xml) 的错误:

".... is not translated in "en" (English)"

什么是最好的解决方案?我不想创建另一个文件夹 values-en,它只包含我的默认 values\strings.xml 资源的副本...

4

3 回答 3

5

在 lint 版本中,添加了 3.2 新功能。有关这些功能的更多信息,您可以访问此参考: http ://tools.android.com/tips/lint-checks

MissingTranslation
------------------
Summary: Incomplete translation

Priority: 8 / 10
Severity: Error
Category: Correctness:Messages

If an application has more than one locale, then all the strings declared in
one language should also be translated in all other languages.

If the string should not be translated, you can add the attribute
translatable="false" on the <string> element, or you can define all your
non-translatable strings in a resource file called donottranslate.xml. Or, you
can ignore the issue with a tools:ignore="MissingTranslation" attribute.

You can tell lint (and other tools) which language is the default language in
your res/values/ folder by specifying tools:locale="languageCode" for the root
<resources> element in your resource file. (The tools prefix refers to the
namespace declaration http://schemas.android.com/tools.)

根据本文的这一部分,您可以使用以下方法:

  1.
  <resources
  xmlns:tools="http://schemas.android.com/tools"
  tools:ignore="MissingTranslation">
  ...
  </resources>


  2.
  <string name="any_name" translatable="false">anything</string>
于 2018-10-10T06:24:17.297 回答
1

一种解决方案是在 build.gradle 文件中包含“resConfigs”部分,如此处所述https://developer.android.com/studio/build/shrink-code 以仅保留我的应用程序正式支持的语言。之后就没有更多的错误了。

对我来说,它将是:

android {
    defaultConfig {
        ...
        resConfigs "de"
    }
}

我喜欢这个解决方案,因为我不想完全禁用“MissingTranslation”功能。

于 2018-10-10T18:36:02.797 回答
0

您必须添加 disable 'MissingTranslation'应用程序级别的 gradle。

android {
     defaultConfig {
           //Your config
     }

     lintOptions {
       disable 'MissingTranslation'
   }
}
于 2018-09-26T11:31:26.593 回答