Sha256: 320e6dfc72ecbf0626adebcb11eb0367eec23bab891d405788ea30a2083384a7

Contents?: true

Size: 1.24 KB

Versions: 53

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require_relative "cldr/date_format_pattern"
require_relative "cldr/fallbacks"
require_relative "ruby_i18n_config"

module Worldwide
  module Cldr
    FALLBACKS = Worldwide::Cldr::Fallbacks.new
    CONFIG = Worldwide::RubyI18nConfig.new.tap do |cldr_config|
      cldr_config.exception_handler = Worldwide::Config.exception_handler
    end

    class << self
      def fallbacks
        FALLBACKS
      end

      def config
        CONFIG
      end

      private

      def respond_to_missing?(method_name, include_private = false)
        I18n.respond_to?(method_name, include_private)
      end

      def method_missing(method_name, *args, **kwargs, &block)
        with_cldr do
          I18n.send(method_name, *args, **kwargs, &block)
        end
      end

      def with_cldr(&block)
        original_fallbacks = Thread.current[:i18n_fallbacks]
        Thread.current[:i18n_fallbacks] = fallbacks

        locale = I18n.locale
        original_config = Thread.current[:i18n_config]
        Thread.current[:i18n_config] = config

        I18n.with_locale(locale, &block)
      ensure
        Thread.current[:i18n_fallbacks] = original_fallbacks
        Thread.current[:i18n_config] = original_config
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
worldwide-1.14.1 lib/worldwide/cldr.rb
worldwide-1.14.0 lib/worldwide/cldr.rb
worldwide-1.13.0 lib/worldwide/cldr.rb
worldwide-1.12.0 lib/worldwide/cldr.rb
worldwide-1.11.1 lib/worldwide/cldr.rb
worldwide-1.11.0 lib/worldwide/cldr.rb
worldwide-1.10.0 lib/worldwide/cldr.rb
worldwide-1.9.0 lib/worldwide/cldr.rb
worldwide-1.8.0 lib/worldwide/cldr.rb
worldwide-1.7.5 lib/worldwide/cldr.rb
worldwide-1.7.4 lib/worldwide/cldr.rb
worldwide-1.7.3 lib/worldwide/cldr.rb
worldwide-1.7.2 lib/worldwide/cldr.rb
worldwide-1.7.1 lib/worldwide/cldr.rb
worldwide-1.7.0 lib/worldwide/cldr.rb
worldwide-1.6.2 lib/worldwide/cldr.rb
worldwide-1.6.1 lib/worldwide/cldr.rb
worldwide-1.6.0 lib/worldwide/cldr.rb
worldwide-1.5.0 lib/worldwide/cldr.rb
worldwide-1.4.1 lib/worldwide/cldr.rb