aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/vendor/i18n-0.0.1
diff options
context:
space:
mode:
authorSven Fuchs <svenfuchs@artweb-design.de>2008-08-10 21:44:35 +0200
committerSven Fuchs <svenfuchs@artweb-design.de>2008-08-10 21:44:35 +0200
commit572f73fae62972cc5aebba24bed45a127f2a4cac (patch)
tree0686cf173de73f0fdf5120a159ab9cac5181e950 /activesupport/lib/active_support/vendor/i18n-0.0.1
parentbdf783b5a8b83b1d565027130de4743fda336523 (diff)
downloadrails-572f73fae62972cc5aebba24bed45a127f2a4cac.tar.gz
rails-572f73fae62972cc5aebba24bed45a127f2a4cac.tar.bz2
rails-572f73fae62972cc5aebba24bed45a127f2a4cac.zip
update i18n gem and clean up dir structure within i18n-0.0.1
Diffstat (limited to 'activesupport/lib/active_support/vendor/i18n-0.0.1')
-rwxr-xr-xactivesupport/lib/active_support/vendor/i18n-0.0.1/MIT-LICENSE20
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/README.textile18
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.gemspec24
-rwxr-xr-xactivesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb (renamed from activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n.rb)8
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb (renamed from activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n/backend/simple.rb)42
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb (renamed from activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n/exceptions.rb)8
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/test/all.rb4
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_exceptions_test.rb100
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_test.rb141
-rw-r--r--activesupport/lib/active_support/vendor/i18n-0.0.1/test/simple_backend_test.rb376
10 files changed, 47 insertions, 694 deletions
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/MIT-LICENSE b/activesupport/lib/active_support/vendor/i18n-0.0.1/MIT-LICENSE
deleted file mode 100755
index ed8e9ee66d..0000000000
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/MIT-LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (c) 2008 The Ruby I18n team
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/README.textile b/activesupport/lib/active_support/vendor/i18n-0.0.1/README.textile
deleted file mode 100644
index 2b14a99c0f..0000000000
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/README.textile
+++ /dev/null
@@ -1,18 +0,0 @@
-h1. Ruby I18n gem
-
-I18n and localization solution for Ruby.
-
-h2. Authors
-
-* "Matt Aimonetti":http://railsontherun.com
-* "Sven Fuchs":http://www.artweb-design.de
-* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
-* "Saimon Moore":http://saimonmoore.net
-* "Stephan Soller":http://www.arkanis-development.de
-
-h2. License
-
-MIT License. See the included MIT-LICENCE file.
-
-
-
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.gemspec b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.gemspec
deleted file mode 100644
index 81ad0b598d..0000000000
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.gemspec
+++ /dev/null
@@ -1,24 +0,0 @@
-Gem::Specification.new do |s|
- s.name = "i18n"
- s.version = "0.0.1"
- s.date = "2008-06-13"
- s.summary = "Internationalization for Ruby"
- s.email = "rails-patch-i18n@googlegroups.com"
- s.homepage = "http://groups.google.com/group/rails-patch-i18n"
- s.description = "Add Internationalization to your Ruby application."
- s.has_rdoc = false
- s.authors = ['Sven Fuchs', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore']
- s.files = [
- "lib/i18n/backend/minimal.rb",
- "lib/i18n/core_ext.rb",
- "lib/i18n/localization.rb",
- "lib/i18n/translation.rb",
- "lib/i18n.rb",
- "LICENSE",
- "README",
- "spec/core_ext_spec.rb",
- "spec/i18n_spec.rb",
- "spec/spec.opts",
- "spec/spec_helper.rb"
- ]
-end \ No newline at end of file
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
index 1bb65263a3..86005553c0 100755
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n.rb
+++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
@@ -56,6 +56,10 @@ module I18n
backend.populate(&block)
end
+ def load_translations(filename)
+ backend.load_translations filename
+ end
+
# Stores translations for the given locale in the backend.
def store_translations(locale, data)
backend.store_translations locale, data
@@ -173,8 +177,8 @@ module I18n
# keys are Symbols.
def normalize_translation_keys(locale, key, scope)
keys = [locale] + Array(scope) + [key]
- keys = keys.map{|k| k.to_s.split(/\./) }
- keys.flatten.map{|k| k.to_sym}
+ keys = keys.map{|key| key.to_s.split(/\./) }
+ keys.flatten.map{|key| key.to_sym}
end
end
end
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
index b8be1cecfb..98c7964b21 100644
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n/backend/simple.rb
+++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
@@ -12,6 +12,10 @@ module I18n
def populate(&block)
yield
end
+
+ def load_translations(*filenames)
+ filenames.each {|filename| load_file filename }
+ end
# Stores translations for the given locale in memory.
# This uses a deep merge for the translations hash, so existing
@@ -23,7 +27,7 @@ module I18n
def translate(locale, key, options = {})
raise InvalidLocale.new(locale) if locale.nil?
- return key.map{|k| translate locale, k, options } if key.is_a? Array
+ return key.map{|key| translate locale, key, options } if key.is_a? Array
reserved = :scope, :default
count, scope, default = options.values_at(:count, *reserved)
@@ -31,8 +35,8 @@ module I18n
values = options.reject{|name, value| reserved.include? name }
entry = lookup(locale, key, scope) || default(locale, default, options) || raise(I18n::MissingTranslationData.new(locale, key, options))
- entry = pluralize entry, count
- entry = interpolate entry, values
+ entry = pluralize locale, entry, count
+ entry = interpolate locale, entry, values
entry
end
@@ -66,7 +70,7 @@ module I18n
def lookup(locale, key, scope = [])
return unless key
keys = I18n.send :normalize_translation_keys, locale, key, scope
- keys.inject(@@translations){|result, k| result[k.to_sym] or return nil }
+ keys.inject(@@translations){|result, key| result[key.to_sym] or return nil }
end
# Evaluates a default translation.
@@ -92,10 +96,13 @@ module I18n
# rules. It will pick the first translation if count is not equal to 1
# and the second translation if it is equal to 1. Other backends can
# implement more flexible or complex pluralization rules.
- def pluralize(entry, count)
- return entry unless entry.is_a?(Array) and count
- raise InvalidPluralizationData.new(entry, count) unless entry.size == 2
- entry[count == 1 ? 0 : 1]
+ def pluralize(locale, entry, count)
+ return entry unless entry.is_a?(Hash) and count
+ # raise InvalidPluralizationData.new(entry, count) unless entry.is_a?(Hash)
+ key = :zero if count == 0 && entry.has_key?(:zero)
+ key ||= count == 1 ? :one : :many
+ raise InvalidPluralizationData.new(entry, count) unless entry.has_key?(key)
+ entry[key]
end
# Interpolates values into a given string.
@@ -106,7 +113,7 @@ module I18n
# Note that you have to double escape the <tt>\\</tt> when you want to escape
# the <tt>{{...}}</tt> key in a string (once for the string and once for the
# interpolation).
- def interpolate(string, values = {})
+ def interpolate(locale, string, values = {})
return string if !string.is_a?(String)
map = {'%d' => '{{count}}', '%s' => '{{value}}'} # TODO deprecate this?
@@ -128,6 +135,23 @@ module I18n
s.string
end
+ def load_file(filename)
+ type = File.extname(filename).tr('.', '').downcase
+ raise UnknownFileType.new(type, filename) unless respond_to? :"load_#{type}"
+ data = send :"load_#{type}", filename # TODO raise a meaningful exception if this does not yield a Hash
+ data.each do |locale, data|
+ merge_translations locale, data
+ end
+ end
+
+ def load_rb(filename)
+ eval IO.read(filename), binding, filename
+ end
+
+ def load_yml(filename)
+ YAML::load IO.read(filename)
+ end
+
# Deep merges the given translations hash with the existing translations
# for the given locale
def merge_translations(locale, data)
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n/exceptions.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb
index 6c1fc6d9b6..0f3eff1071 100644
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/lib/i18n/exceptions.rb
+++ b/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb
@@ -42,4 +42,12 @@ module I18n
super "reserved key #{key.inspect} used in #{string.inspect}"
end
end
+
+ class UnknownFileType < ArgumentError
+ attr_reader :type, :filename
+ def initialize(type, filename)
+ @type, @filename = type, filename
+ super "can not load translations from #{filename}, the file type #{type} is not known"
+ end
+ end
end \ No newline at end of file
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/all.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/test/all.rb
deleted file mode 100644
index 048b62f8c3..0000000000
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/all.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-dir = File.dirname(__FILE__)
-require dir + '/i18n_test.rb'
-require dir + '/simple_backend_test.rb'
-require dir + '/i18n_exceptions_test.rb'
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_exceptions_test.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_exceptions_test.rb
deleted file mode 100644
index 1ea1601681..0000000000
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_exceptions_test.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-$:.unshift "lib"
-
-require 'rubygems'
-require 'test/unit'
-require 'mocha'
-require 'i18n'
-require 'active_support'
-
-class I18nExceptionsTest < Test::Unit::TestCase
- def test_invalid_locale_stores_locale
- force_invalid_locale
- rescue I18n::ArgumentError => e
- assert_nil e.locale
- end
-
- def test_invalid_locale_message
- force_invalid_locale
- rescue I18n::ArgumentError => e
- assert_equal 'nil is not a valid locale', e.message
- end
-
- def test_missing_translation_data_stores_locale_key_and_options
- force_missing_translation_data
- rescue I18n::ArgumentError => e
- options = {:scope => :bar}
- assert_equal 'de-DE', e.locale
- assert_equal :foo, e.key
- assert_equal options, e.options
- end
-
- def test_missing_translation_data_message
- force_missing_translation_data
- rescue I18n::ArgumentError => e
- assert_equal 'translation missing: de-DE, bar, foo', e.message
- end
-
- def test_invalid_pluralization_data_stores_entry_and_count
- force_invalid_pluralization_data
- rescue I18n::ArgumentError => e
- assert_equal [:bar], e.entry
- assert_equal 1, e.count
- end
-
- def test_invalid_pluralization_data_message
- force_invalid_pluralization_data
- rescue I18n::ArgumentError => e
- assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
- end
-
- def test_missing_interpolation_argument_stores_key_and_string
- force_missing_interpolation_argument
- rescue I18n::ArgumentError => e
- assert_equal 'bar', e.key
- assert_equal "{{bar}}", e.string
- end
-
- def test_missing_interpolation_argument_message
- force_missing_interpolation_argument
- rescue I18n::ArgumentError => e
- assert_equal 'interpolation argument bar missing in "{{bar}}"', e.message
- end
-
- def test_reserved_interpolation_key_stores_key_and_string
- force_reserved_interpolation_key
- rescue I18n::ArgumentError => e
- assert_equal 'scope', e.key
- assert_equal "{{scope}}", e.string
- end
-
- def test_reserved_interpolation_key_message
- force_reserved_interpolation_key
- rescue I18n::ArgumentError => e
- assert_equal 'reserved key "scope" used in "{{scope}}"', e.message
- end
-
- private
- def force_invalid_locale
- I18n.backend.translate nil, :foo
- end
-
- def force_missing_translation_data
- I18n.store_translations 'de-DE', :bar => nil
- I18n.backend.translate 'de-DE', :foo, :scope => :bar
- end
-
- def force_invalid_pluralization_data
- I18n.store_translations 'de-DE', :foo => [:bar]
- I18n.backend.translate 'de-DE', :foo, :count => 1
- end
-
- def force_missing_interpolation_argument
- I18n.store_translations 'de-DE', :foo => "{{bar}}"
- I18n.backend.translate 'de-DE', :foo, :baz => 'baz'
- end
-
- def force_reserved_interpolation_key
- I18n.store_translations 'de-DE', :foo => "{{scope}}"
- I18n.backend.translate 'de-DE', :foo, :baz => 'baz'
- end
-end \ No newline at end of file
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_test.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_test.rb
deleted file mode 100644
index bbb1316b49..0000000000
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/i18n_test.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-$:.unshift "lib"
-
-require 'rubygems'
-require 'test/unit'
-require 'mocha'
-require 'i18n'
-require 'active_support'
-
-class I18nTest < Test::Unit::TestCase
- def setup
- I18n.store_translations :'en-US', {
- :currency => {
- :format => {
- :separator => '.',
- :delimiter => ',',
- }
- }
- }
- end
-
- def test_uses_simple_backend_set_by_default
- assert_equal I18n::Backend::Simple, I18n.backend
- end
-
- def test_can_set_backend
- assert_nothing_raised{ I18n.backend = self }
- assert_equal self, I18n.backend
- I18n.backend = I18n::Backend::Simple
- end
-
- def test_uses_en_us_as_default_locale_by_default
- assert_equal 'en-US', I18n.default_locale
- end
-
- def test_can_set_default_locale
- assert_nothing_raised{ I18n.default_locale = 'de-DE' }
- assert_equal 'de-DE', I18n.default_locale
- I18n.default_locale = 'en-US'
- end
-
- def test_uses_default_locale_as_locale_by_default
- assert_equal I18n.default_locale, I18n.locale
- end
-
- def test_can_set_locale_to_thread_current
- assert_nothing_raised{ I18n.locale = 'de-DE' }
- assert_equal 'de-DE', I18n.locale
- assert_equal 'de-DE', Thread.current[:locale]
- I18n.locale = 'en-US'
- end
-
- def test_can_set_exception_handler
- assert_nothing_raised{ I18n.exception_handler = :custom_exception_handler }
- I18n.exception_handler = :default_exception_handler # revert it
- end
-
- def test_uses_custom_exception_handler
- I18n.exception_handler = :custom_exception_handler
- I18n.expects(:custom_exception_handler)
- I18n.translate :bogus
- I18n.exception_handler = :default_exception_handler # revert it
- end
-
- def test_delegates_translate_to_backend
- I18n.backend.expects(:translate).with 'de-DE', :foo, {}
- I18n.translate :foo, :locale => 'de-DE'
- end
-
- def test_delegates_localize_to_backend
- I18n.backend.expects(:localize).with 'de-DE', :whatever, :default
- I18n.localize :whatever, :locale => 'de-DE'
- end
-
- def test_delegates_store_translations_to_backend
- I18n.backend.expects(:store_translations).with 'de-DE', {:foo => :bar}
- I18n.store_translations 'de-DE', {:foo => :bar}
- end
-
- def test_delegates_populate_to_backend
- I18n.backend.expects(:populate) # can't specify a block here as an expected argument
- I18n.populate{ }
- end
-
- def test_populate_yields_the_block
- tmp = nil
- I18n.populate do tmp = 'yielded' end
- assert_equal 'yielded', tmp
- end
-
- def test_translate_given_no_locale_uses_i18n_locale
- I18n.backend.expects(:translate).with 'en-US', :foo, {}
- I18n.translate :foo
- end
-
- def test_translate_on_nested_symbol_keys_works
- assert_equal ".", I18n.t(:'currency.format.separator')
- end
-
- def test_translate_with_nested_string_keys_works
- assert_equal ".", I18n.t('currency.format.separator')
- end
-
- def test_translate_with_array_as_scope_works
- assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
- end
-
- def test_translate_with_array_containing_dot_separated_strings_as_scope_works
- assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
- end
-
- def test_translate_with_key_array_and_dot_separated_scope_works
- assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
- end
-
- def test_translate_with_dot_separated_key_array_and_scope_works
- assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
- end
-
- def test_translate_with_options_using_scope_works
- I18n.backend.expects(:translate).with('de-DE', :precision, :scope => :"currency.format")
- I18n.with_options :locale => 'de-DE', :scope => :'currency.format' do |locale|
- locale.t :precision
- end
- end
-
- # def test_translate_given_no_args_raises_missing_translation_data
- # assert_equal "translation missing: en-US, no key", I18n.t
- # end
-
- def test_translate_given_a_bogus_key_raises_missing_translation_data
- assert_equal "translation missing: en-US, bogus", I18n.t(:bogus)
- end
-
- def test_localize_nil_raises_argument_error
- assert_raises(I18n::ArgumentError) { I18n.l nil }
- end
-
- def test_localize_object_raises_argument_error
- assert_raises(I18n::ArgumentError) { I18n.l Object.new }
- end
-end
diff --git a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/simple_backend_test.rb b/activesupport/lib/active_support/vendor/i18n-0.0.1/test/simple_backend_test.rb
deleted file mode 100644
index c94d742e2d..0000000000
--- a/activesupport/lib/active_support/vendor/i18n-0.0.1/test/simple_backend_test.rb
+++ /dev/null
@@ -1,376 +0,0 @@
-$:.unshift "lib"
-
-require 'rubygems'
-require 'test/unit'
-require 'mocha'
-require 'i18n'
-
-module I18nSimpleBackendTestSetup
- def setup_backend
- @backend = I18n::Backend::Simple
- @backend.send :class_variable_set, :@@translations, {}
- @backend.store_translations 'en-US', :foo => {:bar => 'bar', :baz => 'baz'}
- end
- alias :setup :setup_backend
-
- def add_datetime_translations
- @backend.store_translations :'de-DE', {
- :date => {
- :formats => {
- :default => "%d.%m.%Y",
- :short => "%d. %b",
- :long => "%d. %B %Y",
- },
- :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
- :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
- :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
- :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
- :order => [:day, :month, :year]
- },
- :time => {
- :formats => {
- :default => "%a, %d. %b %Y %H:%M:%S %z",
- :short => "%d. %b %H:%M",
- :long => "%d. %B %Y %H:%M",
- },
- :am => 'am',
- :pm => 'pm'
- },
- :datetime => {
- :distance_in_words => {
- :half_a_minute => 'half a minute',
- :less_than_x_seconds => ['less than 1 second', 'less than {{count}} seconds'],
- :x_seconds => ['1 second', '{{count}} seconds'],
- :less_than_x_minutes => ['less than a minute', 'less than {{count}} minutes'],
- :x_minutes => ['1 minute', '{{count}} minutes'],
- :about_x_hours => ['about 1 hour', 'about {{count}} hours'],
- :x_days => ['1 day', '{{count}} days'],
- :about_x_months => ['about 1 month', 'about {{count}} months'],
- :x_months => ['1 month', '{{count}} months'],
- :about_x_years => ['about 1 year', 'about {{count}} year'],
- :over_x_years => ['over 1 year', 'over {{count}} years']
- }
- }
- }
- end
-end
-
-class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_store_translations_adds_translations # no, really :-)
- @backend.store_translations :'en-US', :foo => 'bar'
- assert_equal Hash[:'en-US', {:foo => 'bar'}], @backend.send(:class_variable_get, :@@translations)
- end
-
- def test_store_translations_deep_merges_translations
- @backend.store_translations :'en-US', :foo => {:bar => 'bar'}
- @backend.store_translations :'en-US', :foo => {:baz => 'baz'}
- assert_equal Hash[:'en-US', {:foo => {:bar => 'bar', :baz => 'baz'}}], @backend.send(:class_variable_get, :@@translations)
- end
-
- def test_store_translations_forces_locale_to_sym
- @backend.store_translations 'en-US', :foo => 'bar'
- assert_equal Hash[:'en-US', {:foo => 'bar'}], @backend.send(:class_variable_get, :@@translations)
- end
-
- def test_store_translations_covert_key_symbols
- @backend.send :class_variable_set, :@@translations, {} # reset translations
- @backend.store_translations :'en-US', 'foo' => {'bar' => 'baz'}
- assert_equal Hash[:'en-US', {:foo => {:bar => 'baz'}}],
- @backend.send(:class_variable_get, :@@translations)
- end
-end
-
-class I18nSimpleBackendTranslateTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_translate_calls_lookup_with_locale_given
- @backend.expects(:lookup).with('de-DE', :bar, [:foo]).returns 'bar'
- @backend.translate 'de-DE', :bar, :scope => [:foo]
- end
-
- def test_translate_given_a_symbol_as_a_default_translates_the_symbol
- assert_equal 'bar', @backend.translate('en-US', nil, :scope => [:foo], :default => :bar)
- end
-
- def test_translate_given_an_array_as_default_uses_the_first_match
- assert_equal 'bar', @backend.translate('en-US', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
- end
-
- def test_translate_an_array_of_keys_translates_all_of_them
- assert_equal %w(bar baz), @backend.translate('en-US', [:bar, :baz], :scope => [:foo])
- end
-
- def test_translate_calls_pluralize
- @backend.expects(:pluralize).with 'bar', 1
- @backend.translate 'en-US', :bar, :scope => [:foo], :count => 1
- end
-
- def test_translate_calls_interpolate
- @backend.expects(:interpolate).with 'bar', {}
- @backend.translate 'en-US', :bar, :scope => [:foo]
- end
-
- def test_translate_calls_interpolate_including_count_as_a_value
- @backend.expects(:interpolate).with 'bar', {:count => 1}
- @backend.translate 'en-US', :bar, :scope => [:foo], :count => 1
- end
-
- def test_given_no_keys_it_returns_the_default
- assert_equal 'default', @backend.translate('en-US', nil, :default => 'default')
- end
-
- def test_translate_given_nil_as_a_locale_raises_an_argument_error
- assert_raises(I18n::InvalidLocale){ @backend.translate nil, :bar }
- end
-
- def test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_data
- assert_raises(I18n::MissingTranslationData){ @backend.translate 'de-DE', :bogus }
- end
-end
-
-class I18nSimpleBackendLookupTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- # useful because this way we can use the backend with no key for interpolation/pluralization
- def test_lookup_given_nil_as_a_key_returns_nil
- assert_nil @backend.send(:lookup, 'en-US', nil)
- end
-
- def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
- assert_equal 'bar', @backend.send(:lookup, 'en-US', :bar, [:foo])
- end
-end
-
-class I18nSimpleBackendPluralizeTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_pluralize_given_nil_returns_the_given_entry
- assert_equal ['bar', 'bars'], @backend.send(:pluralize, ['bar', 'bars'], nil)
- end
-
- def test_pluralize_given_0_returns_plural_string
- assert_equal 'bars', @backend.send(:pluralize, ['bar', 'bars'], 0)
- end
-
- def test_pluralize_given_1_returns_singular_string
- assert_equal 'bar', @backend.send(:pluralize, ['bar', 'bars'], 1)
- end
-
- def test_pluralize_given_2_returns_plural_string
- assert_equal 'bars', @backend.send(:pluralize, ['bar', 'bars'], 2)
- end
-
- def test_pluralize_given_3_returns_plural_string
- assert_equal 'bars', @backend.send(:pluralize, ['bar', 'bars'], 3)
- end
-
- def test_interpolate_given_invalid_pluralization_data_raises_invalid_pluralization_data
- assert_raises(I18n::InvalidPluralizationData){ @backend.send(:pluralize, ['bar'], 2) }
- end
-end
-
-class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def test_interpolate_given_a_value_hash_interpolates_the_values_to_the_string
- assert_equal 'Hi David!', @backend.send(:interpolate, 'Hi {{name}}!', :name => 'David')
- end
-
- def test_interpolate_given_nil_as_a_string_returns_nil
- assert_nil @backend.send(:interpolate, nil, :name => 'David')
- end
-
- def test_interpolate_given_an_non_string_as_a_string_returns_nil
- assert_equal [], @backend.send(:interpolate, [], :name => 'David')
- end
-
- def test_interpolate_given_a_values_hash_with_nil_values_interpolates_the_string
- assert_equal 'Hi !', @backend.send(:interpolate, 'Hi {{name}}!', {:name => nil})
- end
-
- def test_interpolate_given_an_empty_values_hash_raises_missing_interpolation_argument
- assert_raises(I18n::MissingInterpolationArgument) { @backend.send(:interpolate, 'Hi {{name}}!', {}) }
- end
-
- def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
- assert_raises(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, '{{default}}', {:default => nil}) }
- end
-end
-
-class I18nSimpleBackendLocalizeDateTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def setup
- @backend = I18n::Backend::Simple
- add_datetime_translations
- @date = Date.new 2008, 1, 1
- end
-
- def test_translate_given_the_short_format_it_uses_it
- assert_equal '01. Jan', @backend.localize('de-DE', @date, :short)
- end
-
- def test_translate_given_the_long_format_it_uses_it
- assert_equal '01. Januar 2008', @backend.localize('de-DE', @date, :long)
- end
-
- def test_translate_given_the_default_format_it_uses_it
- assert_equal '01.01.2008', @backend.localize('de-DE', @date, :default)
- end
-
- def test_translate_given_a_day_name_format_it_returns_a_day_name
- assert_equal 'Dienstag', @backend.localize('de-DE', @date, '%A')
- end
-
- def test_translate_given_an_abbr_day_name_format_it_returns_an_abbrevated_day_name
- assert_equal 'Di', @backend.localize('de-DE', @date, '%a')
- end
-
- def test_translate_given_a_month_name_format_it_returns_a_month_name
- assert_equal 'Januar', @backend.localize('de-DE', @date, '%B')
- end
-
- def test_translate_given_an_abbr_month_name_format_it_returns_an_abbrevated_month_name
- assert_equal 'Jan', @backend.localize('de-DE', @date, '%b')
- end
-
- def test_translate_given_no_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de-DE', @date }
- end
-
- def test_translate_given_an_unknown_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de-DE', @date, '%x' }
- end
-
- def test_localize_nil_raises_argument_error
- assert_raises(I18n::ArgumentError) { @backend.localize 'de-DE', nil }
- end
-
- def test_localize_object_raises_argument_error
- assert_raises(I18n::ArgumentError) { @backend.localize 'de-DE', Object.new }
- end
-end
-
-class I18nSimpleBackendLocalizeDateTimeTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def setup
- @backend = I18n::Backend::Simple
- add_datetime_translations
- @morning = DateTime.new 2008, 1, 1, 6
- @evening = DateTime.new 2008, 1, 1, 18
- end
-
- def test_translate_given_the_short_format_it_uses_it
- assert_equal '01. Jan 06:00', @backend.localize('de-DE', @morning, :short)
- end
-
- def test_translate_given_the_long_format_it_uses_it
- assert_equal '01. Januar 2008 06:00', @backend.localize('de-DE', @morning, :long)
- end
-
- def test_translate_given_the_default_format_it_uses_it
- assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de-DE', @morning, :default)
- end
-
- def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
- assert_equal 'Dienstag', @backend.localize('de-DE', @morning, '%A')
- end
-
- def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
- assert_equal 'Di', @backend.localize('de-DE', @morning, '%a')
- end
-
- def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
- assert_equal 'Januar', @backend.localize('de-DE', @morning, '%B')
- end
-
- def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
- assert_equal 'Jan', @backend.localize('de-DE', @morning, '%b')
- end
-
- def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
- assert_equal 'am', @backend.localize('de-DE', @morning, '%p')
- assert_equal 'pm', @backend.localize('de-DE', @evening, '%p')
- end
-
- def test_translate_given_no_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de-DE', @morning }
- end
-
- def test_translate_given_an_unknown_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de-DE', @morning, '%x' }
- end
-end
-
-class I18nSimpleBackendLocalizeTimeTest < Test::Unit::TestCase
- include I18nSimpleBackendTestSetup
-
- def setup
- @old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
- @backend = I18n::Backend::Simple
- add_datetime_translations
- @morning = Time.parse '2008-01-01 6:00 UTC'
- @evening = Time.parse '2008-01-01 18:00 UTC'
- end
-
- def teardown
- ENV['TZ'] = @old_timezone
- end
-
- def test_translate_given_the_short_format_it_uses_it
- assert_equal '01. Jan 06:00', @backend.localize('de-DE', @morning, :short)
- end
-
- def test_translate_given_the_long_format_it_uses_it
- assert_equal '01. Januar 2008 06:00', @backend.localize('de-DE', @morning, :long)
- end
-
- # TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
- # def test_translate_given_the_default_format_it_uses_it
- # assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de-DE', @morning, :default)
- # end
-
- def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
- assert_equal 'Dienstag', @backend.localize('de-DE', @morning, '%A')
- end
-
- def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
- assert_equal 'Di', @backend.localize('de-DE', @morning, '%a')
- end
-
- def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
- assert_equal 'Januar', @backend.localize('de-DE', @morning, '%B')
- end
-
- def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
- assert_equal 'Jan', @backend.localize('de-DE', @morning, '%b')
- end
-
- def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
- assert_equal 'am', @backend.localize('de-DE', @morning, '%p')
- assert_equal 'pm', @backend.localize('de-DE', @evening, '%p')
- end
-
- def test_translate_given_no_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de-DE', @morning }
- end
-
- def test_translate_given_an_unknown_format_it_does_not_fail
- assert_nothing_raised{ @backend.localize 'de-DE', @morning, '%x' }
- end
-end
-
-class I18nSimpleBackendHelperMethodsTest < Test::Unit::TestCase
- def setup
- @backend = I18n::Backend::Simple
- end
-
- def test_deep_symbolize_keys_works
- result = @backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
- expected = {:foo => {:bar => {:baz => 'bar'}}}
- assert_equal expected, result
- end
-end