Sha256: e4d5c1b12af3c67492ac5d53cb4e7d5f3e391e7fdbd47b769773089c16c28a6d

Contents?: true

Size: 975 Bytes

Versions: 4

Compression:

Stored size: 975 Bytes

Contents

require 'active_record'
require 'patches/active_record/xml_attribute_serializer'
require 'patches/active_record/query_method'

module Globalize
  autoload :ActiveRecord, 'globalize/active_record'
  autoload :Versioning,   'globalize/versioning'

  class << self
    def locale
      read_locale || I18n.locale
    end

    def locale=(locale)
      set_locale(locale)
    end

    def with_locale(locale, &block)
      previous_locale = read_locale
      set_locale(locale)
      result = yield
      set_locale(previous_locale)
      result
    end

    def fallbacks?
      I18n.respond_to?(:fallbacks)
    end

    def fallbacks(locale = self.locale)
      fallbacks? ? I18n.fallbacks[locale] : [locale.to_sym]
    end

    protected

      def read_locale
        Thread.current[:globalize_locale]
      end

      def set_locale(locale)
        Thread.current[:globalize_locale] = locale
      end
  end
end

ActiveRecord::Base.extend(Globalize::ActiveRecord::ActMacro)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
globalize3-0.1.0.beta lib/globalize.rb
globalize3-0.0.11 lib/globalize.rb
globalize3-0.0.10 lib/globalize.rb
globalize3-0.0.9 lib/globalize.rb