Class: QTranslate::Translation

Inherits:
Object
  • Object
show all
Defined in:
lib/q_translate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, options = {}) ⇒ Translation

Returns a new instance of Translation.



8
9
10
11
12
# File 'lib/q_translate.rb', line 8

def initialize text, options={}
  @text = text
  @locale = options[:locale] || I18n.locale
  @fallback = options[:fallback] || true
end

Instance Attribute Details

#fallbackObject

Returns the value of attribute fallback.



6
7
8
# File 'lib/q_translate.rb', line 6

def fallback
  @fallback
end

#localeObject

Returns the value of attribute locale.



6
7
8
# File 'lib/q_translate.rb', line 6

def locale
  @locale
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/q_translate.rb', line 6

def text
  @text
end

Instance Method Details

#translateObject



14
15
16
17
18
19
20
# File 'lib/q_translate.rb', line 14

def translate
  return @text if @text and @text.blank?
  return translations[@locale] if translations.has_key?(@locale)
  return translations[I18n.default_locale] if @fallback and translations.has_key?(I18n.default_locale)
  return '' if translations.keys.any?
  @text
end

#translationsObject



22
23
24
25
# File 'lib/q_translate.rb', line 22

def translations
  @translations ||= split_locales
  @translations
end