dyserone dyserone - 1 year ago 80
Ruby Question

Rails, is there a way to assosciate a name with each locale?

I have 2 languages at the moment English and Greek (:en & :el).

I'm using the globalize gem.

Is there a way so I can put them in a loop and then extract the name of each language?

For example is there something like the following:


If yes, where do I declare/change it?

Answer Source

One solution is to create a :language_name key inside your en.yml and gr.yml:

  language_name: English

  language_name: Greek

Then simply call I18n.t('language_name'). If you need to have them all at once, you can still loop through all the available locales:

I18n.available_locales.map { |locale| I18n.t('language_name', locale: locale) }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download