[DRE-commits] [SCM] ruby-i18n.git branch, master, updated. debian/0.6.0-3-17-gdb5f289
Praveen Arimbrathodiyil
praveen at debian.org
Mon Jun 3 19:40:29 UTC 2013
The following commit has been merged in the master branch:
commit b9eb5848f9f1a3a8ed065665f9d60bcfe31991ce
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date: Mon Jun 3 19:19:23 2013 +0530
Imported Upstream version 0.6.1
diff --git a/README.textile b/README.textile
index 54e331f..57b79c1 100644
--- a/README.textile
+++ b/README.textile
@@ -1,5 +1,7 @@
h1. Ruby I18n
+!https://secure.travis-ci.org/svenfuchs/i18n.png?branch=master(Build Status)!:http://travis-ci.org/svenfuchs/i18n
+
Ruby Internationalization and localization solution.
Features:
diff --git a/lib/i18n.rb b/lib/i18n.rb
index b49479c..a351b4a 100755
--- a/lib/i18n.rb
+++ b/lib/i18n.rb
@@ -12,7 +12,7 @@ module I18n
RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :throw, :raise, :rescue_format]
RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
- class << self
+ extend Module.new {
# Gets I18n configuration object.
def config
Thread.current[:i18n_config] ||= I18n::Config.new
@@ -160,6 +160,8 @@ module I18n
end
alias :t :translate
+ # Wrapper for <tt>translate</tt> that adds <tt>:raise => true</tt>. With
+ # this option, if no translation is found, it will raise <tt>I18n::MissingTranslationData</tt>
def translate!(key, options={})
translate(key, options.merge(:raise => true))
end
@@ -220,12 +222,11 @@ module I18n
options = args.pop if args.last.is_a?(Hash)
key = args.shift
locale = options && options.delete(:locale) || config.locale
- raises = options && options.delete(:raise)
+ handling = options && (options.delete(:throw) && :throw || options.delete(:raise) && :raise)
replacement = options && options.delete(:replacement)
config.backend.transliterate(locale, key, replacement)
rescue I18n::ArgumentError => exception
- raise exception if raises
- handle_exception(exception, locale, key, options)
+ handle_exception(handling, exception, locale, key, options || {})
end
# Localizes certain objects, such as dates and numbers to local formatting.
@@ -327,5 +328,5 @@ module I18n
"(an instance of which is set to I18n.exception_handler by default)."
exception.is_a?(MissingTranslation) ? exception.message : raise(exception)
end
- end
+ }
end
diff --git a/lib/i18n/backend/base.rb b/lib/i18n/backend/base.rb
index a9e70fd..0b6217c 100644
--- a/lib/i18n/backend/base.rb
+++ b/lib/i18n/backend/base.rb
@@ -168,7 +168,13 @@ module I18n
# Loads a YAML translations file. The data must have locales as
# toplevel keys.
def load_yml(filename)
- YAML.load_file(filename)
+ begin
+ YAML.load_file(filename)
+ rescue TypeError
+ nil
+ rescue SyntaxError
+ nil
+ end
end
end
end
diff --git a/lib/i18n/backend/cache.rb b/lib/i18n/backend/cache.rb
index 6757341..3c456ff 100644
--- a/lib/i18n/backend/cache.rb
+++ b/lib/i18n/backend/cache.rb
@@ -4,7 +4,7 @@
# To enable caching you can simply include the Cache module to the Simple
# backend - or whatever other backend you are using:
#
-# I18n::Backend::Simple.include(I18n::Backend::Cache)
+# I18n::Backend::Simple.send(:include, I18n::Backend::Cache)
#
# You will also need to set a cache store implementation that you want to use:
#
diff --git a/lib/i18n/backend/cascade.rb b/lib/i18n/backend/cascade.rb
index 66758a2..d8fb1cf 100644
--- a/lib/i18n/backend/cascade.rb
+++ b/lib/i18n/backend/cascade.rb
@@ -46,6 +46,7 @@ module I18n
begin
result = super
return result unless result.nil?
+ scope = scope.dup
end while (!scope.empty? || !skip_root) && scope.slice!(-step, step)
end
end
diff --git a/lib/i18n/backend/fallbacks.rb b/lib/i18n/backend/fallbacks.rb
index 70c2c04..7252bb0 100644
--- a/lib/i18n/backend/fallbacks.rb
+++ b/lib/i18n/backend/fallbacks.rb
@@ -31,12 +31,12 @@ module I18n
# the given options. If it does not find any result for any of the
# locales it will then throw MissingTranslation as usual.
#
- # The default option takes precedence over fallback locales
- # only when it's a Symbol. When the default contains a String or a Proc
+ # The default option takes precedence over fallback locales only when
+ # it's a Symbol. When the default contains a String, Proc or Hash
# it is evaluated last after all the fallback locales have been tried.
def translate(locale, key, options = {})
return super if options[:fallback]
- default = extract_string_or_lambda_default!(options) if options[:default]
+ default = extract_non_symbol_default!(options) if options[:default]
options[:fallback] = true
I18n.fallbacks[locale].each do |fallback|
@@ -51,18 +51,15 @@ module I18n
throw(:exception, I18n::MissingTranslation.new(locale, key, options))
end
- def extract_string_or_lambda_default!(options)
+ def extract_non_symbol_default!(options)
defaults = [options[:default]].flatten
- if index = find_first_string_or_lambda_default(defaults)
- options[:default] = defaults[0, index]
- defaults[index]
+ first_non_symbol_default = defaults.detect{|default| !default.is_a?(Symbol)}
+ if first_non_symbol_default
+ options[:default] = defaults[0, defaults.index(first_non_symbol_default)]
end
+ return first_non_symbol_default
end
- def find_first_string_or_lambda_default(defaults)
- defaults.each_with_index { |default, ix| return ix if String === default || Proc === default }
- nil
- end
end
end
end
diff --git a/lib/i18n/backend/gettext.rb b/lib/i18n/backend/gettext.rb
index f84ff2d..c357a6d 100644
--- a/lib/i18n/backend/gettext.rb
+++ b/lib/i18n/backend/gettext.rb
@@ -40,6 +40,7 @@ module I18n
def normalize(locale, data)
data.inject({}) do |result, (key, value)|
unless key.nil? || key.empty?
+ key = key.gsub(I18n::Gettext::CONTEXT_SEPARATOR, '|')
key, value = normalize_pluralization(locale, key, value) if key.index("\000")
parts = key.split('|').reverse
@@ -59,7 +60,7 @@ module I18n
keys = I18n::Gettext.plural_keys(locale)
values = value.split("\000")
- raise "invalid number of plurals: #{values.size}, keys: #{keys.inspect}" if values.size != keys.size
+ raise "invalid number of plurals: #{values.size}, keys: #{keys.inspect} on #{locale} locale for msgid #{key.inspect} with values #{values.inspect}" if values.size != keys.size
result = {}
values.each_with_index { |_value, ix| result[keys[ix]] = _value }
diff --git a/lib/i18n/backend/key_value.rb b/lib/i18n/backend/key_value.rb
index df80718..c34b797 100644
--- a/lib/i18n/backend/key_value.rb
+++ b/lib/i18n/backend/key_value.rb
@@ -73,7 +73,7 @@ module I18n
raise "Key-value stores cannot handle procs"
end
- @store[key] = ActiveSupport::JSON.encode(value) unless value.is_a?(Symbol)
+ @store[key] = ActiveSupport::JSON.encode([value]) unless value.is_a?(Symbol)
end
end
@@ -90,7 +90,7 @@ module I18n
def lookup(locale, key, scope = [], options = {})
key = normalize_flat_keys(locale, key, scope, options[:separator])
value = @store["#{locale}.#{key}"]
- value = ActiveSupport::JSON.decode(value) if value
+ value = ActiveSupport::JSON.decode(value)[0] if value
value.is_a?(Hash) ? value.deep_symbolize_keys : value
end
end
diff --git a/lib/i18n/backend/pluralization.rb b/lib/i18n/backend/pluralization.rb
index 875040c..c73a009 100644
--- a/lib/i18n/backend/pluralization.rb
+++ b/lib/i18n/backend/pluralization.rb
@@ -1,7 +1,5 @@
-# I18n locale fallbacks are useful when you want your application to use
-# translations from other locales when translations for the current locale are
-# missing. E.g. you might want to use :en translations when translations in
-# your applications main locale :de are missing.
+# I18n Pluralization are useful when you want your application to
+# customize pluralization rules.
#
# To enable locale specific pluralizations you can simply include the
# Pluralization module to the Simple backend - or whatever other backend you
diff --git a/lib/i18n/locale/fallbacks.rb b/lib/i18n/locale/fallbacks.rb
index 589817c..08bf6f5 100644
--- a/lib/i18n/locale/fallbacks.rb
+++ b/lib/i18n/locale/fallbacks.rb
@@ -25,12 +25,12 @@
# # using the default locale as default fallback locale
#
# I18n.default_locale = :"en-US"
-# I18n.fallbacks = I18n::Fallbacks.new(:"de-AT" => :"de-DE")
+# I18n.fallbacks = I18n::Locale::Fallbacks.new(:"de-AT" => :"de-DE")
# I18n.fallbacks[:"de-AT"] # => [:"de-AT", :"de-DE", :de, :"en-US", :en]
#
# # using a custom locale as default fallback locale
#
-# I18n.fallbacks = I18n::Fallbacks.new(:"en-GB", :"de-AT" => :de, :"de-CH" => :de)
+# I18n.fallbacks = I18n::Locale::Fallbacks.new(:"en-GB", :"de-AT" => :de, :"de-CH" => :de)
# I18n.fallbacks[:"de-AT"] # => [:"de-AT", :de, :"en-GB", :en]
# I18n.fallbacks[:"de-CH"] # => [:"de-CH", :de, :"en-GB", :en]
#
@@ -82,10 +82,10 @@ module I18n
protected
- def compute(tags, include_defaults = true)
+ def compute(tags, include_defaults = true, exclude = [])
result = Array(tags).collect do |tag|
- tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym }
- tags.each { |_tag| tags += compute(@map[_tag]) if @map[_tag] }
+ tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym } - exclude
+ tags.each { |_tag| tags += compute(@map[_tag], false, exclude + tags) if @map[_tag] }
tags
end.flatten
result.push(*defaults) if include_defaults
diff --git a/lib/i18n/version.rb b/lib/i18n/version.rb
index 8e9db4f..9249aa8 100644
--- a/lib/i18n/version.rb
+++ b/lib/i18n/version.rb
@@ -1,3 +1,3 @@
module I18n
- VERSION = "0.6.0"
+ VERSION = "0.6.1"
end
diff --git a/metadata.yml b/metadata.yml
index 1f53560..f820942 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,15 +1,10 @@
---- !ruby/object:Gem::Specification
+--- !ruby/object:Gem::Specification
name: i18n
-version: !ruby/object:Gem::Version
- hash: 7
+version: !ruby/object:Gem::Version
+ version: 0.6.1
prerelease:
- segments:
- - 0
- - 6
- - 0
- version: 0.6.0
platform: ruby
-authors:
+authors:
- Sven Fuchs
- Joshua Harvey
- Matt Aimonetti
@@ -18,77 +13,78 @@ authors:
autorequire:
bindir: bin
cert_chain: []
-
-date: 2011-05-22 00:00:00 +02:00
-default_executable:
-dependencies:
-- !ruby/object:Gem::Dependency
+date: 2012-08-31 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
name: activesupport
- prerelease: false
- requirement: &id001 !ruby/object:Gem::Requirement
+ requirement: !ruby/object:Gem::Requirement
none: false
- requirements:
+ requirements:
- - ~>
- - !ruby/object:Gem::Version
- hash: 7
- segments:
- - 3
- - 0
- - 0
+ - !ruby/object:Gem::Version
version: 3.0.0
type: :development
- version_requirements: *id001
-- !ruby/object:Gem::Dependency
- name: sqlite3
prerelease: false
- requirement: &id002 !ruby/object:Gem::Requirement
+ version_requirements: !ruby/object:Gem::Requirement
none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+ requirements:
+ - - ~>
+ - !ruby/object:Gem::Version
+ version: 3.0.0
+- !ruby/object:Gem::Dependency
+ name: sqlite3
+ requirement: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
type: :development
- version_requirements: *id002
-- !ruby/object:Gem::Dependency
- name: mocha
prerelease: false
- requirement: &id003 !ruby/object:Gem::Requirement
+ version_requirements: !ruby/object:Gem::Requirement
none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: mocha
+ requirement: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
type: :development
- version_requirements: *id003
-- !ruby/object:Gem::Dependency
- name: test_declarative
prerelease: false
- requirement: &id004 !ruby/object:Gem::Requirement
+ version_requirements: !ruby/object:Gem::Requirement
none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: test_declarative
+ requirement: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
type: :development
- version_requirements: *id004
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ none: false
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
description: New wave Internationalization support for Ruby.
email: rails-i18n at googlegroups.com
executables: []
-
extensions: []
-
extra_rdoc_files: []
-
-files:
+files:
- ci/Gemfile.no-rails
- ci/Gemfile.no-rails.lock
- ci/Gemfile.rails-2.3.x
@@ -147,6 +143,7 @@ files:
- test/api/fallbacks_test.rb
- test/api/key_value_test.rb
- test/api/memoize_test.rb
+- test/api/override_test.rb
- test/api/pluralization_test.rb
- test/api/simple_test.rb
- test/backend/cache_test.rb
@@ -182,41 +179,29 @@ files:
- README.textile
- MIT-LICENSE
- CHANGELOG.textile
-has_rdoc: true
homepage: http://github.com/svenfuchs/i18n
licenses: []
-
post_install_message:
rdoc_options: []
-
-require_paths:
+require_paths:
- lib
-required_ruby_version: !ruby/object:Gem::Requirement
+required_ruby_version: !ruby/object:Gem::Requirement
none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
-required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
+ version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
none: false
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- hash: 17
- segments:
- - 1
- - 3
- - 5
+ requirements:
+ - - ! '>='
+ - !ruby/object:Gem::Version
version: 1.3.5
requirements: []
-
-rubyforge_project: "[none]"
-rubygems_version: 1.4.2
+rubyforge_project: ! '[none]'
+rubygems_version: 1.8.23
signing_key:
specification_version: 3
summary: New wave Internationalization support for Ruby
test_files: []
-
+has_rdoc:
diff --git a/test/api/override_test.rb b/test/api/override_test.rb
new file mode 100644
index 0000000..1f4e564
--- /dev/null
+++ b/test/api/override_test.rb
@@ -0,0 +1,48 @@
+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
diff --git a/test/backend/fallbacks_test.rb b/test/backend/fallbacks_test.rb
index e743639..2b17da9 100644
--- a/test/backend/fallbacks_test.rb
+++ b/test/backend/fallbacks_test.rb
@@ -48,6 +48,11 @@ class I18nBackendFallbacksTranslateTest < Test::Unit::TestCase
assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => Proc.new { "Default Bar" })
end
+ test "returns the :de translation for a missing :'de-DE' when :default is a Hash" do
+ assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => {})
+ assert_equal({}, I18n.t(:missing_bar, :locale => :'de-DE', :default => {}))
+ end
+
test "returns the :'de-DE' default :baz translation for a missing :'de-DE' when defaults contains Symbol" do
assert_equal 'Baz in :de-DE', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:baz, "Default Bar"])
end
diff --git a/test/backend/metadata_test.rb b/test/backend/metadata_test.rb
index 96e9f6d..584c7f6 100644
--- a/test/backend/metadata_test.rb
+++ b/test/backend/metadata_test.rb
@@ -16,16 +16,6 @@ class I18nBackendMetadataTest < Test::Unit::TestCase
assert translation.translation_metadata.is_a?(Hash)
end
- test "translate preserves metadata stored on original Strings" do
- store_metadata(:foo, :bar, 'bar')
- assert_equal 'bar', I18n.t(:foo, :name => 'David').translation_metadata[:bar]
- end
-
- test "translate preserves metadata stored on original Strings (when interpolated)" do
- store_metadata(:foo, :bar, 'bar')
- assert_equal 'bar', I18n.t(:foo, :name => 'David').translation_metadata[:bar]
- 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
@@ -33,7 +23,7 @@ class I18nBackendMetadataTest < Test::Unit::TestCase
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
@@ -53,15 +43,5 @@ class I18nBackendMetadataTest < Test::Unit::TestCase
test "metadata works with frozen values" do
assert_equal(1, I18n.t(:missing, :count => 1, :default => 'foo'.freeze).translation_metadata[:count])
end
-
- protected
-
- def translations
- I18n.backend.instance_variable_get(:@translations)
- end
-
- def store_metadata(key, name, value)
- translations[:en][key].translation_metadata[name] = value
- end
end
diff --git a/test/gettext/backend_test.rb b/test/gettext/backend_test.rb
index ecb6e0c..39c64b3 100644
--- a/test/gettext/backend_test.rb
+++ b/test/gettext/backend_test.rb
@@ -43,11 +43,13 @@ unless RUBY_VERSION == '1.9.1' && RUBY_PATCHLEVEL <= 129
I18n.locale = :de
assert_equal 'Räderzahl', sgettext('Car|Wheels count')
assert_equal 'Räderzahl', pgettext('Car', 'Wheels count')
+ assert_equal 'Räderzahl!', pgettext('New car', 'Wheels count')
end
def test_uses_namespaced_default_translation
assert_equal 'Wheels count', sgettext('Car|Wheels count')
assert_equal 'Wheels count', pgettext('Car', 'Wheels count')
+ assert_equal 'Wheels count', pgettext('New car', 'Wheels count')
end
def test_pluralizes_entry
@@ -67,6 +69,8 @@ unless RUBY_VERSION == '1.9.1' && RUBY_PATCHLEVEL <= 129
assert_equal 'Räder', nsgettext('Car|wheel', 'wheels', 2)
assert_equal 'Rad', npgettext('Car', 'wheel', 'wheels', 1)
assert_equal 'Räder', npgettext('Car', 'wheel', 'wheels', 2)
+ assert_equal 'Rad!', npgettext('New car', 'wheel', 'wheels', 1)
+ assert_equal 'Räder!', npgettext('New car', 'wheel', 'wheels', 2)
end
def test_pluralizes_namespaced_default_entry
@@ -74,6 +78,8 @@ unless RUBY_VERSION == '1.9.1' && RUBY_PATCHLEVEL <= 129
assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
assert_equal 'wheels', npgettext('Car', 'wheel', 'wheels', 2)
+ assert_equal 'wheel', npgettext('New car', 'wheel', 'wheels', 1)
+ assert_equal 'wheels', npgettext('New car', 'wheel', 'wheels', 2)
end
def test_pluralizes_namespaced_entry_with_alternative_syntax
@@ -82,6 +88,8 @@ unless RUBY_VERSION == '1.9.1' && RUBY_PATCHLEVEL <= 129
assert_equal 'Räder', nsgettext(['Car|wheel', 'wheels'], 2)
assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
+ assert_equal 'Rad!', npgettext('New car', ['wheel', 'wheels'], 1)
+ assert_equal 'Räder!', npgettext('New car', ['wheel', 'wheels'], 2)
end
def test_ngettextpluralizes_entry_with_dots
diff --git a/test/i18n_test.rb b/test/i18n_test.rb
index ad7872e..c7e4aad 100644
--- a/test/i18n_test.rb
+++ b/test/i18n_test.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'test_helper'
class I18nTest < Test::Unit::TestCase
@@ -233,4 +234,21 @@ class I18nTest < Test::Unit::TestCase
assert_raise(I18n::ArgumentError) { I18n.with_locale(:pl) { raise I18n::ArgumentError } }
assert_equal I18n.default_locale, I18n.locale
end
+
+ test "I18n.translitarate handles I18n::ArgumentError exception" do
+ I18n::Backend::Transliterator.stubs(:get).raises(I18n::ArgumentError)
+ I18n.exception_handler.expects(:call).raises(I18n::ArgumentError)
+ assert_raise(I18n::ArgumentError) {
+ I18n.transliterate("ąćó")
+ }
+ end
+
+ test "I18n.translitarate raises I18n::ArgumentError exception" do
+ I18n::Backend::Transliterator.stubs(:get).raises(I18n::ArgumentError)
+ I18n.exception_handler.expects(:call).never
+ assert_raise(I18n::ArgumentError) {
+ I18n.transliterate("ąćó", :raise => true)
+ }
+ end
+
end
diff --git a/test/locale/fallbacks_test.rb b/test/locale/fallbacks_test.rb
index 951016a..ca5e942 100644
--- a/test/locale/fallbacks_test.rb
+++ b/test/locale/fallbacks_test.rb
@@ -121,4 +121,16 @@ class I18nFallbacksComputationTest < Test::Unit::TestCase
test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
assert_equal [:he, :"en-US", :en], @fallbacks[:he]
end
+
+ # Test allowing mappings that fallback to each other
+
+ test "with :no => :nb, :nb => :no defined :no returns [:no, :nb, :en-US, :en]" do
+ @fallbacks.map(:no => :nb, :nb => :no)
+ assert_equal [:no, :nb, :"en-US", :en], @fallbacks[:no]
+ end
+
+ test "with :no => :nb, :nb => :no defined :nb returns [:nb, :no, :en-US, :en]" do
+ @fallbacks.map(:no => :nb, :nb => :no)
+ assert_equal [:nb, :no, :"en-US", :en], @fallbacks[:nb]
+ end
end
diff --git a/test/test_data/locales/de.po b/test/test_data/locales/de.po
index c162e87..f3c9998 100644
--- a/test/test_data/locales/de.po
+++ b/test/test_data/locales/de.po
@@ -42,6 +42,10 @@ msgstr "Modell"
msgid "Car|Wheels count"
msgstr "Räderzahl"
+msgctxt "New car"
+msgid "Wheels count"
+msgstr "Räderzahl!"
+
#: app/views/cars/show.html.erb:7
msgid "Created"
msgstr "Erstellt"
@@ -66,6 +70,12 @@ msgid_plural "Car|wheels"
msgstr[0] "Rad"
msgstr[1] "Räder"
+msgctxt "New car"
+msgid "wheel"
+msgid_plural "wheels"
+msgstr[0] "Rad!"
+msgstr[1] "Räder!"
+
msgid "On %{count} wheel."
msgid_plural "On %{count} wheels."
msgstr[0] "Auf %{count} Achse."
diff --git a/test/test_data/locales/invalid/empty.yml b/test/test_data/locales/invalid/empty.yml
index d002480..e69de29 100644
--- a/test/test_data/locales/invalid/empty.yml
+++ b/test/test_data/locales/invalid/empty.yml
@@ -1 +0,0 @@
-en:
\ No newline at end of file
diff --git a/test/test_data/locales/plurals.rb b/test/test_data/locales/plurals.rb
index d1ea34e..835e28f 100644
--- a/test/test_data/locales/plurals.rb
+++ b/test/test_data/locales/plurals.rb
@@ -27,7 +27,7 @@
:fi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:fil => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:fo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
- :fr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n && n != 2 ? :one : :other } } } },
+ :fr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n.between?(0, 2) && n != 2 ? :one : :other } } } },
:fur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:fy => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:ga => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
@@ -74,7 +74,7 @@
:or => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:pa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:pap => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
- :pl => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) && ![22, 23, 24].include?(n % 100) ? :few : :other } } } },
+ :pl => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : :other } } } },
:ps => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:pt => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:"pt-PT" => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
--
ruby-i18n.git
More information about the Pkg-ruby-extras-commits
mailing list