Module: ActiveDelegate::Localized
- Defined in:
- lib/active_delegate/localized.rb
Class Method Summary collapse
-
.localized_methods(attributes) ⇒ Object
Get localized methods for attributes.
-
.method_suffixes ⇒ Object
Get method suffixes.
-
.normalize_locale(locale) ⇒ Object
Normalize locale.
Class Method Details
.localized_methods(attributes) ⇒ Object
Get localized methods for attributes
7 8 9 10 11 |
# File 'lib/active_delegate/localized.rb', line 7 def localized_methods(attributes) @localized_methods = attributes.to_a.flat_map do |attribute| method_suffixes.map { |suffix| "#{attribute}#{suffix}" } end end |
.method_suffixes ⇒ Object
Get method suffixes
14 15 16 17 18 |
# File 'lib/active_delegate/localized.rb', line 14 def method_suffixes @method_suffixes ||= I18n.available_locales.map do |locale| "_#{normalize_locale(locale)}" end end |
.normalize_locale(locale) ⇒ Object
Normalize locale
21 22 23 |
# File 'lib/active_delegate/localized.rb', line 21 def normalize_locale(locale) "#{locale.to_s.downcase.sub("-", "_")}".freeze end |