将Android Studio升级到3.2版后,出现本地化错误

时间:2018-09-26 11:28:35

标签: android localization resources android-studio-3.2

我有字符串资源:

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

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

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

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

3 个答案:

答案 0 :(得分:1)

在皮棉版本中,添加了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>

答案 1 :(得分:1)

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

对我来说是

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

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

答案 2 :(得分:0)

您必须在应用级gradle中添加disable 'MissingTranslation'

android {
     defaultConfig {
           //Your config
     }

     lintOptions {
       disable 'MissingTranslation'
   }
}