无法在 Android Studio 中设置默认语言 [英] Cannot set the default language in Android Studio

查看:58
本文介绍了无法在 Android Studio 中设置默认语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android Studio 中收到有关未翻译字符串的警告 - 它告诉我它们尚未翻译成英文.这似乎是因为我有一个en-rGB"资源文件夹.但是我已经尝试按照 lint 中的说明指定默认语言,但这并没有奏效.

我有以下 strings.xml 文件:

values/strings.xml:

<string name="string1">你好</string><string name="string2">你好</string></资源>

values-en-rGB/strings.xml:

<string name="string1">你好</string></资源>

values-fr/strings.xml:

<string name="string1">Bonjour</string><string name="string2">Bonjour</string></资源>

values-fr-rCA/strings.xml:

<string name="string2">Bonjour</string></资源>

预期结果:应该没有警告,两个字符串都被翻译成英文和法文

实际结果:Lint 会警告 string2,说它没有翻译成英文.

注意,我已经包含了 fr-rCA 以表明它不是区域性的东西.令人高兴的是,只要将其翻译为未区域化"的法语,它也不需要翻译为加拿大法语.在这种情况下,它不会警告 string1,即使它没有被翻译成法文加拿大,因为它已经被翻译成法文.

我无法将主资源文件夹更改为英文 (values-en),因为这会导致没有默认资源的错误.这是真的.

我一般不想取消警告,因为我打算添加其他语言,而且我确实希望对未翻译成我包含的其他语言的字符串显示警告.

我所追求的是将默认语言告知 lint 的正确方法.我已按照翻译不完整"警告的说明进行操作:

<块引用>

你可以告诉 lint(和其他工具)哪种语言是默认的通过指定 res/values/文件夹中的语言tools:locale="languageCode" 用于您的根元素资源文件.(工具前缀指的是命名空间声明

I am getting warnings in Android Studio about untranslated strings - it is telling me they have not been translated to English. This appears to be because I have an "en-rGB" resource folder. But I have tried to follow the instructions in lint to specify the default language, but this has not worked.

I have the following strings.xml files:

values/strings.xml:

<resources xmlns:tools="http://schemas.android.com/tools"
    tools:locale="en">

    <string name="string1">Howdy</string>
    <string name="string2">Howdy</string>
</resources>

values-en-rGB/strings.xml:

<resources>

    <string name="string1">Hello</string>
</resources>

values-fr/strings.xml:

<resources>

    <string name="string1">Bonjour</string>
    <string name="string2">Bonjour</string>
</resources>

values-fr-rCA/strings.xml:

<resources>

    <string name="string2">Bonjour</string>
</resources>

Expected result: There should be no warnings, both strings are translated to both English and French

Actual result: Lint will warn about string2, saying it is not translated to English.

Note, I have included fr-rCA to show that it is not a regional thing. It is happy that as long as it is translated to the "unregioned" french, it does not also need to be translated to French Canadian. In this instance, it will not warn about string1, even though it's not been translated to French Canadian, because it's already been translated to French.

I cannot change the main resource folder to English (values-en), as that will result in errors that there is no default resources. Which is true.

I do not want to suppress the warning in general, because I am planning to add other languages and I DO want the warning to appear for strings which are not translated into other languages that I have included.

What I am after is the correct way to inform lint of the default language. I have done it as per the instructions for the "Imcomplete translation" warning:

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 element in your resource file. (The tools prefix refers to the namespace declaration http://schemas.android.com/tools.)

But this does not seem to work. Am I doing it wrong, or is this an issue with lint?

解决方案

It's a bug: https://issuetracker.google.com/issues/142590628

I have a hotfix for you: Auto copy values/strings.xml into values-en folder

1. Create values-en folder

2. Paste it into app/build.gradle

task copyEnResource {
    copy {
        from ('src/main/res/values/strings.xml')
        into ('src/main/res/values-en/')
    }
}

preBuild.dependsOn copyEnResource

Demo:

这篇关于无法在 Android Studio 中设置默认语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆