ios - 私有 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")
尽管我在模拟器设置中的国家和地区设置为西班牙和墨西哥,但我得到的价值是“美国土地出租”。有什么我需要做的吗?您的帮助将不胜感激。谢谢。
解决方案
造成问题的是 pod 缓存。我花了将近半天的时间。从模拟器中删除应用程序并删除派生数据挽救了我的生命。我将这个问题留在这里,以便将来有人想要将本地化添加到私人 pod 或面临相同类型的问题时,它可能会有所帮助并节省时间。
推荐阅读
- java - 使用 jsonpath 解析数组索引
- vue.js - 路由器视图外的Vue路由返回空数据
- javascript - 如何使用 async/await 调用 AWS 开发工具包的 Athena API?
- html - 有没有办法为范围输入设置滑动持续时间?
- r - 如果一列中至少有两个零,我如何用 NA 替换所有零?
- powerbi - 兼容性问题
- python - 访问列表中的引用元素
- automated-tests - 如何在 Windows 10 上的 Cygwin 中安装 Dieharder?
- c++ - Visual Studio Code 中的调试器显示神秘的错误窗口
- excel - 有没有办法将大文本流分成 550 个字符的部分?