Class: Translation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Translation
- Defined in:
- lib/models/translation.rb
Class Method Summary collapse
-
.ck(locale, key, hash = true) ⇒ Object
create cache key.
-
.hk(key) ⇒ Object
create hash key.
Instance Method Summary collapse
Class Method Details
.ck(locale, key, hash = true) ⇒ Object
create cache key
31 32 33 34 |
# File 'lib/models/translation.rb', line 31 def self.ck(locale, key, hash=true) key = self.hk(key) if hash "#{locale.code}:#{key}" end |
.hk(key) ⇒ Object
create hash key
26 27 28 |
# File 'lib/models/translation.rb', line 26 def self.hk(key) Base64.encode64(Digest::MD5.hexdigest(key.to_s)).gsub(/\n/, '') end |
Instance Method Details
#default_locale_value(rescue_value = 'No default locale value') ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/models/translation.rb', line 12 def default_locale_value(rescue_value='No default locale value') begin Locale.default_locale.translations.find_by_key_and_pluralization_index(self.key, self.pluralization_index).value rescue rescue_value end end |
#value_or_default ⇒ Object
20 21 22 23 |
# File 'lib/models/translation.rb', line 20 def value_or_default value = self.value || self.default_locale_value(self.raw_key) value =~ /^---(.*)\n/ ? YAML.load(value) : value # supports using YAML e.g. order: [ :year, :month, :day ] values are stored as Symbols "--- :year\n", "--- :month\n", "--- :day\n" end |