sandra oo
sandra oo

Reputation: 91

Using Localization in a pod

I have not found any similar topic here. I am developing a pod that requires multi-language support.

I am adding a Localizable.string :

this one is for the English version:

"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.";

and a class to handle string localization

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)
    }
}

I am getting the following error when I run the project example with my (hereabove) pod as a dependency.

unable to locate the Localizable file

the Localizable file cannot be found.

How can I make the strings file available in my development pod ? Any hint ?

Upvotes: 3

Views: 2433

Answers (1)

Vadim Zhuk
Vadim Zhuk

Reputation: 393

Add this to your podspec:

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

and refer to this bundle name.

Upvotes: 2

Related Questions