Sha256: 5ccf041533f7c83e14657ff9194cc5392a955da3975ef0588a740fe5d23645a6

Contents?: true

Size: 1.22 KB

Versions: 141

Compression:

Stored size: 1.22 KB

Contents

require 'test_helper'

class I18nOverrideTest < Test::Unit::TestCase
  module OverrideInverse

    def translate(*args)
      super(*args).reverse
    end
    alias :t :translate

  end

  module OverrideSignature

    def translate(*args)
      args.first + args[1]
    end
    alias :t :translate

  end

  def setup
    @I18n = I18n.dup
    @I18n.backend = I18n::Backend::Simple.new
    super
  end

  test "make sure modules can overwrite I18n methods" do
    @I18n.extend OverrideInverse
    @I18n.backend.store_translations('en', :foo => 'bar')

    assert_equal 'rab', @I18n.translate(:foo, :locale => 'en')
    # FIXME: this fails under 1.8.7
    # assert_equal 'rab', @I18n.t(:foo, :locale => 'en')
    assert_equal 'rab', @I18n.translate!(:foo, :locale => 'en')
    assert_equal 'rab', @I18n.t!(:foo, :locale => 'en')
  end

  test "make sure modules can overwrite I18n signature" do
    exception = catch(:exception) do
      @I18n.t('Hello', 'Welcome message on home page', :tokenize => true, :throw => true)
    end
    assert exception.message
    @I18n.extend OverrideSignature
    assert_equal 'HelloWelcome message on home page', @I18n.translate('Hello', 'Welcome message on home page', :tokenize => true) # tr8n example
  end

end

Version data entries

141 entries across 120 versions & 41 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb