Class: RailsI18nterface::Translation

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-i18nterface/translation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filesObject

Returns the value of attribute files.



6
7
8
# File 'lib/rails-i18nterface/translation.rb', line 6

def files
  @files
end

#from_textObject (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

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/rails-i18nterface/translation.rb', line 7

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/rails-i18nterface/translation.rb', line 7

def key
  @key
end

#linesObject (readonly)

Returns the value of attribute lines.



7
8
9
# File 'lib/rails-i18nterface/translation.rb', line 7

def lines
  @lines
end

#persistedObject

Returns the value of attribute persisted.



6
7
8
# File 'lib/rails-i18nterface/translation.rb', line 6

def persisted
  @persisted
end

#to_textObject (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