alphagov/slimmer — pull request #101 by edds (2014-12-01 15:54:06+00:00)
Title: First iteration of network based i18n translations

To enable us to have components which have translated strings in them.
For example the titles on the metadata component.

This doesn't necessarily want merging in this state but I would appreciate
comments and thoughts on the approach and direction.

---

A i18n backend which can be plugged into Rails. This will let us load
translations for strings which are in components dynamically the same
way we are loading templates. This means we can then reliably update
translations for components across the site.

As this uses the same caching engine as the component loader the
translation calls and the translations should always remain in sync.

This will need some changes to Static to serve YAML translation files.
The files which will need to be served are:

/templates/govuk_component/translations/available

This should be a YAML array of different locales which are available.
For each locale that is available there should be a YAML file the same
as you would normally find in `./config/locales/:locale.yml`:

/templates/govuk_component/translations/translations.:locale

Where `:locale` is a two letter language code.

The I18n backend can be added to the default Simple backend in rails by
calling:

```ruby
I18n.backend = I18n::Backend::Chain.new(I18n.backend, Slimmer::ComponentI18nBackend.new)
```

This will cause Rails to first try and use the strings from the
application and then fallback onto this backend. This will also enable
applications to override strings if they need to be different for some
reason.

In a component you could then call something like:

```erb
<%= t("govuk_component.metadata.from", default: "From") %>:

```