首页 > 解决方案 > 私有 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")

尽管我在模拟器设置中的国家和地区设置为西班牙和墨西哥,但我得到的价值是“美国土地出租”。有什么我需要做的吗?您的帮助将不胜感激。谢谢。

标签: iosswiftlocalizationframeworkscocoapods

解决方案


造成问题的是 pod 缓存。我花了将近半天的时间。从模拟器中删除应用程序并删除派生数据挽救了我的生命。我将这个问题留在这里,以便将来有人想要将本地化添加到私人 pod 或面临相同类型的问题时,它可能会有所帮助并节省时间。


推荐阅读