Class: QTranslate::Translation
- Inherits:
-
Object
- Object
- QTranslate::Translation
- Defined in:
- lib/q_translate.rb
Instance Attribute Summary collapse
-
#fallback ⇒ Object
Returns the value of attribute fallback.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text, options = {}) ⇒ Translation
constructor
A new instance of Translation.
- #translate ⇒ Object
- #translations ⇒ Object
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, ={} @text = text @locale = [:locale] || I18n.locale @fallback = [:fallback] || true end |
Instance Attribute Details
#fallback ⇒ Object
Returns the value of attribute fallback.
6 7 8 |
# File 'lib/q_translate.rb', line 6 def fallback @fallback end |
#locale ⇒ Object
Returns the value of attribute locale.
6 7 8 |
# File 'lib/q_translate.rb', line 6 def locale @locale end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/q_translate.rb', line 6 def text @text end |
Instance Method Details
#translate ⇒ Object
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 |
#translations ⇒ Object
22 23 24 25 |
# File 'lib/q_translate.rb', line 22 def translations @translations ||= split_locales @translations end |