denisjacquemin
denisjacquemin

Reputation: 7414

Translate Model's value

What's the best way to handle the following problem with rails 3.0.3?

I have a Model(id, name) Nationality, in which I store different nationalities

ie: French, German, Belgian

My application should be available in multiples languages, so the select input which contains the nationalities should show French, German, Belgian if the locale is set to english, and should show Francais, Allemand, Belge if the locale is set to french.

Where to store the translation and how to use them in my code?

Thanks for your help.

Upvotes: 1

Views: 898

Answers (3)

Max Williams
Max Williams

Reputation: 32933

Have a look at the puret gem which hooks into your existing schema without changing it.
https://github.com/jo/puret#readme

Upvotes: 1

DanneManne
DanneManne

Reputation: 21180

If you create the following structure in your en.yml:

#en.yml
en:
  label_french: French
  label_german: German

Then you can call the following from your views:

<%= t("label_#{@nationality.name}") %>

Upvotes: 5

shingara
shingara

Reputation: 46914

All is explain on i18n rails guides : http://guides.rubyonrails.org/i18n.html

Upvotes: 0

Related Questions