Class: RailsI18nterface::Translation
- Inherits:
-
Object
- Object
- RailsI18nterface::Translation
- Defined in:
- lib/rails-i18nterface/translation.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#from_text ⇒ Object
readonly
Returns the value of attribute from_text.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#persisted ⇒ Object
Returns the value of attribute persisted.
-
#to_text ⇒ Object
readonly
Returns the value of attribute to_text.
Instance Method Summary collapse
-
#initialize(key, from, to) ⇒ Translation
constructor
A new instance of Translation.
- #lookup(locale, key) ⇒ Object
- #n_lines(text) ⇒ Object
Constructor Details
#initialize(key, from, to) ⇒ Translation
Returns a new instance of Translation.
9 10 11 12 13 14 15 16 17 |
# File 'lib/rails-i18nterface/translation.rb', line 9 def initialize(key, from, to) @key = key @from_text = lookup(from, key) @to_text = lookup(to, key) @lines = n_lines(@to_text) @id = key.gsub(/\./, '_') @files = [] @persisted = true end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
6 7 8 |
# File 'lib/rails-i18nterface/translation.rb', line 6 def files @files end |
#from_text ⇒ Object (readonly)
Returns the value of attribute from_text.
7 8 9 |
# File 'lib/rails-i18nterface/translation.rb', line 7 def from_text @from_text end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/rails-i18nterface/translation.rb', line 7 def id @id end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/rails-i18nterface/translation.rb', line 7 def key @key end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
7 8 9 |
# File 'lib/rails-i18nterface/translation.rb', line 7 def lines @lines end |
#persisted ⇒ Object
Returns the value of attribute persisted.
6 7 8 |
# File 'lib/rails-i18nterface/translation.rb', line 6 def persisted @persisted end |
#to_text ⇒ Object (readonly)
Returns the value of attribute to_text.
7 8 9 |
# File 'lib/rails-i18nterface/translation.rb', line 7 def to_text @to_text end |
Instance Method Details
#lookup(locale, key) ⇒ Object
19 20 21 |
# File 'lib/rails-i18nterface/translation.rb', line 19 def lookup(locale, key) I18n.backend.send(:lookup, locale, key) end |
#n_lines(text) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rails-i18nterface/translation.rb', line 23 def n_lines(text) n_lines = 1 line_size = 100 if text.present? n_lines = text.to_s.split("\n").size n_lines = text.to_s.length / line_size + 1 if n_lines == 1 && text.to_s.length > line_size end n_lines end |