We have an ongoing project which is a site that is available both in English and Chinese. We used the Rails baked in i18n functionality to implement the translations and the languages can be switched between to display either.
We found that adding links into our translations files was a bit of an arse and left it rather untidy. It was also going to be difficult to explain to our client how to do the Chinese translations from the English YAML file that we provided. After some searching we stumbled upon the
it gem (it was and remains hard to find because the name is so ambiguous) which was a more elegant solution to our problem.
First of all you will want to add the gem to your Gemfile.
You want this to sit out in your ‘main’ Gemfile as you’ll probably want it available in all environments. Then run
bundle to grab your dependencies.
So onto using it. in your YAML file you’ll want to have something like this:
You want to call the ‘it’ Gem with
It. Within your view file you want something like this:
So this will give us something that looks like this:
The easiest way for me to explain the relationship between what is in the yaml file and view is with this diagram: