Class: Vinber::Translate
- Inherits:
-
Object
- Object
- Vinber::Translate
- Defined in:
- lib/vinber/translate.rb
Constant Summary collapse
- VALUE_BOOL_LABLE =
"vinber.%{key}"
- VALUE_COMMON_LABLE =
"vinber.%{attribute}_%{key}"
- VALUE_LABLE =
"vinber.%{klass}.%{attribute}_%{key}"
Instance Method Summary collapse
-
#initialize(klass, attribute, attribute_vinber_key) ⇒ Translate
constructor
A new instance of Translate.
- #label ⇒ Object
- #text ⇒ Object (also: #to_s)
Constructor Details
#initialize(klass, attribute, attribute_vinber_key) ⇒ Translate
Returns a new instance of Translate.
8 9 10 11 12 13 14 |
# File 'lib/vinber/translate.rb', line 8 def initialize(klass, attribute, attribute_vinber_key) @label = { :klass => (klass.is_a?(Class) ? klass.name : klass), :attribute => attribute, :key => attribute_vinber_key } end |
Instance Method Details
#label ⇒ Object
16 17 18 |
# File 'lib/vinber/translate.rb', line 16 def label @label ||= %() end |
#text ⇒ Object Also known as: to_s
20 21 22 23 24 |
# File 'lib/vinber/translate.rb', line 20 def text @text ||= I18n.t((VALUE_LABLE % label), default: nil) || I18n.t((VALUE_COMMON_LABLE % label), default: nil) || I18n.t((VALUE_BOOL_LABLE % label), default: label[:key].to_s.humanize) end |