Class: I18n::Backend::InlineForms::Translation

Inherits:
InlineForms::Base
  • Object
show all
Defined in:
lib/i18n/backend/inline_forms/translation.rb

Constant Summary collapse

TRUTHY_CHAR =
"\001"
FALSY_CHAR =
"\002"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_localesObject



97
98
99
# File 'lib/i18n/backend/inline_forms/translation.rb', line 97

def available_locales
  Translation.select(:locale).uniq.map { |t| t.locale.to_sym }
end

Instance Method Details

#interpolates?(key) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/i18n/backend/inline_forms/translation.rb', line 102

def interpolates?(key)
  self.interpolations.include?(key) if self.interpolations
end

#valueObject



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/i18n/backend/inline_forms/translation.rb', line 106

def value
  value = read_attribute(:value)
  if is_proc
    Kernel.eval(value)
  elsif value == FALSY_CHAR
    false
  elsif value == TRUTHY_CHAR
    true
  else
    value
  end
end

#value=(value) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/i18n/backend/inline_forms/translation.rb', line 119

def value=(value)
  if value === false
    value = FALSY_CHAR
  elsif value === true
    value = TRUTHY_CHAR
  end

  write_attribute(:value, value)
end