Skip to content

Instantly share code, notes, and snippets.

@WaYdotNET
Forked from henrik/en.yml
Created December 1, 2011 11:39
Show Gist options
  • Save WaYdotNET/1416082 to your computer and use it in GitHub Desktop.
Save WaYdotNET/1416082 to your computer and use it in GitHub Desktop.
Ruby on Rails i18n: storing locale names in their yml files and retrieving them.
# config/locales/en.yml
en:
i18n:
language:
name: 'English'
# config/initializers/i18n.rb
module I18n
def self.name_for_locale(locale)
I18n.backend.translate(locale, "i18n.language.name")
rescue I18n::MissingTranslationData
locale.to_s
end
end
# E.g.:
# I18n.name_for_locale(:en) # => "English"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment