module Translatable
Helper class for storing values per locale. Used by Globalize::Adapter to stash and cache attribute values.
Constants
- VERSION
Public Class Methods
add_translatable(klass)
click to toggle source
# File lib/translatable.rb, line 40 def add_translatable(klass) if @@translatable.has_key? klass.name klass.translated_attribute_names.each do |attr| @@translatable[klass.name] << attr unless @@translatable[klass.name].include?(attr) end else @@translatable[klass.name] = klass.translated_attribute_names end unless klass.translated_serialized_attributes.nil? @@translatable[klass.name].map! do |attr| serialized = klass.translated_serialized_attributes.reject{|k,v| k != attr} serialized.empty? ? attr : serialized end end end
list()
click to toggle source
Hash of models that are translatable (values are the attrs)
# File lib/translatable.rb, line 36 def list @@translatable ||= Hash.new end
locale()
click to toggle source
# File lib/translatable.rb, line 9 def locale read_locale || I18n.locale end
locale=(locale)
click to toggle source
# File lib/translatable.rb, line 13 def locale=(locale) set_locale(locale) end
translation_class()
click to toggle source
# File lib/translatable.rb, line 31 def translation_class @@translation_class ||= nil end
translation_class_name=(klass)
click to toggle source
# File lib/translatable.rb, line 28 def translation_class_name=(klass) @@translation_class = klass.constantize end
with_locale(locale) { |locale| ... }
click to toggle source
# File lib/translatable.rb, line 17 def with_locale(locale, &block) previous_locale = read_locale begin set_locale(locale) result = yield(locale) ensure set_locale(previous_locale) end result end
Protected Class Methods
read_locale()
click to toggle source
# File lib/translatable.rb, line 59 def read_locale Thread.current[:translatable_locale] end
set_locale(locale)
click to toggle source
# File lib/translatable.rb, line 63 def set_locale(locale) Thread.current[:translatable_locale] = locale.try(:to_sym) end