【发布时间】:2019-10-01 20:41:43
【问题描述】:
我在应用程序中有一个私有 pod。我正在尝试本地化 pod。您可以在下图中看到。
我在 pod 的资源包中添加了本地化文件。
之后,我在 String 上创建了一个扩展,用于本地化 pod 内的值。
extension Bundle {
private class ClassForBundle {}
static func frameworkBundle() -> Bundle {
let frameworkBundle = Bundle(for: ClassForBundle.self)
let bundleURL = frameworkBundle.resourceURL?.appendingPathComponent("ABC.bundle")
print("Bundle url....\(String(describing: bundleURL))")
return Bundle(url: bundleURL!)!
}
}
extension String {
func localized(withComment comment: String = "") -> String {
return NSLocalizedString(self, bundle: Bundle.frameworkBundle(), comment: comment)
}
}
当我尝试使用以下代码本地化字符串时。它始终默认为英语。
let localizedString = "Land For Lease".localized(withComment: "Land For Lease label")
虽然我在模拟器设置中的国家和地区设置为西班牙和墨西哥,但我得到的价值是“美国土地出租”。有什么我需要做的吗?您的帮助将不胜感激。谢谢。
【问题讨论】:
标签: ios swift localization frameworks cocoapods