在广告连播中使用本地化

时间:2018-12-07 18:48:19

标签: swift localization pod

我在这里没有找到任何类似的话题。我正在开发需要多语言支持的pod。

我要添加 Localizable.string

这是英文版本:

"No Preview Available" = "Preview is not available for this file";
"No Network Available" = "An error has occurred, please check your network connection or try again later.";

class 来处理字符串本地化

private class Localizator {

    static let sharedInstance = Localizator()

    lazy var localizableDictionary: NSDictionary! = {
        if let path = Bundle.main.path(forResource: "Localizable", ofType: "strings") {
            return NSDictionary(contentsOfFile: path)
        }
        fatalError("Localizable file NOT found")
    }()

    func localize(string: String) -> String {
        guard let localizedString = localizableDictionary.value(forKey: string) as? String else {
            assertionFailure("Missing translation for: \(string)")
            return ""
        }
        return localizedString
    }
}

extension String {
    var localized: String {
        return Localizator.sharedInstance.localize(string: self)
    }
}

当我使用(以上)pod作为依赖项运行项目示例时,出现以下错误。

unable to locate the Localizable file

找不到可本地化的文件。

如何在开发窗格中使用字符串文件? 有什么提示吗?

1 个答案:

答案 0 :(得分:1)

将此添加到您的podspec:

s.resource_bundles = {
            'YourBundleName' => ['path_to_resource/Internationalization/*.lproj']
        }

并引用此捆绑包名称。