Module: ClassyEnum::Translation
- Included in:
- Base
- Defined in:
- lib/classy_enum/translation.rb
Instance Method Summary collapse
-
#text ⇒ Object
Returns a translated string of the enum type.
Instance Method Details
#text ⇒ Object
Returns a translated string of the enum type. Used internally to create the select_options array.
Translation location is: locale.classy_enum.base_class.enum_string
Example
# Create an Enum with some elements
class Priority < ClassyEnum::Base
end
class Priority::Low < Priority; end
class Priority::ReallyHigh < Priority; end
# Default translations are `to_s.titlieze`
Priority::Low.new.text # => 'Low'
Priority::ReallyHigh.new.text # => 'Really High'
# Assuming we have a translation defined for:
# es.classy_enum.priority.low # => 'Bajo'
Priority::Low.new.text # => 'Bajo'
28 29 30 |
# File 'lib/classy_enum/translation.rb', line 28 def text I18n.translate to_s, :scope => i18n_scope, :default => to_s.titleize end |