Module: Groseillier::Locale
- Defined in:
- lib/groseillier/locale.rb
Class Method Summary collapse
-
.available ⇒ Object
Return really supported locales.
-
.collection_select(default = false) ⇒ Object
Return array suitable for use with options_for_select.
-
.human_name(locale) ⇒ Object
Convert locale (ex: :en) to human name (ex: English).
Class Method Details
.available ⇒ Object
Return really supported locales
15 16 17 |
# File 'lib/groseillier/locale.rb', line 15 def available [:fr, :en].freeze end |
.collection_select(default = false) ⇒ Object
Return array suitable for use with options_for_select
20 21 22 23 24 25 26 |
# File 'lib/groseillier/locale.rb', line 20 def collection_select(default = false) locales = available.dup locales.map! { |locale| [ human_name(locale), locale ] } locales.sort! { |a, b| a.first <=> b.first } locales.insert(0, [human_name(''), '']) if default locales end |
.human_name(locale) ⇒ Object
Convert locale (ex: :en) to human name (ex: English)
6 7 8 9 10 11 12 |
# File 'lib/groseillier/locale.rb', line 6 def human_name(locale) if locale.blank? I18n.t('locale.default', locale_name: I18n.t('locale.name', locale: default_locale)) else I18n.t('locale.name', locale: locale) end end |