ylliX - Online Advertising Network

How to reload translations strings from remote at runtime?

At some point your app may need lot of supported languages, which sooner or later will come to common problem – each translation change requires app release via AppStore, which takes at least a day. Of course, there are many commercial solution, some pretty expensive. But is there any free way?

Fortunately, there is. And is quite simple. All you need to do, is download translations files (if your app supports many languages, it will be more efficient to use ZIP for single request) and create your custom bundle in documents directory, directly on device. Then instead of:

NSLocalizedString("label1", comment: "")

you need to use:

NSLocalizedString("label1", tableName: "", bundle: currentBundle, value: "", comment: "")

where “currentBundle” is “Bundle.main” by default, then your custom bundle.

If you want it to try by yourself, grab repo at https://github.com/blastar/Dynamic-Strings-Loading.

But beware – this is only for educational purposes. My proposal is not production-ready and needs refactoring if you want to use it in real app. Current one is made for simplicity and readability in mind.

UPDATE: On repo you can find some update – now there are 2 buttons which are fetching different strings. Usually Bundle content is cached and simple reloading won’t work, but the key is to use “.nocache” in tableName parameter. Just checkout last commit here.

Leave a Reply