添加翻译数量多于应用程序的库会在 string.xml 中出现错误
Adding a library with more translations than the app has gives errors in string.xml
所以我在我的 Android 应用程序中添加了 GDPR 对话框库,它被翻译成 10 种语言。我的应用目前有 7 种语言的翻译。
现在,问题是,我的应用程序中的所有字符串都显示错误,如下所示:
错误说,
"load_next" is not translated in "cs"(Czech), etc (names of languages which library has but my app doesn't)
我的应用程序有 7 种不同的语言,当我使用 implementation 'com.github.MFlisar:GDPRDialog:LATEST-VERSION'
添加 GDPR 库时,没有显示此错误,但由于我想自己做一些更改,我下载了库并将它作为 java 模块添加到我的应用程序中,然后开始出现此错误。
应用程序编译和运行没有错误(如果我已经添加了我使用过的所有语言的翻译),但这是一个巨大的不便,因为我不能只看一眼 string.xml
就找到如果我错过了任何翻译(因为它显示了所有文本的错误)。
那么有什么方法可以纠正这个问题而不必:
- 删除库中多余的语言
- 或者不取消缺少翻译的警告,因为这对我来说很重要,因为我必须管理 7 种不同语言的翻译。
也许我可以只针对选定的语言抑制此警告?
您可以在build.gradle
中使用
resConfigs "en", "de", "it", "fr"
您可以查看 official doc:
Specifies a list of alternative resources to keep.
For example, if you are using a library that includes language resources (such as AppCompat or Google Play Services), then your APK includes all translated language strings for the messages in those libraries whether the rest of your app is translated to the same languages or not. If you'd like to keep only the languages that your app officially supports, you can specify those languages using the resConfigs property, as shown in the sample below. Any resources for languages not specified are removed.
android {
defaultConfig {
...
// Keeps language resources for only the locales specified below.
resConfigs "en", "fr"
}
}
所以我在我的 Android 应用程序中添加了 GDPR 对话框库,它被翻译成 10 种语言。我的应用目前有 7 种语言的翻译。
现在,问题是,我的应用程序中的所有字符串都显示错误,如下所示:
错误说,
"load_next" is not translated in "cs"(Czech), etc (names of languages which library has but my app doesn't)
我的应用程序有 7 种不同的语言,当我使用 implementation 'com.github.MFlisar:GDPRDialog:LATEST-VERSION'
添加 GDPR 库时,没有显示此错误,但由于我想自己做一些更改,我下载了库并将它作为 java 模块添加到我的应用程序中,然后开始出现此错误。
应用程序编译和运行没有错误(如果我已经添加了我使用过的所有语言的翻译),但这是一个巨大的不便,因为我不能只看一眼 string.xml
就找到如果我错过了任何翻译(因为它显示了所有文本的错误)。
那么有什么方法可以纠正这个问题而不必:
- 删除库中多余的语言
- 或者不取消缺少翻译的警告,因为这对我来说很重要,因为我必须管理 7 种不同语言的翻译。
也许我可以只针对选定的语言抑制此警告?
您可以在build.gradle
resConfigs "en", "de", "it", "fr"
您可以查看 official doc:
Specifies a list of alternative resources to keep.
For example, if you are using a library that includes language resources (such as AppCompat or Google Play Services), then your APK includes all translated language strings for the messages in those libraries whether the rest of your app is translated to the same languages or not. If you'd like to keep only the languages that your app officially supports, you can specify those languages using the resConfigs property, as shown in the sample below. Any resources for languages not specified are removed.
android {
defaultConfig {
...
// Keeps language resources for only the locales specified below.
resConfigs "en", "fr"
}
}