Charles Charles -4 years ago 127
Ruby Question

Rails language name using I18n locale

I want to match the locale code to the specific language name. Is there any build in function in I18n/rails which would return the language name to the corresponding locales. Is installing a gem is the only way?

Answer Source

It seems there is no method for this in I18n. If you just need current language name, you can easily include it to corresponding locale file:

# config/locales/en.yml
en:
  language_name: "English"

And get it as usual: I18n.t('language_name') or I18n.t('language_name', locale: :en). For general purposes you could use: https://github.com/hexorx/countries or initialize your own mapping.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download