问题
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?
回答1:
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:
来源:https://stackoverflow.com/questions/59375358/cannot-set-the-default-language-in-android-studio