Localization in iOS is so simple by using system provided mechanism.

But it can be a nightmare if you want to achieve a more flexible goal with a so far convenient way to access.

Compare to lots of solution around, I decide to use gyb to make my baby work like a charm.

Why gyb?

Because it's just a simple script that makes all thing works. I can use dot syntax around the project and so far flexible, easy to organize the files and the source format, JSON, first level web citizen.

GYB is just a template engine using python to generate your file. Actually, you can do it with lots of other languages to make your own. But don't make your own wheel. When a tool come and just work, and the outcome is so far satisfying, why would you bother?

The result is I can do the following easily.

What I need to do is in my JSON:

<br />{
...

"investmentDescription": "Bla bla bla"

...
}

Then I can access the content by dot syntax. Just run a compilation script in shell( or add a run script in target build setting )

let locale = SBLocalization.shared.use("en") /// You can use enum
// or SBLocalization.en()
descriptionLabel.text = locale.investmentDescription

The difference between localizedString and this solution is, the localizedString is, write before declare and fill the empty later. And this solution is, declare before you use it. I think both of them have their strength. But in a high regulation binding company like us, nature is already declared before use.

You can find more information of gyb in swift build tools which you can find it on GitHub.

See you soon.

Original post from my previous site: http://povoq.blogspot.com/2017/08/how-i-use-gyb-to-achieve-more-flexible.html