Skip to content

Instantly share code, notes, and snippets.

@FiXato
Forked from henrik/en.yml
Last active August 29, 2015 13:59
Show Gist options
  • Save FiXato/10746754 to your computer and use it in GitHub Desktop.
Save FiXato/10746754 to your computer and use it in GitHub Desktop.
# config/locales/en.yml
en:
i18n:
language:
name: 'English'
# config/initializers/i18n.rb
module I18n
def self.name_for_locale(locale=nil)
locale = I18n.locale || I18n.default_locale if locale.nil?
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