Sha256: a2560c746f06cd62bc179cf4ba14d08f0dccc65bc61a53ea43b60ea1eaeb604e

Contents?: true

Size: 1.62 KB

Versions: 141

Compression:

Stored size: 1.62 KB

Contents

require 'test_helper'

class I18nBackendMetadataTest < Test::Unit::TestCase
  class Backend < I18n::Backend::Simple
    include I18n::Backend::Metadata
  end

  def setup
    I18n.backend = Backend.new
    store_translations(:en, :foo => 'Hi %{name}')
  end

  test "translation strings carry metadata" do
    translation = I18n.t(:foo, :name => 'David')
    assert translation.respond_to?(:translation_metadata)
    assert translation.translation_metadata.is_a?(Hash)
  end

  test "translate adds the locale to metadata on Strings" do
    assert_equal :en, I18n.t(:foo, :name => 'David', :locale => :en).translation_metadata[:locale]
  end

  test "translate adds the key to metadata on Strings" do
    assert_equal :foo, I18n.t(:foo, :name => 'David').translation_metadata[:key]
  end

  test "translate adds the default to metadata on Strings" do
    assert_equal 'bar', I18n.t(:foo, :default => 'bar', :name => '').translation_metadata[:default]
  end

  test "translation adds the interpolation values to metadata on Strings" do
    assert_equal({:name => 'David'}, I18n.t(:foo, :name => 'David').translation_metadata[:values])
  end

  test "interpolation adds the original string to metadata on Strings" do
    assert_equal('Hi %{name}', I18n.t(:foo, :name => 'David').translation_metadata[:original])
  end

  test "pluralization adds the count to metadata on Strings" do
    assert_equal(1, I18n.t(:missing, :count => 1, :default => { :one => 'foo' }).translation_metadata[:count])
  end

  test "metadata works with frozen values" do
    assert_equal(1, I18n.t(:missing, :count => 1, :default => 'foo'.freeze).translation_metadata[:count])
  end
end

Version data entries

141 entries across 120 versions & 41 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/i18n-0.6.9/test/backend/metadata_test.rb