Swift Xcode 12.5 更新后包未正确本地化

Swift Package not localizing correctly after Xcode 12.5 Update

我有一个 Swift 包,在“资源”文件夹内的文件夹中有多个翻译,例如“Resources/de.lproj/Localizable.strings”和“Resources/en.lproj/Localizable.strings”.

自从我更新到 Xcode 12.5 后,实现这个 Swift 包的应用程序总是回退到英文,它只有 returns 字符串本地化为英文。 我的 Package.swift 默认使用“de”:

defaultLocalization: "de",

示例: 运行 设备上的应用设置为德语:

print(Locale.preferredLanguages) // ["de"]
print(Bundle.module.localizations) // ["de", "en", "es", "it", "fr"]
print(NSLocalizedString("Yes", tableName: nil, bundle: .module, value: "", comment: "")) // "Yes" (instead of "Ja" from the German file)

在 iOS 模拟器中设置“App Language”也会导致同样的问题。

问题是宿主应用似乎没有任何本地化,所以 Swift 包也不会本地化。

Swift 论坛上有详尽的解释:https://forums.swift.org/t/swift-package-manager-localization/46685/6

It sounds like the real issue might be you are expecting libraries to use additional localizations beyond those supported by the main application bundle. If so, setting CFBundleAllowMixedLocalizations to YES in the application’s Info.plist is the proper solution.