Sha256: 4dd82320db3f7de16d5499bb1d5121d2410fe0652c8aec24d1f834bfaa89f925

Contents?: true

Size: 914 Bytes

Versions: 7

Compression:

Stored size: 914 Bytes

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Localized

    class LocalizedObject

      attr_reader :locale, :base_obj, :formatter

      def initialize(obj, locale, options = {})
        @base_obj = obj
        @locale = TwitterCldr.convert_locale(locale)
        @locale = TwitterCldr::DEFAULT_LOCALE unless TwitterCldr.supported_locale?(@locale)

        options = options.dup
        options[:locale] = @locale

        @formatter = formatter_const.new(options) if formatter_const
      end

      def formatter_const
        raise NotImplementedError
      end

      def self.localize(klass)
        klass.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
          def localize(locale = TwitterCldr.get_locale, options = {})
            #{self}.new(self, locale, options)
          end
        LOCALIZE
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
twitter_cldr-2.0.2 lib/twitter_cldr/localized/localized_object.rb
twitter_cldr-2.0.1 lib/twitter_cldr/localized/localized_object.rb
twitter_cldr-2.0.0 lib/twitter_cldr/localized/localized_object.rb
twitter_cldr-1.9.1 lib/twitter_cldr/localized/localized_object.rb
twitter_cldr-1.9.0 lib/twitter_cldr/localized/localized_object.rb
twitter_cldr-1.8.1 lib/twitter_cldr/localized/localized_object.rb
twitter_cldr-1.8.0 lib/twitter_cldr/localized/localized_object.rb