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

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

问题描述

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

我有以下strings.xml文件:

values/strings.xml :

 <资源xmlns:tools ="http://schemas.android.com/tools"工具:locale ="zh-CN">< string name ="string1"> Howdy</string>< string name ="string2"> Howdy</string></resources> 

values-en-rGB/strings.xml :

 < resources>< string name ="string1">你好</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> 

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

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

请注意,我加入了fr-rCA来表明这不是区域性的事情.很高兴的是,只要将其翻译成未划分区域的"法语,就不必将其翻译成加拿大法语.在这种情况下,即使它没有被翻译成加拿大法语,它也不会警告string1,因为它已经被翻译成法语.

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

我一般不希望取消警告,因为我正计划添加其他语言,并且我确实希望针对未翻译成我所包含的其他语言的字符串显示警告.

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

您可以告诉皮棉(和其他工具)哪种语言是默认语言通过在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天全站免登陆