Xcoder
Xcoder

Reputation: 131

Is it possible to update String Catalog file dynamically?

I am trying to localise my app using String Catalog, the problem I am facing is all the strings(label/button title) are downloaded from the server. For e.g their is a label which has the text "I am dynamic label" this text is getting loaded from the server. How can I localise it in my app, as at the time of development I don't what the text would be. Is there any way I can parse the String Catalog as json file and update it via code. I tried reading it first but it's not working.

func readStringCatalog(fileName: String) {
guard let url = Bundle.main.url(forResource: fileName, withExtension: "xcstrings") else { return nil }

guard let data = try? Data(contentsOf: url) else { return nil }

guard let jsonData = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) else { return nil }
        if let jsonDict = jsonData as? [String:Any] {
            return jsonDict
        }
        return nil
}

Upvotes: 0

Views: 108

Answers (0)

Related Questions