views:

29

answers:

1

hi all

I have a category collection and each category has a array of hashes containing attributes names and units to create a inout form with, to add a product of that category.

for example category car fields - {name : length, unit : mm}, {name : weight, unit : kg}.

Problem is i would this site to be multi-lingual and therefore need to store the field names per language.

I could put them inline :

for example category car fields - {en-name : length, cn-name : ....., de-name : ....., unit : mm}

Is there a better way ?

Not sure if this is best way as i want to be able to pass a docuement of names needing to be translated to the translator for all field names for all categories, so storing this way i would have to grab all then put into another docuement then translate and inset new translated naes back!!!

Any help or ideas ?

Thanks rick

+1  A: 

The best way would be to put translations in locale files (in config/locales/). For example (english locale):

en:
  categories:
    car:
      length: Length

And then something like that when displaying name of the field:

I18n.t("categories.#{category.name}.#{field_name}")

This way you can maintain only one locale file and send the other ones to the translator.

Michal
thanks for the solution.Only problem is i need to restart the application to pull in new changes to the locale files. or dont i ?Also is it possible for my users to add the translation for certain fields to these files from my app ?thanks
rick moss
Yes, you need to restart the app to reload locale files. I thought the field names already known and you just need some simple way to translate them, I didn't assume that you'd want your users to add translations via the running app. If that's the case my solution may not be easily applicable. Anyway if you need some simple way to work on translations you should check http://99translations.com
Michal