升级到Android Studio 3.2版本后,我在本地化方面遇到了错误。

3

我有字符串资源:

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

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

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

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


1
你找到解决方案了吗? - Tushar Nallan
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>

1

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

对于我来说,这将是:

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

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


0

您需要在应用级别的gradle中添加disable 'MissingTranslation'

android {
     defaultConfig {
           //Your config
     }

     lintOptions {
       disable 'MissingTranslation'
   }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接