Fix [54a5088cd5] where the i18n gem was wrongly updated to 0.4.1.

I've tested and confirm that `2-3-stable` will use the vendored `i18n` gem if there's no `i18n` gem with version >= 0.4.1 installed

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Prem Sichanugrist
2010-06-29 19:33:48 +07:00
committed by José Valim
parent 80473e035a
commit 69c4e4ce65
99 changed files with 0 additions and 4326 deletions

View File

@@ -1,135 +0,0 @@
h1. Changelog
h2. master
h2. 0.4.0 (2010-05-27)
* "The localization proc also receives the object as option":http://github.com/svenfuchs/i18n/commit/4a8cd9fa660daaa3078e24c5851353ca377d9213
h2. 0.4.0.beta1 (2010-05-03)
* "Renamed Fast backend to Memoize backend":http://github.com/svenfuchs/i18n/commit/f7f7dc12c00a19d3876223771e14f8671ff313cd
* "Deprecate {{}} as interpolation syntax":http://github.com/svenfuchs/i18n/commit/8894ee521ef5788c415b625a6daf522af4c416e0
* "Allow nil translation to be stored again":http://github.com/svenfuchs/i18n/commit/f2074f1e82d10c2e9a801c8cc2f2a0c7c30703ba
h2. 0.4.0.beta (2010-04-30)
* "Added a KeyValue backend":http://github.com/svenfuchs/i18n/commit/28ca5f53ade7f545f8c0804e93564d4686b416a4
* "Added transliteration support":http://github.com/svenfuchs/i18n/commit/928fdb4794959e779e90f360eb01ba043672d8d5
* "Create Flatten backend module to aid handling flatten translations":http://github.com/svenfuchs/i18n/commit/2ec9d6998aa8facd7b15a3ef47a96cf2471cd8a1
* "Decouple the external separator (used when storing translations) from the internal separator in Fast and ActiveRecord backends":http://github.com/svenfuchs/i18n/commit/274cb4daa0ca5e3b2bd23b45eb7f9fc58f75a79d
h2. 0.3.7 (2010-04-17)
* "Speed up I18n.normalize_keys by caching reused normalizations and producing less garbage":http://github.com/svenfuchs/i18n/commit/819dac0fea9c29e6545801aa107e63e355728cd4
h2. 0.3.6 (2010-03-23)
* "Move gettext po parser to lib":http://github.com/svenfuchs/i18n/commit/b2f038663b55727ac2327e6f07a46ba5d69d600c
* "Move I18n configuration to I18n.config":http://github.com/svenfuchs/i18n/commit/4a7baea86663ead8c681008c3e80a622f0546b07
h2. 0.3.5 (2010-02-26)
* "Delegate I18n.normalize_translation_keys to I18n.normalize_keys and deprecate
the former":http://github.com/svenfuchs/i18n/commit/7284b04d5f5dd9679cb68875515cdd0cdfc96fef
h2. 0.3.4 (2010-02-25)
* "Rename I18n.normalize_translation_keys to I18n.normalize_keys and finally make it public":http://github.com/svenfuchs/i18n/commit/20b05fe5802df6c90fb70a4e3760b2b851b791b3
* "Added CLDR supoprt":http://github.com/svenfuchs/i18n/commit/860eadf671a231e7f5dffb1bb27fa318ff7a8786
h2. 0.3.3 (2009-12-29)
* "Use lib/i18n/version":http://github.com/svenfuchs/i18n/commit/ff426c8e7a2438b814cb303adadec292dacb752e
* "Added a benchmark suite":http://github.com/svenfuchs/i18n/commit/f9b5b9b113097724638bdab96862ffa404e67e70
* "Ensure links can be handled recursively":http://github.com/svenfuchs/i18n/commit/2c50bd209f3fc24fe9dfa694c81be64340f09b7d
* "Make sure we can lookup false values as translation data":http://github.com/svenfuchs/i18n/commit/561c82ba4b8921d03bfdf56cb2d0c2f287629001
* "Added Fast backend module":http://github.com/svenfuchs/i18n/commit/bd2f09f0a251ca793b0e8ecc7e32177a2f091c23
* "Added InterpolationCompiler backend module":http://github.com/svenfuchs/i18n/commit/91810887d1abfb28996a9183bc9004678290d28b
h2. 0.3.2 (2009-12-12)
* "Added Cascade backend":http://github.com/svenfuchs/i18n/commit/8009aef293e9ef8564c9005090d8380feabcaf6f
h2. 0.3.1 (2009-12-11)
* "Add PoParser to gemspec":http://github.com/svenfuchs/i18n/commit/d6b2763f39c932f66adb039b96882a472f883c51
* "Enable custom separators for ActiveRecord backend":http://github.com/svenfuchs/i18n/commit/9341d3fcfc951cc31807ba672d2b5d90909ef3e5
* "Pass interpolation values to interpolation procs":http://github.com/svenfuchs/i18n/commit/39c2ed8fbad645671cd5520ce7ad0aeefe2b0cca
* "Fix that ngettext supports keys with dots":http://github.com/svenfuchs/i18n/commit/7362a43c34364d500de8899cfcca6bf1a5e6d1c8
h2. 0.3.0 (2009-11-30)
* "Gettext backend and helpers":http://github.com/svenfuchs/i18n/commit/35a1740d2f10b808548af352006950da4017e374
* "Metadata module":http://github.com/svenfuchs/i18n/commit/2677208555179b36fcbe958c0e8bc642cf5bc020
* "Basic ActiveRecord backend":http://github.com/svenfuchs/i18n/commit/786632d0b42de423ecf0969622efc87f1691e2a2
* "Set encoding to UTF8 for all files":http://github.com/svenfuchs/i18n/commit/9be3d4a311b5bf583eec5d39986176cc40c112f2
* "Chain backend":http://github.com/svenfuchs/i18n/commit/08259ffb88b3005403648d77bc1cbca0b92f3cf5
* "Backend/cache implementation":http://github.com/svenfuchs/i18n/commit/e7bf15351cd2e27f5972eb40e65a5dd6f4a0feed
* "Pluralization module":http://github.com/svenfuchs/i18n/commit/9ca4c9ed52d4706566a6abeb2d78722dcc5d4764
* "add and adapt Globalize2 fallback implementation":http://github.com/svenfuchs/i18n/commit/1b37a303b27d6222b17162804b06323e5628768f
* "move Simple backend implementation to a Base backend class and extend Simple from Base.":http://github.com/svenfuchs/i18n/commit/32ddc80a04e6aa247f6d6613bde7f78c73396cb4
h2. 0.2.0 (2009-07-12)
* "Allow using Ruby 1.9 syntax for string interpolation (API addition)":http://github.com/svenfuchs/i18n/commit/c6e0b06d512f2af57199a843a1d8a40241b32861
* "Allow configuring the default scope separator, allow to pass a custom scope separator(API addition)":http://github.com/svenfuchs/i18n/commit/5b75bfbc348061adc11e3790187a187275bfd471 (e.g. I18n.t(:'foo|bar', :separator => '|')
* "Pass :format option to #translate for #localize more useful lambda support":http://github.com/svenfuchs/i18n/commit/e277711b3c844fe7589b8d3f9af0f7d1b969a273
* "Refactor Simple backend #resolve to #default and #resolve for more consistency. Now allows to pass lambdas as defaults and re-resolve Symbols":http://github.com/svenfuchs/i18n/commit/8c4ce3d923ce5fa73e973fe28217e18165549aba
* "Add lambda support to #translate (API addition)":http://github.com/svenfuchs/i18n/commit/c90e62d8f7d3d5b78f34cfe328d871b58884f115
* "Add lambda support to #localize (API addition)":http://github.com/svenfuchs/i18n/commit/9d390afcf33f3f469bb95e6888147152f6cc7442
h2. 0.1.3 (2009-02-27)
* "Remove unnecessary string encoding handling in the i18n simple backend which made the backend break on Ruby 1.9":http://github.com/svenfuchs/i18n/commit/4c3a970783861a94f2e89f46714fb3434e4f4f8d
h2. 0.1.2 (2009-01-09)
* "added #available_locales (returns an array of locales for which translations are available)":http://github.com/svenfuchs/i18n/commit/411f8fe7c8f3f89e9b6b921fa62ed66cb92f3af4
* "flatten load_path before using it so that a nested array of paths won't throw up":http://github.com/svenfuchs/i18n/commit/d473a068a2b90aba98135deb225d6eb6d8104d70
h2. 0.1.1 (2008-11-20)
* "Use :'en' as a default locale (in favor of :'en-US')":http://github.com/svenfuchs/i18n/commit/c4b10b246aecf7da78cb2568dd0d2ab7e6b8a230
* "Add #reload! to Simple backend":http://github.com/svenfuchs/i18n/commit/36dd2bd9973b9e1559728749a9daafa44693e964
h2. 0.1.0 (2008-10-25)
* "Fix Simple backend to distinguish false from nil values":http://github.com/svenfuchs/i18n/commit/39d9a47da14b5f3ba126af48923af8c30e135166
* "Add #load_path to public api, add initialize to simple backend and remove #load_translations from public api":http://github.com/svenfuchs/i18n/commit/c4c5649e6bc8f020f1aaf5a5470bde048e22c82d
* "Speed up Backend::Simple#interpolate":http://github.com/svenfuchs/i18n/commit/9e1ac6bf8833304e036323ec9932b9f33c468a35
* "Remove #populate and #store_translations from public API":http://github.com/svenfuchs/i18n/commit/f4e514a80be7feb509f66824ee311905e2940900
* "Use :other instead of :many as a plural key":http://github.com/svenfuchs/i18n/commit/0f8f20a2552bf6a2aa758d8fdd62a7154e4a1bf6
* "Use a class instead of a module for Simple backend":http://github.com/svenfuchs/i18n/commit/08f051aa61320c17debde24a83268bc74e33b995
* "Make Simple backend #interpolate deal with non-ASCII string encodings":http://github.com/svenfuchs/i18n/commit/d84a3f3f55543c084d5dc5d1fed613b8df148789
* "Fix default arrays of non-existant keys returning the default array":http://github.com/svenfuchs/i18n/commit/6c04ca86c87f97dc78f07c2a4023644e5ba8b839
h2. Initial implementation (June/July 2008)
Initial implementation by "Sven Fuchs":http://www.workingwithrails.com/person/9963-sven-fuchs based on previous discussion/consensus of the rails-i18n team (alphabetical order) and many others:
* "Matt Aimonetti":http://railsontherun.com
* "Sven Fuchs":http://www.workingwithrails.com/person/9963-sven-fuchs
* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
* "Saimon Moore":http://saimonmoore.net
* "Stephan Soller":http://www.arkanis-development.de
h2. More information
* "Homepage":http://rails-i18n.org
* "Wiki":http://rails-i18n.org/wiki
* "Mailinglist":http://groups.google.com/group/rails-i18n
* "About the project/history":http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized
* "Initial API Intro":http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api

View File

@@ -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.

View File

@@ -1,93 +0,0 @@
h1. Ruby I18n
Ruby Internationalization and localization solution.
Features:
* translation and localization
* interpolation of values to translations (Ruby 1.9 compatible syntax)
* pluralization (CLDR compatible)
* customizable transliteration to ASCII
* flexible defaults
* bulk lookup
* lambdas as translation data
* custom key/scope separator
* custom exception handlers
* extensible architecture with a swappable backend
Pluggable features:
* Cache
* Pluralization: lambda pluralizers stored as translation data
* Locale fallbacks, RFC4647 compliant (optionally: RFC4646 locale validation)
* Gettext support
* Translation metadata
Alternative backends:
* Chain
* ActiveRecord (optionally: ActiveRecord::Missing and ActiveRecord::StoreProcs)
* KeyValue (uses active_support/json and cannot store procs)
For more information and lots of resources see: "http://rails-i18n.org/wiki":http://rails-i18n.org/wiki
h2. Installation
gem install i18n
h3. Installation on Rails < 2.3.5 (deprecated)
Up to version 2.3.4 Rails will not accept i18n gems > 0.1.3. There is an unpacked
gem inside of active_support/lib/vendor which gets loaded unless gem 'i18n', '~> 0.1.3'.
This requirement is relaxed in "6da03653":http://github.com/rails/rails/commit/6da03653
The new i18n gem can be loaded from vendor/plugins like this:
def reload_i18n!
raise "Move to i18n version 0.2.0 or greater" if Rails.version > "2.3.4"
$:.grep(/i18n/).each { |path| $:.delete(path) }
I18n::Backend.send :remove_const, "Simple"
$: << Rails.root.join('vendor', 'plugins', 'i18n', 'lib').to_s
end
Then you can `reload_i18n!` inside an i18n initializer.
h2. Tests
You can run tests both with
* `rake test` or just `rake`
* run any test file directly, e.g. `ruby test/api/simple_test.rb`
* run all tests with `ruby test/all.rb`
The structure of the test suite is a bit unusual as it uses modules to reuse
particular tests in different test cases.
The reason for this is that we need to enforce the I18n API across various
combinations of extensions. E.g. the Simple backend alone needs to support
the same API as any combination of feature and/or optimization modules included
to the Simple backend. We test this by reusing the same API defition (implemented
as test methods) in test cases with different setups.
You can find the test cases that enforce the API in test/api. And you can find
the API definition test methods in test/api/tests.
All other test cases (e.g. as defined in test/backend, test/core\_ext) etc.
follow the usual test setup and should be easy to grok.
h2. Authors
* "Sven Fuchs":http://www.artweb-design.de
* "Joshua Harvey":http://www.workingwithrails.com/person/759-joshua-harvey
* "Stephan Soller":http://www.arkanis-development.de
* "Saimon Moore":http://saimonmoore.net
* "Matt Aimonetti":http://railsontherun.com
h2. Contributors
http://github.com/svenfuchs/i18n/contributors
h2. License
MIT License. See the included MIT-LICENSE file.

View File

@@ -1,24 +0,0 @@
require 'rake/testtask'
require "rake/gempackagetask"
require "rake/clean"
task :default => [:test]
CLEAN << "pkg" << "doc" << "coverage" << ".yardoc"
Rake::TestTask.new(:test) do |t|
t.pattern = "#{File.dirname(__FILE__)}/test/all.rb"
t.verbose = true
end
Rake::Task['test'].comment = "Run all i18n tests"
Rake::GemPackageTask.new(eval(File.read("i18n.gemspec"))) { |pkg| }
begin
require "yard"
YARD::Rake::YardocTask.new do |t|
t.options = ["--output-dir=doc"]
t.options << "--files" << ["CHANGELOG.textile", "contributors.txt", "MIT-LICENSE"].join(",")
end
rescue LoadError
end

View File

@@ -1,148 +0,0 @@
en:
first: "First"
activemodel:
errors:
messages: :"activerecord.errors.messages"
activerecord:
errors:
messages:
inclusion: "is not included in the list"
exclusion: "is reserved"
invalid: "is invalid"
confirmation: "doesn't match confirmation"
accepted: "must be accepted"
empty: "can't be empty"
blank: "can't be blank"
too_long: "is too long (maximum is %{count} characters)"
too_short: "is too short (minimum is %{count} characters)"
wrong_length: "is the wrong length (should be %{count} characters)"
taken: "has already been taken"
not_a_number: "is not a number"
greater_than: "must be greater than %{count}"
greater_than_or_equal_to: "must be greater than or equal to %{count}"
equal_to: "must be equal to %{count}"
less_than: "must be less than %{count}"
less_than_or_equal_to: "must be less than or equal to %{count}"
odd: "must be odd"
even: "must be even"
record_invalid: "Validation failed: %{errors}"
models:
user:
blank: "This is a custom blank message for %{model}: %{attribute}"
attributes:
login:
blank: "This is a custom blank message for User login"
models:
user: "Dude"
attributes:
admins:
user:
login: "Handle"
date:
formats:
# Use the strftime parameters for formats.
# When no format has been given, it uses default.
# You can provide other formats here if you like!
default: "%Y-%m-%d"
short: "%b %d"
long: "%B %d, %Y"
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
# Don't forget the nil at the beginning; there's no such thing as a 0th month
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
# Used in date_select and datime_select.
order: [ :year, :month, :day ]
time:
formats:
default: "%a, %d %b %Y %H:%M:%S %z"
short: "%d %b %H:%M"
long: "%B %d, %Y %H:%M"
am: "am"
pm: "pm"
support:
array:
words_connector: ", "
two_words_connector: " and "
last_word_connector: ", and "
activemodel:
errors:
messages:
inclusion: "is not included in the list"
exclusion: "is reserved"
invalid: "is invalid"
confirmation: "doesn't match confirmation"
accepted: "must be accepted"
empty: "can't be empty"
blank: "can't be blank"
too_long: "is too long (maximum is %{count} characters)"
too_short: "is too short (minimum is %{count} characters)"
wrong_length: "is the wrong length (should be %{count} characters)"
taken: "has already been taken"
not_a_number: "is not a number"
greater_than: "must be greater than %{count}"
greater_than_or_equal_to: "must be greater than or equal to %{count}"
equal_to: "must be equal to %{count}"
less_than: "must be less than %{count}"
less_than_or_equal_to: "must be less than or equal to %{count}"
odd: "must be odd"
even: "must be even"
record_invalid: "Validation failed: %{errors}"
models:
user:
blank: "This is a custom blank message for %{model}: %{attribute}"
attributes:
login:
blank: "This is a custom blank message for User login"
models:
user: "Dude"
attributes:
user:
login: "Handle"
model_data:
date:
formats:
# Use the strftime parameters for formats.
# When no format has been given, it uses default.
# You can provide other formats here if you like!
default: "%Y-%m-%d"
short: "%b %d"
long: "%B %d, %Y"
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
# Don't forget the nil at the beginning; there's no such thing as a 0th month
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
# Used in date_select and datime_select.
order: [ :year, :month, :day ]
time:
formats:
default: "%a, %d %b %Y %H:%M:%S %z"
short: "%d %b %H:%M"
long: "%B %d, %Y %H:%M"
am: "am"
pm: "pm"
support:
array:
words_connector: ", "
two_words_connector: " and "
last_word_connector: ", and "

View File

@@ -1,116 +0,0 @@
#! /usr/bin/ruby
$:.unshift File.expand_path('../../lib', __FILE__)
require 'i18n'
require 'benchmark'
require 'yaml'
DATA_STORES = ARGV.delete("-ds")
N = (ARGV.shift || 1000).to_i
YAML_HASH = YAML.load_file(File.expand_path("example.yml", File.dirname(__FILE__)))
module Backends
Simple = I18n::Backend::Simple.new
Interpolation = Class.new(I18n::Backend::Simple) do
include I18n::Backend::InterpolationCompiler
end.new
if DATA_STORES
require 'rubygems'
require File.expand_path('../../test/test_setup_requirements', __FILE__)
setup_active_record
ActiveRecord = I18n::Backend::ActiveRecord.new if defined?(::ActiveRecord)
setup_rufus_tokyo
TokyoCabinet = I18n::Backend::KeyValue.new(Rufus::Tokyo::Cabinet.new("*"), true) if defined?(::Rufus::Tokyo)
end
end
ORDER = %w(Simple Interpolation ActiveRecord TokyoCabinet)
ORDER.map!(&:to_sym) if RUBY_VERSION > '1.9'
module Benchmark
WIDTH = 20
def self.rt(label = "", n=N, &blk)
print label.ljust(WIDTH)
time, objects = measure_objects(n, &blk)
time = time.respond_to?(:real) ? time.real : time
print format("%8.2f ms %8d objects\n", time * 1000, objects)
rescue Exception => e
print "FAILED: #{e.message}"
end
if ObjectSpace.respond_to?(:allocated_objects)
def self.measure_objects(n, &blk)
obj = ObjectSpace.allocated_objects
t = Benchmark.realtime { n.times(&blk) }
[t, ObjectSpace.allocated_objects - obj]
end
else
def self.measure_objects(n, &blk)
[Benchmark.measure { n.times(&blk) }, 0]
end
end
end
benchmarker = lambda do |backend_name|
I18n.backend = Backends.const_get(backend_name)
puts "=> #{backend_name}\n\n"
Benchmark.rt "store", 1 do
I18n.backend.store_translations *(YAML_HASH.to_a.first)
end
I18n.backend.translate :en, :first
Benchmark.rt "available_locales" do
I18n.backend.available_locales
end
Benchmark.rt "t (depth=3)" do
I18n.backend.translate :en, :"activerecord.models.user"
end
Benchmark.rt "t (depth=5)" do
I18n.backend.translate :en, :"activerecord.attributes.admins.user.login"
end
Benchmark.rt "t (depth=7)" do
I18n.backend.translate :en, :"activerecord.errors.models.user.attributes.login.blank"
end
Benchmark.rt "t w/ default" do
I18n.backend.translate :en, :"activerecord.models.another", :default => "Another"
end
Benchmark.rt "t w/ interpolation" do
I18n.backend.translate :en, :"activerecord.errors.models.user.blank", :model => "User", :attribute => "name"
end
Benchmark.rt "t w/ link" do
I18n.backend.translate :en, :"activemodel.errors.messages.blank"
end
Benchmark.rt "t subtree" do
I18n.backend.translate :en, :"activerecord.errors.messages"
end
puts
end
# Run!
puts
puts "Running benchmarks with N = #{N}\n\n"
(ORDER & Backends.constants).each(&benchmarker)
Backends.constants.each do |backend_name|
backend = Backends.const_get(backend_name)
backend.reload!
backend.extend I18n::Backend::Memoize
end
puts "Running memoized benchmarks with N = #{N}\n\n"
(ORDER & Backends.constants).each(&benchmarker)

View File

@@ -1,20 +0,0 @@
# encoding: utf-8
$: << File.expand_path('../lib', __FILE__)
require 'i18n/version'
Gem::Specification.new do |s|
s.name = "i18n"
s.version = I18n::VERSION
s.authors = ["Sven Fuchs", "Joshua Harvey", "Matt Aimonetti", "Stephan Soller", "Saimon Moore"]
s.email = "rails-i18n@googlegroups.com"
s.homepage = "http://github.com/svenfuchs/i18n"
s.summary = "New wave Internationalization support for Ruby"
s.description = "New wave Internationalization support for Ruby."
s.files = `git ls-files {app,lib}`.split("\n") + %w(README.textile MIT-LICENSE CHANGELOG.textile)
s.platform = Gem::Platform::RUBY
s.require_path = 'lib'
s.rubyforge_project = '[none]'
s.required_rubygems_version = '>= 1.3.6'
end

View File

@@ -1 +0,0 @@
require 'i18n'

View File

@@ -1,8 +0,0 @@
# encoding: utf-8
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift(dir)
Dir["#{dir}/**/*_test.rb"].sort.each do |file|
require file.sub(/^#{dir}\/(.*)\.rb$/, '\1')
end

View File

@@ -1,18 +0,0 @@
module Tests
module Api
autoload :Basics, 'api/tests/basics'
autoload :Defaults, 'api/tests/defaults'
autoload :Interpolation, 'api/tests/interpolation'
autoload :Link, 'api/tests/link'
autoload :Lookup, 'api/tests/lookup'
autoload :Pluralization, 'api/tests/pluralization'
autoload :Procs, 'api/tests/procs'
module Localization
autoload :Date, 'api/tests/localization/date'
autoload :DateTime, 'api/tests/localization/date_time'
autoload :Procs, 'api/tests/localization/procs'
autoload :Time, 'api/tests/localization/time'
end
end
end

View File

@@ -1,30 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
setup_active_record
class I18nActiveRecordApiTest < Test::Unit::TestCase
def setup
I18n.backend = I18n::Backend::ActiveRecord.new
super
end
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs # unless RUBY_VERSION >= '1.9.1'
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs # unless RUBY_VERSION >= '1.9.1'
test "make sure we use an ActiveRecord backend" do
assert_equal I18n::Backend::ActiveRecord, I18n.backend.class
end
end if defined?(ActiveRecord)

View File

@@ -1,57 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
begin
require 'rubygems'
require 'active_support'
rescue LoadError
puts "not testing with Cache enabled because active_support can not be found"
end
class I18nAllFeaturesApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cache
include I18n::Backend::Metadata
include I18n::Backend::Cascade
include I18n::Backend::Fallbacks
include I18n::Backend::Pluralization
include I18n::Backend::Memoize
end
def setup
I18n.backend = I18n::Backend::Chain.new(Backend.new, I18n::Backend::Simple.new)
I18n.cache_store = cache_store
super
end
def teardown
I18n.cache_store.clear
I18n.cache_store = nil
super
end
def cache_store
ActiveSupport::Cache.lookup_store(:memory_store) if defined?(ActiveSupport) && defined?(ActiveSupport::Cache)
end
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs
test "make sure we use a Chain backend with an all features backend" do
assert_equal I18n::Backend::Chain, I18n.backend.class
assert_equal Backend, I18n.backend.backends.first.class
end
# links: test that keys stored on one backend can link to keys stored on another backend
end

View File

@@ -1,31 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
class I18nCascadeApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cascade
end
def setup
I18n.backend = Backend.new
super
end
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs
test "make sure we use a backend with Cascade included" do
assert_equal Backend, I18n.backend.class
end
end

View File

@@ -1,27 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
class I18nApiChainTest < Test::Unit::TestCase
def setup
super
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
end
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs
test "make sure we use the Chain backend" do
assert_equal I18n::Backend::Chain, I18n.backend.class
end
end

View File

@@ -1,33 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
class I18nFallbacksApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
def setup
I18n.backend = Backend.new
super
end
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs
test "make sure we use a backend with Fallbacks included" do
assert_equal Backend, I18n.backend.class
end
# links: test that keys stored on one backend can link to keys stored on another backend
end

View File

@@ -1,31 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
setup_rufus_tokyo
class I18nKeyValueApiTest < Test::Unit::TestCase
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
# include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
# include Tests::Api::Localization::Procs
STORE = Rufus::Tokyo::Cabinet.new('*')
def setup
I18n.backend = I18n::Backend::KeyValue.new(STORE)
super
end
test "make sure we use the KeyValue backend" do
assert_equal I18n::Backend::KeyValue, I18n.backend.class
end
end if defined?(Rufus::Tokyo::Cabinet)

View File

@@ -1,62 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
class I18nMemoizeBackendWithSimpleApiTest < Test::Unit::TestCase
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs
class MemoizeBackend < I18n::Backend::Simple
include I18n::Backend::Memoize
end
def setup
I18n.backend = MemoizeBackend.new
super
end
test "make sure we use the MemoizeBackend backend" do
assert_equal MemoizeBackend, I18n.backend.class
end
end
setup_rufus_tokyo
class I18nMemoizeBackendWithKeyValueApiTest < Test::Unit::TestCase
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
# include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
# include Tests::Api::Localization::Procs
class MemoizeBackend < I18n::Backend::KeyValue
include I18n::Backend::Memoize
end
STORE = Rufus::Tokyo::Cabinet.new('*')
def setup
I18n.backend = MemoizeBackend.new(STORE)
super
end
test "make sure we use the MemoizeBackend backend" do
assert_equal MemoizeBackend, I18n.backend.class
end
end if defined?(Rufus::Tokyo::Cabinet)

View File

@@ -1,33 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
class I18nPluralizationApiTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Pluralization
end
def setup
I18n.backend = Backend.new
super
end
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs
test "make sure we use a backend with Pluralization included" do
assert_equal Backend, I18n.backend.class
end
# links: test that keys stored on one backend can link to keys stored on another backend
end

View File

@@ -1,22 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
class I18nSimpleBackendApiTest < Test::Unit::TestCase
include Tests::Api::Basics
include Tests::Api::Defaults
include Tests::Api::Interpolation
include Tests::Api::Link
include Tests::Api::Lookup
include Tests::Api::Pluralization
include Tests::Api::Procs
include Tests::Api::Localization::Date
include Tests::Api::Localization::DateTime
include Tests::Api::Localization::Time
include Tests::Api::Localization::Procs
test "make sure we use the Simple backend" do
assert_equal I18n::Backend::Simple, I18n.backend.class
end
end

View File

@@ -1,24 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Basics
def test_available_locales
store_translations('de', :foo => 'bar')
store_translations('en', :foo => 'foo')
assert I18n.available_locales.include?(:de)
assert I18n.available_locales.include?(:en)
end
def test_delete_value
store_translations(:to_be_deleted => 'bar')
assert_equal 'bar', I18n.t('to_be_deleted', :default => 'baz')
I18n.cache_store.clear if I18n.respond_to?(:cache_store) && I18n.cache_store
store_translations(:to_be_deleted => nil)
assert_equal 'baz', I18n.t('to_be_deleted', :default => 'baz')
end
end
end
end

View File

@@ -1,40 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Defaults
def setup
super
store_translations(:foo => { :bar => 'bar', :baz => 'baz' })
end
define_method "test defaults: given nil as a key it returns the given default" do
assert_equal 'default', I18n.t(nil, :default => 'default')
end
define_method "test defaults: given a symbol as a default it translates the symbol" do
assert_equal 'bar', I18n.t(nil, :default => :'foo.bar')
end
define_method "test defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do
assert_equal 'bar', I18n.t(:missing, :default => :bar, :scope => :foo)
end
define_method "test defaults: given an array as a default it returns the first match" do
assert_equal 'bar', I18n.t(:does_not_exist, :default => [:does_not_exist_2, :'foo.bar'])
end
define_method "test defaults: given an array of missing keys it raises a MissingTranslationData exception" do
assert_raise I18n::MissingTranslationData do
I18n.t(:does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3], :raise => true)
end
end
define_method "test defaults: using a custom scope separator" do
# data must have been stored using the custom separator when using the ActiveRecord backend
I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|')
end
end
end
end

View File

@@ -1,108 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Interpolation
def interpolate(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
key = args.pop
I18n.backend.translate('en', key, options)
end
# If no interpolation parameter is not given, I18n should not alter the string.
# This behavior is due to three reasons:
#
# * Checking interpolation keys in all strings hits performance, badly;
#
# * This allows us to retrieve untouched values through I18n. For example
# I could have a middleware that returns I18n lookup results in JSON
# to be processed through Javascript. Leaving the keys untouched allows
# the interpolation to happen at the javascript level;
#
# * Security concerns: if I allow users to translate a web site, they can
# insert %{} in messages causing the I18n lookup to fail in every request.
#
define_method "test interpolation: given no values it does not alter the string" do
assert_equal 'Hi %{name}!', interpolate(:default => 'Hi %{name}!')
end
define_method "test interpolation: given values it interpolates them into the string" do
assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
end
define_method "test interpolation: given a nil value it still interpolates it into the string" do
assert_equal 'Hi !', interpolate(:default => 'Hi %{name}!', :name => nil)
end
define_method "test interpolation: given a lambda as a value it calls it if the string contains the key" do
assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => lambda { |*args| 'David' })
end
define_method "test interpolation: given a lambda as a value it does not call it if the string does not contain the key" do
assert_nothing_raised { interpolate(:default => 'Hi!', :name => lambda { |*args| raise 'fail' }) }
end
define_method "test interpolation: given values but missing a key it raises I18n::MissingInterpolationArgument" do
assert_raise(I18n::MissingInterpolationArgument) do
interpolate(:default => '%{foo}', :bar => 'bar')
end
end
define_method "test interpolation: it does not raise I18n::MissingInterpolationArgument for escaped variables" do
assert_nothing_raised(I18n::MissingInterpolationArgument) do
assert_equal 'Barr %{foo}', interpolate(:default => '%{bar} %%{foo}', :bar => 'Barr')
end
end
define_method "test interpolation: it does not change the original, stored translation string" do
I18n.backend.store_translations(:en, :interpolate => 'Hi %{name}!')
assert_equal 'Hi David!', interpolate(:interpolate, :name => 'David')
assert_equal 'Hi Yehuda!', interpolate(:interpolate, :name => 'Yehuda')
end
define_method "test interpolation: works with the deprecated syntax" do
deprecation = capture(:stderr) do
assert_equal 'Hi David!', interpolate(:default => 'Hi {{name}}!', :name => 'David')
end
assert_match "The {{key}} interpolation syntax in I18n messages is deprecated", deprecation
end
define_method "test interpolation: given the translation is in utf-8 it still works" do
assert_equal 'Häi David!', interpolate(:default => 'Häi %{name}!', :name => 'David')
end
define_method "test interpolation: given the value is in utf-8 it still works" do
assert_equal 'Hi ゆきひろ!', interpolate(:default => 'Hi %{name}!', :name => 'ゆきひろ')
end
define_method "test interpolation: given the translation and the value are in utf-8 it still works" do
assert_equal 'こんにちは、ゆきひろさん!', interpolate(:default => 'こんにちは、%{name}さん!', :name => 'ゆきひろ')
end
if Kernel.const_defined?(:Encoding)
define_method "test interpolation: given a euc-jp translation and a utf-8 value it raises Encoding::CompatibilityError" do
assert_raise(Encoding::CompatibilityError) do
interpolate(:default => euc_jp('こんにちは、%{name}さん!'), :name => 'ゆきひろ')
end
end
# define_method "test interpolation: given a utf-8 translation and a euc-jp value it returns a translation in euc-jp" do
# assert_equal euc_jp('Hi ゆきひろ!'), interpolate(:default => 'Hi %{name}!', :name => euc_jp('ゆきひろ'))
# end
#
# TODO should better explain how this relates to the test above with the simpler utf-8 default string
define_method "test interpolation: given a utf-8 translation and a euc-jp value it raises Encoding::CompatibilityError" do
assert_raise(Encoding::CompatibilityError) do
interpolate(:default => 'こんにちは、%{name}さん!', :name => euc_jp('ゆきひろ'))
end
end
end
define_method "test interpolation: given a translations containing a reserved key it raises I18n::ReservedInterpolationKey" do
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{default}', :foo => :bar) }
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{scope}', :foo => :bar) }
assert_raise(I18n::ReservedInterpolationKey) { interpolate(:default => '%{separator}', :foo => :bar) }
end
end
end
end

View File

@@ -1,56 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Link
define_method "test linked lookup: if a key resolves to a symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:link => :linked,
:linked => 'linked'
}
assert_equal 'linked', I18n.backend.translate('en', :link)
end
define_method "test linked lookup: if a key resolves to a dot-separated symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:link => :"foo.linked",
:foo => { :linked => 'linked' }
}
assert_equal('linked', I18n.backend.translate('en', :link))
end
define_method "test linked lookup: if a dot-separated key resolves to a symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:foo => { :link => :linked },
:linked => 'linked'
}
assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
end
define_method "test linked lookup: if a dot-separated key resolves to a dot-separated symbol it looks up the symbol" do
I18n.backend.store_translations 'en', {
:foo => { :link => :"bar.linked" },
:bar => { :linked => 'linked' }
}
assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
end
define_method "test linked lookup: links always refer to the absolute key" do
I18n.backend.store_translations 'en', {
:foo => { :link => :linked, :linked => 'linked in foo' },
:linked => 'linked absolutely'
}
assert_equal 'linked absolutely', I18n.backend.translate('en', :link, :scope => :foo)
end
define_method "test linked lookup: a link can resolve to a namespace in the middle of a dot-separated key" do
I18n.backend.store_translations 'en', {
:activemodel => { :errors => { :messages => { :blank => "can't be blank" } } },
:activerecord => { :errors => { :messages => :"activemodel.errors.messages" } }
}
assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
end
end
end
end

View File

@@ -1,84 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Localization
module Date
def setup
super
setup_date_translations
@date = ::Date.new(2008, 3, 1)
end
define_method "test localize Date: given the short format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal '01. Mar', I18n.l(@date, :format => :short, :locale => :de)
end
define_method "test localize Date: given the long format it uses it" do
assert_equal '01. März 2008', I18n.l(@date, :format => :long, :locale => :de)
end
define_method "test localize Date: given the default format it uses it" do
assert_equal '01.03.2008', I18n.l(@date, :format => :default, :locale => :de)
end
define_method "test localize Date: given a day name format it returns the correct day name" do
assert_equal 'Samstag', I18n.l(@date, :format => '%A', :locale => :de)
end
define_method "test localize Date: given an abbreviated day name format it returns the correct abbreviated day name" do
assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de)
end
define_method "test localize Date: given a month name format it returns the correct month name" do
assert_equal 'März', I18n.l(@date, :format => '%B', :locale => :de)
end
define_method "test localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Mar', I18n.l(@date, :format => '%b', :locale => :de)
end
define_method "test localize Date: given an unknown format it does not fail" do
assert_nothing_raised { I18n.l(@date, :format => '%x') }
end
define_method "test localize Date: given nil it raises I18n::ArgumentError" do
assert_raise(I18n::ArgumentError) { I18n.l(nil) }
end
define_method "test localize Date: given a plain Object it raises I18n::ArgumentError" do
assert_raise(I18n::ArgumentError) { I18n.l(Object.new) }
end
define_method "test localize Date: given a format is missing it raises I18n::MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.l(@date, :format => :missing) }
end
define_method "test localize Date: it does not alter the format string" do
assert_equal '01. Februar 2009', I18n.l(::Date.parse('2009-02-01'), :format => :long, :locale => :de)
assert_equal '01. Oktober 2009', I18n.l(::Date.parse('2009-10-01'), :format => :long, :locale => :de)
end
protected
def setup_date_translations
store_translations :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)
}
}
end
end
end
end
end

View File

@@ -1,77 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Localization
module DateTime
def setup
super
setup_datetime_translations
@datetime = ::DateTime.new(2008, 3, 1, 6)
@other_datetime = ::DateTime.new(2008, 3, 1, 18)
end
define_method "test localize DateTime: given the short format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal '01. Mar 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
end
define_method "test localize DateTime: given the long format it uses it" do
assert_equal '01. März 2008 06:00', I18n.l(@datetime, :format => :long, :locale => :de)
end
define_method "test localize DateTime: given the default format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
end
define_method "test localize DateTime: given a day name format it returns the correct day name" do
assert_equal 'Samstag', I18n.l(@datetime, :format => '%A', :locale => :de)
end
define_method "test localize DateTime: given an abbreviated day name format it returns the correct abbreviated day name" do
assert_equal 'Sa', I18n.l(@datetime, :format => '%a', :locale => :de)
end
define_method "test localize DateTime: given a month name format it returns the correct month name" do
assert_equal 'März', I18n.l(@datetime, :format => '%B', :locale => :de)
end
define_method "test localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Mar', I18n.l(@datetime, :format => '%b', :locale => :de)
end
define_method "test localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
assert_equal 'am', I18n.l(@datetime, :format => '%p', :locale => :de)
assert_equal 'pm', I18n.l(@other_datetime, :format => '%p', :locale => :de)
end
define_method "test localize DateTime: given an unknown format it does not fail" do
assert_nothing_raised { I18n.l(@datetime, :format => '%x') }
end
define_method "test localize DateTime: given a format is missing it raises I18n::MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.l(@datetime, :format => :missing) }
end
protected
def setup_datetime_translations
# time translations might have been set up in Tests::Api::Localization::Time
store_translations :de, {
: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'
}
}
end
end
end
end
end

View File

@@ -1,117 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Localization
module Procs
define_method "test localize: using day names from lambdas" do
if can_store_procs?
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_match /Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru)
assert_match /суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru)
end
end
define_method "test localize: using month names from lambdas" do
if can_store_procs?
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_match /марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru)
assert_match /Март /, I18n.l(time, :format => "%B %Y", :locale => :ru)
end
end
define_method "test localize: using abbreviated day names from lambdas" do
if can_store_procs?
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_match /марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru)
assert_match /март /, I18n.l(time, :format => "%b %Y", :locale => :ru)
end
end
define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
if can_store_procs?
setup_time_proc_translations
date = ::Date.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008, {}]', I18n.l(date, :format => :proc, :locale => :ru)
end
end
define_method "test localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
if can_store_procs?
setup_time_proc_translations
date = ::Date.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008, {:foo=>"foo"}]', I18n.l(date, :format => :proc, :foo => 'foo', :locale => :ru)
end
end
define_method "test localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
if can_store_procs?
setup_time_proc_translations
datetime = ::DateTime.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
end
end
define_method "test localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
if can_store_procs?
setup_time_proc_translations
datetime = ::DateTime.new(2008, 3, 1, 6)
assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
end
end
define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
if can_store_procs?
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
assert_equal [time, {}].inspect, I18n.l(time, :format => :proc, :locale => :ru)
end
end
define_method "test localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
if can_store_procs?
setup_time_proc_translations
time = ::Time.parse('2008-03-01 6:00 UTC')
options = { :foo => 'foo' }
assert_equal [time, options].inspect, I18n.l(time, options.merge(:format => :proc, :locale => :ru))
end
end
protected
def setup_time_proc_translations
store_translations :ru, {
:time => {
:formats => {
:proc => lambda { |*args| args.inspect }
}
},
:date => {
:formats => {
:proc => lambda { |*args| args.inspect }
},
:'day_names' => lambda { |key, options|
(options[:format] =~ /^%A/) ?
%w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
%w(воскресенье понедельник вторник среда четверг пятница суббота)
},
:'month_names' => lambda { |key, options|
(options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
%w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
%w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
},
:'abbr_month_names' => lambda { |key, options|
(options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
%w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
%w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
},
}
}
end
end
end
end
end

View File

@@ -1,76 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Localization
module Time
def setup
super
setup_time_translations
@time = ::Time.parse('2008-03-01 6:00 UTC')
@other_time = ::Time.parse('2008-03-01 18:00 UTC')
end
define_method "test localize Time: given the short format it uses it" do
# TODO should be Mrz, shouldn't it?
assert_equal '01. Mar 06:00', I18n.l(@time, :format => :short, :locale => :de)
end
define_method "test localize Time: given the long format it uses it" do
assert_equal '01. März 2008 06:00', I18n.l(@time, :format => :long, :locale => :de)
end
# TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
# def test_localize_given_the_default_format_it_uses_it
# assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@time, :format => :default, :locale => :de)
# end
define_method "test localize Time: given a day name format it returns the correct day name" do
assert_equal 'Samstag', I18n.l(@time, :format => '%A', :locale => :de)
end
define_method "test localize Time: given an abbreviated day name format it returns the correct abbreviated day name" do
assert_equal 'Sa', I18n.l(@time, :format => '%a', :locale => :de)
end
define_method "test localize Time: given a month name format it returns the correct month name" do
assert_equal 'März', I18n.l(@time, :format => '%B', :locale => :de)
end
define_method "test localize Time: given an abbreviated month name format it returns the correct abbreviated month name" do
# TODO should be Mrz, shouldn't it?
assert_equal 'Mar', I18n.l(@time, :format => '%b', :locale => :de)
end
define_method "test localize Time: given a meridian indicator format it returns the correct meridian indicator" do
assert_equal 'am', I18n.l(@time, :format => '%p', :locale => :de)
assert_equal 'pm', I18n.l(@other_time, :format => '%p', :locale => :de)
end
define_method "test localize Time: given an unknown format it does not fail" do
assert_nothing_raised { I18n.l(@time, :format => '%x') }
end
define_method "test localize Time: given a format is missing it raises I18n::MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.l(@time, :format => :missing) }
end
protected
def setup_time_translations
store_translations :de, {
: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'
}
}
end
end
end
end
end

View File

@@ -1,70 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Lookup
def setup
super
store_translations(:foo => { :bar => 'bar', :baz => 'baz' }, :bla => false,
:string => "a", :array => %w(a b c), :hash => { "a" => "b" })
end
define_method "test lookup: it returns a string" do
assert_equal("a", I18n.t(:string))
end
define_method "test lookup: it returns hash" do
assert_equal({ :a => "b" }, I18n.t(:hash))
end
define_method "test lookup: it returns a array" do
assert_equal(%w(a b c), I18n.t(:array))
end
define_method "test lookup: it returns a native false" do
assert_equal false, I18n.t(:bla)
end
define_method "test lookup: given a missing key, no default and no raise option it returns an error message" do
assert_equal "translation missing: en, missing", I18n.t(:missing)
end
define_method "test lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
end
define_method "test lookup: does not raise an exception if no translation data is present for the given locale" do
assert_nothing_raised { I18n.t(:foo, :locale => :xx) }
end
define_method "test lookup: given an array of keys it translates all of them" do
assert_equal %w(bar baz), I18n.t([:bar, :baz], :scope => [:foo])
end
define_method "test lookup: using a custom scope separator" do
# data must have been stored using the custom separator when using the ActiveRecord backend
I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
assert_equal 'bar', I18n.t('foo|bar', :separator => '|')
end
# In fact it probably *should* fail but Rails currently relies on using the default locale instead.
# So we'll stick to this for now until we get it fixed in Rails.
define_method "test lookup: given nil as a locale it does not raise but use the default locale" do
# assert_raise(I18n::InvalidLocale) { I18n.t(:bar, :locale => nil) }
assert_nothing_raised { I18n.t(:bar, :locale => nil) }
end
define_method "test lookup: a resulting String is not frozen" do
assert !I18n.t(:string).frozen?
end
define_method "test lookup: a resulting Array is not frozen" do
assert !I18n.t(:array).frozen?
end
define_method "test lookup: a resulting Hash is not frozen" do
assert !I18n.t(:hash).frozen?
end
end
end
end

View File

@@ -1,35 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Pluralization
define_method "test pluralization: given 0 it returns the :zero translation if it is defined" do
assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0)
end
define_method "test pluralization: given 0 it returns the :other translation if :zero is not defined" do
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0)
end
define_method "test pluralization: given 1 it returns the singular translation" do
assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1)
end
define_method "test pluralization: given 2 it returns the :other translation" do
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2)
end
define_method "test pluralization: given 3 it returns the :other translation" do
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3)
end
define_method "test pluralization: given nil it returns the whole entry" do
assert_equal({ :one => 'bar' }, I18n.t(:default => { :one => 'bar' }, :count => nil))
end
define_method "test pluralization: given incomplete pluralization data it raises I18n::InvalidPluralizationData" do
assert_raise(I18n::InvalidPluralizationData) { I18n.t(:default => { :one => 'bar' }, :count => 2) }
end
end
end
end

View File

@@ -1,55 +0,0 @@
# encoding: utf-8
module Tests
module Api
module Procs
define_method "test lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
if can_store_procs?
store_translations(:a_lambda => lambda { |*args| args.inspect })
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
end
end
define_method "test defaults: given a default is a Proc it calls it with the key and interpolation values" do
proc = lambda { |*args| args.inspect }
assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
end
define_method "test defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do
if can_store_procs?
store_translations(:a_lambda => lambda { |*args| args.inspect })
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo')
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo')
end
end
define_method "test interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
proc = lambda { |*args| args.inspect }
assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc)
end
define_method "test interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
proc = lambda { |*args| "%{foo}: " + args.inspect }
assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
end
define_method "test pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do
proc = lambda { |*args| { :zero => 'zero', :one => 'one', :other => 'other' } }
assert_equal 'zero', I18n.t(:default => proc, :count => 0)
assert_equal 'one', I18n.t(:default => proc, :count => 1)
assert_equal 'other', I18n.t(:default => proc, :count => 2)
end
define_method "test lookup: given the option :resolve => false was passed it does not resolve proc translations" do
if can_store_procs?
store_translations(:a_lambda => lambda { |*args| args.inspect })
assert_equal Proc, I18n.t(:a_lambda, :resolve => false).class
end
end
define_method "test lookup: given the option :resolve => false was passed it does not resolve proc default" do
assert_equal Proc, I18n.t(nil, :default => lambda { |*args| args.inspect }, :resolve => false).class
end
end
end
end

View File

@@ -1,51 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../')); $:.uniq!
require 'test_helper'
setup_active_record
class I18nActiveRecordMissingTest < Test::Unit::TestCase
def setup
store_translations(:en, :i18n => { :plural => { :keys => [:zero, :one, :other] } })
I18n.backend = I18n::Backend::Chain.new(I18n.backend)
I18n.backend.meta_class.send(:include, I18n::Backend::ActiveRecord::Missing)
I18n::Backend::ActiveRecord::Translation.delete_all
end
test "can persist interpolations" do
translation = I18n::Backend::ActiveRecord::Translation.new(:key => 'foo', :value => 'bar', :locale => :en)
translation.interpolations = %w(count name)
translation.save
assert translation.valid?
end
test "lookup persists the key" do
I18n.t('foo.bar.baz')
assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
end
test "lookup does not persist the key twice" do
2.times { I18n.t('foo.bar.baz') }
assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
end
test "lookup persists interpolation keys when looked up directly" do
I18n.t('foo.bar.baz', :cow => "lucy" ) # creates stub translation.
translation_stub = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.bar.baz').first
assert translation_stub.interpolates?(:cow)
end
test "creates one stub per pluralization" do
I18n.t('foo', :count => 999)
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_all_by_key %w{ foo.zero foo.one foo.other }
assert_equal 3, translations.length
end
test "creates no stub for base key in pluralization" do
I18n.t('foo', :count => 999)
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key %w{ foo.zero foo.one foo.other }
assert !I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key("foo")
end
end if defined?(ActiveRecord)

View File

@@ -1,57 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
setup_active_record
class I18nBackendActiveRecordTest < Test::Unit::TestCase
def setup
I18n.backend = I18n::Backend::ActiveRecord.new
store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
end
def teardown
I18n::Backend::ActiveRecord::Translation.destroy_all
super
end
test "store_translations does not allow ambiguous keys (1)" do
I18n::Backend::ActiveRecord::Translation.delete_all
I18n.backend.store_translations(:en, :foo => 'foo')
I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all
assert_equal %w(bar baz), translations.map(&:value)
assert_equal({ :bar => 'bar', :baz => 'baz' }, I18n.t(:foo))
end
test "store_translations does not allow ambiguous keys (2)" do
I18n::Backend::ActiveRecord::Translation.delete_all
I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
I18n.backend.store_translations(:en, :foo => 'foo')
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all
assert_equal %w(foo), translations.map(&:value)
assert_equal 'foo', I18n.t(:foo)
end
test "can store translations with keys that are translations containing special chars" do
I18n.backend.store_translations(:es, :"Pagina's" => "Pagina's" )
assert_equal "Pagina's", I18n.t(:"Pagina's", :locale => :es)
end
with_mocha do
test "missing translations table does not cause an error in #available_locales" do
I18n::Backend::ActiveRecord::Translation.expects(:available_locales).raises(::ActiveRecord::StatementInvalid)
assert_equal [], I18n.backend.available_locales
end
end
def test_expand_keys
assert_equal %w(foo foo.bar foo.bar.baz), I18n.backend.send(:expand_keys, :'foo.bar.baz')
end
end if defined?(ActiveRecord)

View File

@@ -1,70 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
begin
require 'active_support'
rescue LoadError
$stderr.puts "Skipping cache tests using ActiveSupport"
else
class I18nBackendCacheTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cache
end
def setup
I18n.backend = Backend.new
super
I18n.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
end
def teardown
I18n.cache_store = nil
end
test "it uses the cache" do
assert I18n.cache_store.is_a?(ActiveSupport::Cache::MemoryStore)
end
with_mocha do
test "translate hits the backend and caches the response" do
I18n.backend.expects(:lookup).returns('Foo')
assert_equal 'Foo', I18n.t(:foo)
I18n.backend.expects(:lookup).never
assert_equal 'Foo', I18n.t(:foo)
I18n.backend.expects(:lookup).returns('Bar')
assert_equal 'Bar', I18n.t(:bar)
end
test "still raises MissingTranslationData but also caches it" do
I18n.backend.expects(:lookup).returns(nil)
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
I18n.backend.expects(:lookup).never
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
end
end
test "uses 'i18n' as a cache key namespace by default" do
assert_equal 0, I18n.backend.send(:cache_key, :foo).index('i18n')
end
test "adds a custom cache key namespace" do
with_cache_namespace('bar') do
assert_equal 0, I18n.backend.send(:cache_key, :foo).index('i18n-bar')
end
end
protected
def with_cache_namespace(namespace)
I18n.cache_namespace = namespace
yield
I18n.cache_namespace = nil
end
end
end # AS cache check

View File

@@ -1,72 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nBackendCascadeTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cascade
end
def setup
I18n.backend = Backend.new
store_translations(:en,
:foo => 'foo',
:bar => { :baz => 'baz' }
)
end
def lookup(key, options = {})
I18n.t(key, options.merge(:cascade => { :step => 1, :offset => 1, :skip_root => false }))
end
test "still returns an existing translation as usual" do
assert_equal 'foo', lookup(:foo)
assert_equal 'baz', lookup(:'bar.baz')
end
test "falls back by cutting keys off the end of the scope" do
assert_equal 'foo', lookup(:foo, :scope => :'missing')
assert_equal 'foo', lookup(:foo, :scope => :'missing.missing')
assert_equal 'baz', lookup(:baz, :scope => :'bar.missing')
assert_equal 'baz', lookup(:baz, :scope => :'bar.missing.missing')
end
test "raises I18n::MissingTranslationData exception when no translation was found" do
assert_raise(I18n::MissingTranslationData) { lookup(:'foo.missing', :raise => true) }
assert_raise(I18n::MissingTranslationData) { lookup(:'bar.baz.missing', :raise => true) }
assert_raise(I18n::MissingTranslationData) { lookup(:'missing.bar.baz', :raise => true) }
end
test "cascades before evaluating the default" do
assert_equal 'foo', lookup(:foo, :scope => :missing, :default => 'default')
end
test "cascades defaults, too" do
assert_equal 'foo', lookup(nil, :default => [:'missing.missing', :'missing.foo'])
end
test "let's us assemble required fallbacks for ActiveRecord validation messages" do
store_translations(:en,
:errors => {
:reply => {
:title => {
:blank => 'blank on reply title'
},
:taken => 'taken on reply'
},
:topic => {
:title => {
:format => 'format on topic title'
},
:length => 'length on topic'
},
:odd => 'odd on errors'
}
)
assert_equal 'blank on reply title', lookup(:'errors.reply.title.blank', :default => :'errors.topic.title.blank')
assert_equal 'taken on reply', lookup(:'errors.reply.title.taken', :default => :'errors.topic.title.taken')
assert_equal 'format on topic title', lookup(:'errors.reply.title.format', :default => :'errors.topic.title.format')
assert_equal 'length on topic', lookup(:'errors.reply.title.length', :default => :'errors.topic.title.length')
assert_equal 'odd on errors', lookup(:'errors.reply.title.odd', :default => :'errors.topic.title.odd')
end
end

View File

@@ -1,63 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nBackendChainTest < Test::Unit::TestCase
def setup
@first = backend(:en => {
:foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '%{count}' }
})
@second = backend(:en => {
:bar => 'Bar', :formats => { :long => 'long' }, :plural_2 => { :one => 'one' }
})
@chain = I18n.backend = I18n::Backend::Chain.new(@first, @second)
end
test "looks up translations from the first chained backend" do
assert_equal 'Foo', @first.send(:translations)[:en][:foo]
assert_equal 'Foo', I18n.t(:foo)
end
test "looks up translations from the second chained backend" do
assert_equal 'Bar', @second.send(:translations)[:en][:bar]
assert_equal 'Bar', I18n.t(:bar)
end
test "defaults only apply to lookups on the last backend in the chain" do
assert_equal 'Foo', I18n.t(:foo, :default => 'Bah')
assert_equal 'Bar', I18n.t(:bar, :default => 'Bah')
assert_equal 'Bah', I18n.t(:bah, :default => 'Bah') # default kicks in only here
end
test "default" do
assert_equal 'Fuh', I18n.t(:default => 'Fuh')
assert_equal 'Zero', I18n.t(:default => { :zero => 'Zero' }, :count => 0)
assert_equal({ :zero => 'Zero' }, I18n.t(:default => { :zero => 'Zero' }))
assert_equal 'Foo', I18n.t(:default => :foo)
end
test "namespace lookup collects results from all backends" do
assert_equal({ :short => 'short', :long => 'long' }, I18n.t(:formats))
end
test "namespace lookup with only the first backend returning a result" do
assert_equal({ :one => '%{count}' }, I18n.t(:plural_1))
end
test "pluralization still works" do
assert_equal '1', I18n.t(:plural_1, :count => 1)
assert_equal 'one', I18n.t(:plural_2, :count => 1)
end
test "bulk lookup collects results from all backends" do
assert_equal ['Foo', 'Bar'], I18n.t([:foo, :bar])
end
protected
def backend(translations)
backend = I18n::Backend::Simple.new
translations.each { |locale, translations| backend.store_translations(locale, translations) }
backend
end
end

View File

@@ -1,150 +0,0 @@
# encoding: utf-8
begin
require 'cldr'
rescue LoadError
puts "Skipping tests for I18n::Backend::Cldr because the ruby-cldr gem is not installed."
end
if defined?(Cldr)
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'i18n/backend/cldr'
require 'date'
class I18nBackendCldrTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Cldr
end
def setup
I18n.backend = Backend.new
I18n.locale = :de
I18n.load_path += Dir[locales_dir + '/cldr/**/*.{yml,rb}']
super
end
# NUMBER
test "format_number" do
assert_equal '123.456,78', I18n.l(123456.78)
end
# CURRENCY
test "format_currency" do
assert_equal '123.456,78 EUR', I18n.l(123456.78, :currency => 'EUR')
end
# hu? does this actually make any sense?
test "format_currency translating currency names" do
assert_equal '1,00 Irisches Pfund', I18n.l(1, :currency => :IEP)
assert_equal '2,00 Irische Pfund', I18n.l(2, :currency => :IEP)
end
# PERCENT
# this is odd but the cldr percent format does not include a fraction
test "format_percent" do
assert_equal '123.457 %', I18n.l(123456.78, :as => :percent)
end
# so we can pass a precision manually
test "format_percent w/ precision" do
assert_equal '123.456,70 %', I18n.l(123456.7, :as => :percent, :precision => 2)
end
# DATE
def date
Date.new(2010, 1, 1)
end
test "format_date :full" do
assert_equal 'Freitag, 1. Januar 2010', I18n.l(date, :format => :full)
end
test "format_date :long" do
assert_equal '1. Januar 2010', I18n.l(date, :format => :long)
end
test "format_date :medium" do
assert_equal '01.01.2010', I18n.l(date)
end
test "format_date :short" do
assert_equal '01.01.10', I18n.l(date, :format => :short)
end
# TIME
def time
Time.utc(2010, 1, 1, 13, 15, 17)
end
# TODO cldr export lacks localized timezone data
# test "format_time :full" do
# assert_equal 'Freitag, 1. Januar 2010', I18n.l(time, :format => :full)
# end
test "format_time :long" do
assert_equal '13:15:17 UTC', I18n.l(time, :format => :long)
end
test "format_time :medium" do
assert_equal '13:15:17', I18n.l(time)
end
test "format_time :short" do
assert_equal '13:15', I18n.l(time, :format => :short)
end
# DATETIME
def datetime
DateTime.new(2010, 11, 12, 13, 14, 15)
end
# TODO cldr export lacks localized timezone data
# test "format_datetime :full" do
# assert_equal 'Thursday, 12. November 2010 13:14:15', I18n.l(datetime, :format => :full)
# end
test "format_datetime :long" do
assert_equal '12. November 2010 13:14:15 +00:00', I18n.l(datetime, :format => :long)
end
test "format_datetime :medium" do
assert_equal '12.11.2010 13:14:15', I18n.l(datetime)
end
test "format_datetime :short" do
assert_equal '12.11.10 13:14', I18n.l(datetime, :format => :short)
end
test "format_datetime mixed :long + :short" do
assert_equal '12. November 2010 13:14', I18n.l(datetime, :date_format => :long, :time_format => :short)
end
test "format_datetime mixed :short + :long" do
assert_equal '12.11.10 13:14:15 +00:00', I18n.l(datetime, :date_format => :short, :time_format => :long)
end
# CUSTOM FORMATS
test "can deal with customized formats data" do
store_translations :de, :numbers => {
:formats => {
:decimal => {
:patterns => {
:default => "#,##0.###",
:stupid => "#"
}
}
}
}
assert_equal '123.456,78', I18n.l(123456.78)
assert_equal '123457', I18n.l(123456.78, :format => :stupid)
end
end
end

View File

@@ -1,25 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nBackendExceptionsTest < Test::Unit::TestCase
def setup
I18n.backend = I18n::Backend::Simple.new
end
test "exceptions: MissingTranslationData message from #translate includes the given scope and full key" do
begin
I18n.t(:'baz.missing', :scope => :'foo.bar', :raise => true)
rescue I18n::MissingTranslationData => exception
end
assert_equal "translation missing: en, foo, bar, baz, missing", exception.message
end
test "exceptions: MissingTranslationData message from #localize includes the given scope and full key" do
begin
I18n.l(Time.now, :format => :foo)
rescue I18n::MissingTranslationData => exception
end
assert_equal "translation missing: en, time, formats, foo", exception.message
end
end

View File

@@ -1,104 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nBackendFallbacksTranslateTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
def setup
I18n.backend = Backend.new
store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en')
store_translations(:de, :bar => 'Bar in :de', :baz => 'Baz in :de')
store_translations(:'de-DE', :baz => 'Baz in :de-DE')
end
test "still returns an existing translation as usual" do
assert_equal 'Foo in :en', I18n.t(:foo, :locale => :en)
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :de)
assert_equal 'Baz in :de-DE', I18n.t(:baz, :locale => :'de-DE')
end
test "returns the :en translation for a missing :de translation" do
assert_equal 'Foo in :en', I18n.t(:foo, :locale => :de)
end
test "returns the :de translation for a missing :'de-DE' translation" do
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE')
end
test "returns the :en translation for translation missing in both :de and :'de-De'" do
assert_equal 'Buz in :en', I18n.t(:buz, :locale => :'de-DE')
end
test "returns the :de translation for a missing :'de-DE' when :default is a String" do
assert_equal 'Bar in :de', I18n.t(:bar, :locale => :'de-DE', :default => "Default Bar")
assert_equal "Default Bar", I18n.t(:missing_bar, :locale => :'de-DE', :default => "Default Bar")
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
test "returns the defaults translation for a missing :'de-DE' when defaults a contains String before Symbol" do
assert_equal "Default Bar", I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, "Default Bar", :baz])
end
test "returns the default translation for a missing :'de-DE' and existing :de when default is a Hash" do
assert_equal 'Default 6 Bars', I18n.t(:missing_foo, :locale => :'de-DE', :default => [:missing_bar, {:other => "Default %{count} Bars"}, "Default Bar"], :count => 6)
end
test "raises I18n::MissingTranslationData exception when no translation was found" do
assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :en, :raise => true) }
assert_raise(I18n::MissingTranslationData) { I18n.t(:faa, :locale => :de, :raise => true) }
end
end
class I18nBackendFallbacksLocalizeTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
def setup
I18n.backend = Backend.new
store_translations(:en, :date => { :formats => { :en => 'en' }, :day_names => %w(Sunday) })
store_translations(:de, :date => { :formats => { :de => 'de' } })
end
test "still uses an existing format as usual" do
assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :en)
end
test "looks up and uses a fallback locale's format for a key missing in the given locale (1)" do
assert_equal 'en', I18n.l(Date.today, :format => :en, :locale => :de)
end
test "looks up and uses a fallback locale's format for a key missing in the given locale (2)" do
assert_equal 'de', I18n.l(Date.today, :format => :de, :locale => :'de-DE')
end
test "still uses an existing day name translation as usual" do
assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :en)
end
test "uses a fallback locale's translation for a key missing in the given locale" do
assert_equal 'Sunday', I18n.l(Date.new(2010, 1, 3), :format => '%A', :locale => :de)
end
end
class I18nBackendFallbacksWithChainTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Fallbacks
end
def setup
backend = Backend.new
backend.store_translations(:de, :foo => 'FOO')
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, backend)
end
test "falls back from de-DE to de when there is no translation for de-DE available" do
assert_equal 'FOO', I18n.t(:foo, :locale => :'de-DE')
end
end

View File

@@ -1,105 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'api'
class InterpolationCompilerTest < Test::Unit::TestCase
Compiler = I18n::Backend::InterpolationCompiler::Compiler
def compile_and_interpolate(str, values = {})
Compiler.compile_if_an_interpolation(str).i18n_interpolate(values)
end
def assert_escapes_interpolation_key(expected, malicious_str)
assert_equal(expected, Compiler.send(:escape_key_sym, malicious_str))
end
def test_escape_key_properly_escapes
assert_escapes_interpolation_key ':"\""', '"'
assert_escapes_interpolation_key ':"\\\\"', '\\'
assert_escapes_interpolation_key ':"\\\\\""', '\\"'
assert_escapes_interpolation_key ':"\#{}"', '#{}'
assert_escapes_interpolation_key ':"\\\\\#{}"', '\#{}'
end
def assert_escapes_plain_string(expected, plain_str)
assert_equal expected, Compiler.send(:escape_plain_str, plain_str)
end
def test_escape_plain_string_properly_escapes
assert_escapes_plain_string '\\"', '"'
assert_escapes_plain_string '\'', '\''
assert_escapes_plain_string '\\#', '#'
assert_escapes_plain_string '\\#{}', '#{}'
assert_escapes_plain_string '\\\\\\"','\\"'
end
def test_non_interpolated_strings_or_arrays_dont_get_compiled
['abc', '\\{a}}', '{a}}', []].each do |obj|
Compiler.compile_if_an_interpolation(obj)
assert_equal false, obj.respond_to?(:i18n_interpolate)
end
end
def test_interpolated_string_gets_compiled
assert_equal '-A-', compile_and_interpolate('-%{a}-', :a => 'A')
end
def assert_handles_key(str, key)
assert_equal 'A', compile_and_interpolate(str, key => 'A')
end
def test_compiles_fancy_keys
assert_handles_key('%{\}', :'\\' )
assert_handles_key('%{#}', :'#' )
assert_handles_key('%{#{}', :'#{' )
assert_handles_key('%{#$SAFE}', :'#$SAFE')
assert_handles_key('%{\000}', :'\000' )
assert_handles_key('%{\'}', :'\'' )
assert_handles_key('%{\'\'}', :'\'\'' )
assert_handles_key('%{a.b}', :'a.b' )
assert_handles_key('%{ }', :' ' )
assert_handles_key('%{:}', :':' )
assert_handles_key("%{:''}", :":''" )
assert_handles_key('%{:"}', :':"' )
end
def test_str_containing_only_escaped_interpolation_is_handled_correctly
assert_equal 'abc %{x}', compile_and_interpolate('abc %%{x}')
end
def test_handles_weird_strings
assert_equal '#{} a', compile_and_interpolate('#{} %{a}', :a => 'a')
assert_equal '"#{abc}"', compile_and_interpolate('"#{ab%{a}c}"', :a => '' )
assert_equal 'a}', compile_and_interpolate('%{{a}}', :'{a' => 'a')
assert_equal '"', compile_and_interpolate('"%{a}', :a => '' )
assert_equal 'a%{a}', compile_and_interpolate('%{a}%%{a}', :a => 'a')
assert_equal '%%{a}', compile_and_interpolate('%%%{a}')
assert_equal '\";eval("a")', compile_and_interpolate('\";eval("%{a}")', :a => 'a')
assert_equal '\";eval("a")', compile_and_interpolate('\";eval("a")%{a}', :a => '' )
assert_equal "\na", compile_and_interpolate("\n%{a}", :a => 'a')
end
end
class I18nBackendInterpolationCompilerTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::InterpolationCompiler
end
include Tests::Api::Interpolation
def setup
I18n.backend = Backend.new
super
end
# pre-compile default strings to make sure we are testing I18n::Backend::InterpolationCompiler
def interpolate(*args)
options = args.last.kind_of?(Hash) ? args.last : {}
if default_str = options[:default]
I18n::Backend::InterpolationCompiler::Compiler.compile_if_an_interpolation(default_str)
end
super
end
end

View File

@@ -1,50 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
setup_rufus_tokyo
require 'active_support/all'
class I18nBackendKeyValueTest < Test::Unit::TestCase
def setup_backend!(subtree=true)
I18n.backend = I18n::Backend::KeyValue.new(Rufus::Tokyo::Cabinet.new('*'), subtree)
store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
end
def assert_flattens(expected, nested, escape=true, subtree=true)
assert_equal expected, I18n.backend.flatten_translations("en", nested, escape, subtree)
end
test "hash flattening works" do
setup_backend!
assert_flattens(
{:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}, :"b.f" => {:x=>"x"}, :"b.c"=>"c", :"b.f.x"=>"x", :"b.d"=>"d"},
{:a=>'a', :b=>{:c=>'c', :d=>'d', :f=>{:x=>'x'}}}
)
assert_flattens({:a=>{:b =>['a', 'b']}, :"a.b"=>['a', 'b']}, {:a=>{:b =>['a', 'b']}})
assert_flattens({:"a\001b" => "c"}, {:"a.b" => "c"})
assert_flattens({:"a.b"=>['a', 'b']}, {:a=>{:b =>['a', 'b']}}, true, false)
assert_flattens({:"a.b" => "c"}, {:"a.b" => "c"}, false)
end
test "store_translations handle subtrees by default" do
setup_backend!
assert_equal({ :bar => 'bar', :baz => 'baz' }, I18n.t("foo"))
end
test "store_translations merge subtrees accordingly" do
setup_backend!
store_translations(:en, :foo => { :baz => "BAZ"})
assert_equal('BAZ', I18n.t("foo.baz"))
assert_equal({ :bar => 'bar', :baz => 'BAZ' }, I18n.t("foo"))
end
test "store_translations does not handle subtrees if desired" do
setup_backend!(false)
assert_raise I18n::MissingTranslationData do
I18n.t("foo", :raise => true)
end
end
end if defined?(Rufus::Tokyo::Cabinet)

View File

@@ -1,15 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'backend/simple_test'
class I18nBackendMemoizeTest < I18nBackendSimpleTest
class MemoizeBackend < I18n::Backend::Simple
include I18n::Backend::Memoize
end
def setup
I18n.backend = MemoizeBackend.new
super
end
end

View File

@@ -1,69 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
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 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
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
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

View File

@@ -1,46 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nBackendPluralizationTest < Test::Unit::TestCase
class Backend < I18n::Backend::Simple
include I18n::Backend::Pluralization
include I18n::Backend::Fallbacks
end
def setup
I18n.backend = Backend.new
@rule = lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other }
store_translations(:xx, :i18n => { :plural => { :rule => @rule } })
@entry = { :zero => 'zero', :one => 'one', :few => 'few', :many => 'many', :other => 'other' }
end
test "pluralization picks a pluralizer from :'i18n.pluralize'" do
assert_equal @rule, I18n.backend.send(:pluralizer, :xx)
end
test "pluralization picks :one for 1" do
assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :xx)
end
test "pluralization picks :few for 2" do
assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :xx)
end
test "pluralization picks :many for 11" do
assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :xx)
end
test "pluralization picks zero for 0 if the key is contained in the data" do
assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :xx)
end
test "pluralization picks few for 0 if the key is not contained in the data" do
@entry.delete(:zero)
assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx)
end
test "Fallbacks can pick up rules from fallback locales, too" do
assert_equal @rule, I18n.backend.send(:pluralizer, :'xx-XX')
end
end

View File

@@ -1,81 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nBackendSimpleTest < Test::Unit::TestCase
def setup
I18n.backend = I18n::Backend::Simple.new
I18n.load_path = [locales_dir + '/en.yml']
end
# useful because this way we can use the backend with no key for interpolation/pluralization
test "simple backend translate: given nil as a key it still interpolations the default value" do
assert_equal "Hi David", I18n.t(nil, :default => "Hi %{name}", :name => "David")
end
# loading translations
test "simple load_translations: given an unknown file type it raises I18n::UnknownFileType" do
assert_raise(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
end
test "simple load_translations: given a Ruby file name it does not raise anything" do
assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
end
test "simple load_translations: given no argument, it uses I18n.load_path" do
I18n.backend.load_translations
assert_equal({ :en => { :foo => { :bar => 'baz' } } }, I18n.backend.send(:translations))
end
test "simple load_rb: loads data from a Ruby file" do
data = I18n.backend.send(:load_rb, "#{locales_dir}/en.rb")
assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
end
test "simple load_yml: loads data from a YAML file" do
data = I18n.backend.send(:load_yml, "#{locales_dir}/en.yml")
assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
end
test "simple load_translations: loads data from known file formats" do
I18n.backend = I18n::Backend::Simple.new
I18n.backend.load_translations("#{locales_dir}/en.rb", "#{locales_dir}/en.yml")
expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
assert_equal expected, translations
end
# storing translations
test "simple store_translations: stores translations, ... no, really :-)" do
I18n.backend.store_translations :'en', :foo => 'bar'
assert_equal Hash[:'en', {:foo => 'bar'}], translations
end
test "simple store_translations: deep_merges with existing translations" do
I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
end
test "simple store_translations: converts the given locale to a Symbol" do
I18n.backend.store_translations 'en', :foo => 'bar'
assert_equal Hash[:'en', {:foo => 'bar'}], translations
end
test "simple store_translations: converts keys to Symbols" do
I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
end
# reloading translations
test "simple reload_translations: unloads translations" do
I18n.backend.reload!
assert_nil translations
end
test "simple reload_translations: uninitializes the backend" do
I18n.backend.reload!
assert_equal I18n.backend.initialized?, false
end
end

View File

@@ -1,83 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nBackendTransliterator < Test::Unit::TestCase
def setup
I18n.backend = I18n::Backend::Simple.new
@proc = lambda { |n| n.upcase }
@hash = { :"ü" => "ue", :"ö" => "oe" }
@transliterator = I18n::Backend::Transliterator.get
end
test "transliteration rule can be a proc" do
store_translations(:xx, :i18n => {:transliterate => {:rule => @proc}})
assert_equal "HELLO", I18n.backend.transliterate(:xx, "hello")
end
test "transliteration rule can be a hash" do
store_translations(:xx, :i18n => {:transliterate => {:rule => @hash}})
assert_equal "ue", I18n.backend.transliterate(:xx, "ü")
end
test "transliteration rule must be a proc or hash" do
store_translations(:xx, :i18n => {:transliterate => {:rule => ""}})
assert_raise I18n::ArgumentError do
I18n.backend.transliterate(:xx, "ü")
end
end
test "transliterator defaults to latin => ascii when no rule is given" do
assert_equal "AEroskobing", I18n.backend.transliterate(:xx, "Ærøskøbing")
end
test "default transliterator should not modify ascii characters" do
(0..127).each do |byte|
char = [byte].pack("U")
assert_equal char, @transliterator.transliterate(char)
end
end
test "default transliterator correctly transliterates latin characters" do
# create string with range of Unicode's western characters with
# diacritics, excluding the division and multiplication signs which for
# some reason or other are floating in the middle of all the letters.
string = (0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include? c}.pack("U*")
string.split(//) do |char|
assert_match %r{^[a-zA-Z']*$}, @transliterator.transliterate(string)
end
end
test "should replace non-ASCII chars not in map with a replacement char" do
assert_equal "abc?", @transliterator.transliterate("abcſ")
end
test "can replace non-ASCII chars not in map with a custom replacement string" do
assert_equal "abc#", @transliterator.transliterate("abcſ", "#")
end
if RUBY_VERSION >= "1.9"
test "default transliterator raises errors for invalid UTF-8" do
assert_raise ArgumentError do
@transliterator.transliterate("a\x92b")
end
end
end
test "I18n.transliterate should transliterate using a default transliterator" do
assert_equal "aeo", I18n.transliterate("áèö")
end
test "I18n.transliterate should transliterate using a locale" do
store_translations(:xx, :i18n => {:transliterate => {:rule => @hash}})
assert_equal "ue", I18n.transliterate("ü", :locale => :xx)
end
test "default transliterator fails with custom rules with uncomposed input" do
char = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS
transliterator = I18n::Backend::Transliterator.get(@hash)
assert_not_equal "ue", transliterator.transliterate(char)
end
end

View File

@@ -1,33 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'i18n/core_ext/hash'
class I18nCoreExtHashInterpolationTest < Test::Unit::TestCase
test "#deep_symbolize_keys" do
hash = { 'foo' => { 'bar' => { 'baz' => 'bar' } } }
expected = { :foo => { :bar => { :baz => 'bar' } } }
assert_equal expected, hash.deep_symbolize_keys
end
test "#slice" do
hash = { :foo => 'bar', :baz => 'bar' }
expected = { :foo => 'bar' }
assert_equal expected, hash.slice(:foo)
end
test "#except" do
hash = { :foo => 'bar', :baz => 'bar' }
expected = { :foo => 'bar' }
assert_equal expected, hash.except(:baz)
end
test "#deep_merge!" do
hash = { :foo => { :bar => { :baz => 'bar' } }, :baz => 'bar' }
hash.deep_merge!(:foo => { :bar => { :baz => 'foo' } })
expected = { :foo => { :bar => { :baz => 'foo' } }, :baz => 'bar' }
assert_equal expected, hash
end
end

View File

@@ -1,100 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../')); $:.uniq!
require 'test_helper'
# thanks to Masao's String extensions these should work the same in
# Ruby 1.8 (patched) and Ruby 1.9 (native)
# some tests taken from Masao's tests
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
class I18nCoreExtStringInterpolationTest < Test::Unit::TestCase
test "String interpolates a single argument" do
assert_equal "Masao", "%s" % "Masao"
end
test "String interpolates an array argument" do
assert_equal "1 message", "%d %s" % [1, 'message']
end
test "String interpolates a hash argument w/ named placeholders" do
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh' }
end
test "String interpolates a hash argument w/ named placeholders (reverse order)" do
assert_equal "Mutoh, Masao", "%{last}, %{first}" % { :first => 'Masao', :last => 'Mutoh' }
end
test "String interpolates named placeholders with sprintf syntax" do
assert_equal "10, 43.4", "%<integer>d, %<float>.1f" % {:integer => 10, :float => 43.4}
end
test "String interpolates named placeholders with sprintf syntax, does not recurse" do
assert_equal "%<not_translated>s", "%{msg}" % { :msg => '%<not_translated>s', :not_translated => 'should not happen' }
end
test "String interpolation does not replace anything when no placeholders are given" do
assert_equal("aaa", "aaa" % {:num => 1})
assert_equal("bbb", "bbb" % [1])
end
test "String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
assert_equal("1", "%<num>d" % {:num => 1})
assert_equal("0b1", "%<num>#b" % {:num => 1})
assert_equal("foo", "%<msg>s" % {:msg => "foo"})
assert_equal("1.000000", "%<num>f" % {:num => 1.0})
assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
assert_equal("0x64", "%<num>#x" % {:num => 100.0})
assert_raise(ArgumentError) { "%<num>,d" % {:num => 100} }
assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
end
test "String interpolation old-style sprintf still works" do
assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0])
end
test "String interpolation raises an ArgumentError when the string has extra placeholders (Array)" do
assert_raise(ArgumentError) do # Ruby 1.9 msg: "too few arguments"
"%s %s" % %w(Masao)
end
end
test "String interpolation raises a KeyError when the string has extra placeholders (Hash)" do
assert_raise(KeyError) do # Ruby 1.9 msg: "key not found"
"%{first} %{last}" % { :first => 'Masao' }
end
end
test "String interpolation does not raise when passed extra values (Array)" do
assert_nothing_raised do
assert_equal "Masao", "%s" % %w(Masao Mutoh)
end
end
test "String interpolation does not raise when passed extra values (Hash)" do
assert_nothing_raised do
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' }
end
end
test "% acts as escape character in String interpolation" do
assert_equal "%{first}", "%%{first}" % { :first => 'Masao' }
assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
end
test "% can be used in Ruby's own sprintf behavior" do
assert_equal "70%", "%d%%" % 70
assert_equal "70-100%", "%d-%d%%" % [70, 100]
assert_equal "+2.30%", "%+.2f%%" % 2.3
end
def test_sprintf_mix_unformatted_and_formatted_named_placeholders
assert_equal("foo 1.000000", "%{name} %<num>f" % {:name => "foo", :num => 1.0})
end
def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders
assert_raise(ArgumentError) { "%{name} %f" % [1.0] }
assert_raise(ArgumentError) { "%{name} %f" % [1.0, 2.0] }
end
end

View File

@@ -1,207 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
require 'i18n/gettext/helpers'
include I18n::Gettext::Helpers
class I18nGettextApiTest < Test::Unit::TestCase
def setup
I18n.locale = :en
I18n.backend.store_translations :de, {
'Hi Gettext!' => 'Hallo Gettext!',
'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
"An apple" => { :one => 'Ein Apfel', :other => '%{count} Äpfel' },
:special => { "A special apple" => { :one => 'Ein spezieller Apfel', :other => '%{count} spezielle Äpfel' } },
:foo => { :bar => 'bar-de' },
'foo.bar' => 'Foo Bar'
}, :separator => '|'
end
# gettext
def test_gettext_uses_msg_as_default
assert_equal 'Hi Gettext!', _('Hi Gettext!')
end
def test_gettext_uses_msg_as_key
I18n.locale = :de
assert_equal 'Hallo Gettext!', gettext('Hi Gettext!')
assert_equal 'Hallo Gettext!', _('Hi Gettext!')
end
def test_gettext_uses_msg_containing_dots_as_default
assert_equal 'Sentence 1. Sentence 2.', gettext('Sentence 1. Sentence 2.')
assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
end
def test_gettext_uses_msg_containing_dots_as_key
I18n.locale = :de
assert_equal 'Satz 1. Satz 2.', gettext('Sentence 1. Sentence 2.')
assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
end
# sgettext
def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
assert_equal 'bar', sgettext('foo|bar')
assert_equal 'bar', s_('foo|bar')
end
def test_sgettext_looks_up_a_scoped_translation
I18n.locale = :de
assert_equal 'bar-de', sgettext('foo|bar')
assert_equal 'bar-de', s_('foo|bar')
end
def test_sgettext_ignores_dots
I18n.locale = :de
assert_equal 'Foo Bar', sgettext('foo.bar')
assert_equal 'Foo Bar', s_('foo.bar')
end
# pgettext
def test_pgettext_defaults_to_msgid
assert_equal 'bar', pgettext('foo', 'bar')
assert_equal 'bar', p_('foo', 'bar')
end
def test_pgettext_looks_up_a_scoped_translation
I18n.locale = :de
assert_equal 'bar-de', pgettext('foo', 'bar')
assert_equal 'bar-de', p_('foo', 'bar')
end
# ngettext
def test_ngettext_looks_up_msg_id_as_default_singular
assert_equal 'An apple', ngettext('An apple', '%{count} apples', 1)
assert_equal 'An apple', n_('An apple', '%{count} apples', 1)
end
def test_ngettext_looks_up_msg_id_plural_as_default_plural
assert_equal '2 apples', ngettext('An apple', '%{count} apples', 2)
assert_equal '2 apples', n_('An apple', '%{count} apples', 2)
end
def test_ngettext_looks_up_a_singular
I18n.locale = :de
assert_equal 'Ein Apfel', ngettext('An apple', '%{count} apples', 1)
assert_equal 'Ein Apfel', n_('An apple', '%{count} apples', 1)
end
def test_ngettext_looks_up_a_plural
I18n.locale = :de
assert_equal '2 Äpfel', ngettext('An apple', '%{count} apples', 2)
assert_equal '2 Äpfel', n_('An apple', '%{count} apples', 2)
end
def test_ngettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
assert_equal 'An apple', ngettext(['An apple', '%{count} apples'], 1)
assert_equal 'An apple', n_(['An apple', '%{count} apples'], 1)
end
def test_ngettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
assert_equal '2 apples', ngettext(['An apple', '%{count} apples'], 2)
assert_equal '2 apples', n_(['An apple', '%{count} apples'], 2)
end
def test_ngettext_looks_up_a_singular_with_alternative_syntax
I18n.locale = :de
assert_equal 'Ein Apfel', ngettext(['An apple', '%{count} apples'], 1)
assert_equal 'Ein Apfel', n_(['An apple', '%{count} apples'], 1)
end
def test_ngettext_looks_up_a_plural_with_alternative_syntax
I18n.locale = :de
assert_equal '2 Äpfel', ngettext(['An apple', '%{count} apples'], 2)
assert_equal '2 Äpfel', n_(['An apple', '%{count} apples'], 2)
end
# nsgettext
def test_nsgettext_looks_up_msg_id_as_default_singular
assert_equal 'A special apple', nsgettext('special|A special apple', '%{count} special apples', 1)
assert_equal 'A special apple', ns_('special|A special apple', '%{count} special apples', 1)
end
def test_nsgettext_looks_up_msg_id_plural_as_default_plural
assert_equal '2 special apples', nsgettext('special|A special apple', '%{count} special apples', 2)
assert_equal '2 special apples', ns_('special|A special apple', '%{count} special apples', 2)
end
def test_nsgettext_looks_up_a_singular
I18n.locale = :de
assert_equal 'Ein spezieller Apfel', nsgettext('special|A special apple', '%{count} special apples', 1)
assert_equal 'Ein spezieller Apfel', ns_('special|A special apple', '%{count} special apples', 1)
end
def test_nsgettext_looks_up_a_plural
I18n.locale = :de
assert_equal '2 spezielle Äpfel', nsgettext('special|A special apple', '%{count} special apples', 2)
assert_equal '2 spezielle Äpfel', ns_('special|A special apple', '%{count} special apples', 2)
end
def test_nsgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
assert_equal 'A special apple', nsgettext(['special|A special apple', '%{count} special apples'], 1)
assert_equal 'A special apple', ns_(['special|A special apple', '%{count} special apples'], 1)
end
def test_nsgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
assert_equal '2 special apples', nsgettext(['special|A special apple', '%{count} special apples'], 2)
assert_equal '2 special apples', ns_(['special|A special apple', '%{count} special apples'], 2)
end
def test_nsgettext_looks_up_a_singular_with_alternative_syntax
I18n.locale = :de
assert_equal 'Ein spezieller Apfel', nsgettext(['special|A special apple', '%{count} special apples'], 1)
assert_equal 'Ein spezieller Apfel', ns_(['special|A special apple', '%{count} special apples'], 1)
end
def test_nsgettext_looks_up_a_plural_with_alternative_syntax
I18n.locale = :de
assert_equal '2 spezielle Äpfel', nsgettext(['special|A special apple', '%{count} special apples'], 2)
assert_equal '2 spezielle Äpfel', ns_(['special|A special apple', '%{count} special apples'], 2)
end
# npgettext
def test_npgettext_looks_up_msg_id_as_default_singular
assert_equal 'A special apple', npgettext('special', 'A special apple', '%{count} special apples', 1)
assert_equal 'A special apple', np_('special', 'A special apple', '%{count} special apples', 1)
end
def test_npgettext_looks_up_msg_id_plural_as_default_plural
assert_equal '2 special apples', npgettext('special', 'A special apple', '%{count} special apples', 2)
assert_equal '2 special apples', np_('special', 'A special apple', '%{count} special apples', 2)
end
def test_npgettext_looks_up_a_singular
I18n.locale = :de
assert_equal 'Ein spezieller Apfel', npgettext('special', 'A special apple', '%{count} special apples', 1)
assert_equal 'Ein spezieller Apfel', np_('special', 'A special apple', '%{count} special apples', 1)
end
def test_npgettext_looks_up_a_plural
I18n.locale = :de
assert_equal '2 spezielle Äpfel', npgettext('special', 'A special apple', '%{count} special apples', 2)
assert_equal '2 spezielle Äpfel', np_('special', 'A special apple', '%{count} special apples', 2)
end
def test_npgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
assert_equal 'A special apple', npgettext('special', ['A special apple', '%{count} special apples'], 1)
assert_equal 'A special apple', np_('special', ['A special apple', '%{count} special apples'], 1)
end
def test_npgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
assert_equal '2 special apples', npgettext('special', ['A special apple', '%{count} special apples'], 2)
assert_equal '2 special apples', np_('special', ['A special apple', '%{count} special apples'], 2)
end
def test_npgettext_looks_up_a_singular_with_alternative_syntax
I18n.locale = :de
assert_equal 'Ein spezieller Apfel', npgettext('special', ['A special apple', '%{count} special apples'], 1)
assert_equal 'Ein spezieller Apfel', np_('special', ['A special apple', '%{count} special apples'], 1)
end
def test_npgettext_looks_up_a_plural_with_alternative_syntax
I18n.locale = :de
assert_equal '2 spezielle Äpfel', npgettext('special', ['A special apple', '%{count} special apples'], 2)
assert_equal '2 spezielle Äpfel', np_('special', ['A special apple', '%{count} special apples'], 2)
end
end

View File

@@ -1,90 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
class I18nGettextBackendTest < Test::Unit::TestCase
include I18n::Gettext::Helpers
class Backend < I18n::Backend::Simple
include I18n::Backend::Gettext
end
def setup
I18n.backend = Backend.new
I18n.locale = :en
I18n.load_path = ["#{locales_dir}/de.po"]
@old_separator, I18n.default_separator = I18n.default_separator, '|'
end
def teardown
I18n.load_path = nil
I18n.backend = nil
I18n.default_separator = @old_separator
end
def test_backend_loads_po_file
I18n.backend.send(:init_translations)
assert I18n.backend.send(:translations)[:de][:"Axis"]
end
def test_looks_up_a_translation
I18n.locale = :de
assert_equal 'Auto', gettext('car')
end
def test_uses_default_translation
assert_equal 'car', gettext('car')
end
def test_looks_up_a_namespaced_translation
I18n.locale = :de
assert_equal 'Räderzahl', sgettext('Car|Wheels count')
assert_equal 'Räderzahl', pgettext('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')
end
def test_pluralizes_entry
I18n.locale = :de
assert_equal 'Achse', ngettext('Axis', 'Axis', 1)
assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
end
def test_pluralizes_default_entry
assert_equal 'Axis', ngettext('Axis', 'Axis', 1)
assert_equal 'Axis', ngettext('Axis', 'Axis', 2)
end
def test_pluralizes_namespaced_entry
I18n.locale = :de
assert_equal 'Rad', nsgettext('Car|wheel', 'wheels', 1)
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)
end
def test_pluralizes_namespaced_default_entry
assert_equal 'wheel', nsgettext('Car|wheel', 'wheels', 1)
assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
assert_equal 'wheels', npgettext('Car', 'wheel', 'wheels', 2)
end
def test_pluralizes_namespaced_entry_with_alternative_syntax
I18n.locale = :de
assert_equal 'Rad', nsgettext(['Car|wheel', 'wheels'], 1)
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)
end
def test_ngettextpluralizes_entry_with_dots
I18n.locale = :de
assert_equal 'Auf 1 Achse.', n_("On %{count} wheel.", "On %{count} wheels.", 1)
assert_equal 'Auf 2 Achsen.', n_("On %{count} wheel.", "On %{count} wheels.", 2)
end
end

View File

@@ -1,97 +0,0 @@
# encoding: utf-8
$:.unshift File.expand_path(File.dirname(__FILE__) + '/')
require 'test_helper'
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', 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, 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
assert_raise(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
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 'missing interpolation argument in "%{bar}" ({:baz=>"baz"} given)', 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.backend.store_translations 'de', :bar => nil
I18n.backend.translate 'de', :foo, :scope => :bar
end
def force_invalid_pluralization_data
I18n.backend.store_translations 'de', :foo => [:bar]
I18n.backend.translate 'de', :foo, :count => 1
end
def force_missing_interpolation_argument
I18n.backend.store_translations 'de', :foo => "%{bar}"
I18n.backend.translate 'de', :foo, :baz => 'baz'
end
def force_reserved_interpolation_key
I18n.backend.store_translations 'de', :foo => "%{scope}"
I18n.backend.translate 'de', :foo, :baz => 'baz'
end
end

View File

@@ -1,23 +0,0 @@
# encoding: utf-8
$:.unshift File.expand_path(File.dirname(__FILE__) + '/')
require 'test_helper'
class I18nLoadPathTest < Test::Unit::TestCase
# include Tests::Backend::Simple::Setup::Base
def setup
I18n.locale = :en
I18n.backend = I18n::Backend::Simple.new
store_translations(:en, :foo => {:bar => 'bar', :baz => 'baz'})
end
def test_nested_load_paths_do_not_break_locale_loading
I18n.load_path = [[locales_dir + '/en.yml']]
assert_equal "baz", I18n.t(:'foo.bar')
end
def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
assert_equal "baz", I18n.t(:'foo.bar')
end
end

View File

@@ -1,244 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__))); $:.uniq!
require 'test_helper'
class I18nTest < Test::Unit::TestCase
def setup
I18n.backend.store_translations :'en', {
:currency => {
:format => {
:separator => '.',
:delimiter => ',',
}
}
}
end
def test_uses_simple_backend_set_by_default
assert I18n.backend.is_a?(I18n::Backend::Simple)
end
def test_can_set_backend
assert_nothing_raised { I18n.backend = self }
assert_equal self, I18n.backend
ensure
I18n.backend = I18n::Backend::Simple.new
end
def test_uses_en_us_as_default_locale_by_default
assert_equal :en, I18n.default_locale
end
def test_can_set_default_locale
assert_nothing_raised { I18n.default_locale = 'de' }
assert_equal :de, I18n.default_locale
ensure
I18n.default_locale = :en
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' }
assert_equal :de, I18n.locale
assert_equal :de, Thread.current[:i18n_config].locale
I18n.locale = :en
end
def test_can_set_i18n_config
I18n.config = self
assert_equal self, I18n.config
assert_equal self, Thread.current[:i18n_config]
ensure
I18n.config = ::I18n::Config.new
end
def test_locale_is_not_shared_between_configurations
a = I18n::Config.new
b = I18n::Config.new
a.locale = :fr
b.locale = :es
assert_equal :fr, a.locale
assert_equal :es, b.locale
assert_equal :en, I18n.locale
end
def test_other_options_are_shared_between_configurations
a = I18n::Config.new
b = I18n::Config.new
a.default_locale = :fr
b.default_locale = :es
assert_equal :es, a.default_locale
assert_equal :es, b.default_locale
assert_equal :es, I18n.default_locale
ensure
I18n.default_locale = :en
end
def test_defaults_to_dot_as_separator
assert_equal '.', I18n.default_separator
end
def test_can_set_default_separator
assert_nothing_raised { I18n.default_separator = "\001" }
ensure
I18n.default_separator = '.' # revert it
end
def test_normalize_keys
assert_equal [:en, :foo, :bar], I18n.normalize_keys(:en, :bar, :foo)
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz.buz', :'foo.bar')
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, 'baz.buz', 'foo.bar')
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, %w(baz buz), %w(foo bar))
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, [:baz, :buz], [:foo, :bar])
end
def test_normalize_keys_should_not_attempt_to_sym_on_empty_string
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz.buz', :'foo..bar')
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz.buz', :'foo......bar')
end
def test_uses_passed_separator_to_normalize_keys
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.normalize_keys(:en, :'baz|buz', :'foo|bar', '|')
end
def test_can_set_exception_handler
assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
ensure
I18n.exception_handler = :default_exception_handler
end
with_mocha do
def test_uses_custom_exception_handler
I18n.exception_handler = :custom_exception_handler
I18n.expects(:custom_exception_handler)
I18n.translate :bogus
ensure
I18n.exception_handler = :default_exception_handler # revert it
end
def test_delegates_translate_to_backend
I18n.backend.expects(:translate).with('de', :foo, {})
I18n.translate :foo, :locale => 'de'
end
def test_delegates_localize_to_backend
I18n.backend.expects(:localize).with('de', :whatever, :default, {})
I18n.localize :whatever, :locale => 'de'
end
def test_translate_given_no_locale_uses_i18n_locale
I18n.backend.expects(:translate).with(:en, :foo, {})
I18n.translate :foo
end
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 => %w(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
# with_mocha do
# def test_translate_with_options_using_scope_works
# I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
# I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
# locale.t :precision
# end
# end
# end
# def test_translate_given_no_args_raises_missing_translation_data
# assert_equal "translation missing: en, no key", I18n.t
# end
def test_translate_given_a_bogus_key_raises_missing_translation_data
assert_equal "translation missing: en, bogus", I18n.t(:bogus)
end
def test_localize_nil_raises_argument_error
assert_raise(I18n::ArgumentError) { I18n.l nil }
end
def test_localize_object_raises_argument_error
assert_raise(I18n::ArgumentError) { I18n.l Object.new }
end
def test_proc_exception_handler
I18n.exception_handler = Proc.new { |exception, locale, key, options|
"No exception here! [Proc handler]"
}
assert_equal "No exception here! [Proc handler]", I18n.translate(:test_proc_handler)
ensure
I18n.exception_handler = :default_exception_handler
end
def test_class_exception_handler
I18n.exception_handler = Class.new do
def call(exception, locale, key, options)
"No exception here! [Class handler]"
end
end.new
assert_equal "No exception here! [Class handler]", I18n.translate(:test_class_handler)
ensure
I18n.exception_handler = :default_exception_handler
end
test "I18n.with_locale" do
store_translations(:en, :foo => 'Foo in :en')
store_translations(:de, :foo => 'Foo in :de')
store_translations(:pl, :foo => 'Foo in :pl')
I18n.with_locale do
assert_equal I18n.default_locale, I18n.locale
assert_equal 'Foo in :en', I18n.t(:foo)
end
I18n.with_locale(:de) do
assert_equal :de, I18n.locale
assert_equal 'Foo in :de', I18n.t(:foo)
end
I18n.with_locale(:pl) do
assert_equal :pl, I18n.locale
assert_equal 'Foo in :pl', I18n.t(:foo)
end
I18n.with_locale(:en) do
assert_equal :en, I18n.locale
assert_equal 'Foo in :en', I18n.t(:foo)
end
assert_equal I18n.default_locale, I18n.locale
end
test "whether I18n.with_locale reset the locale in case of errors" do
assert_raise(I18n::ArgumentError) do
I18n.with_locale(:pl) do
raise I18n::ArgumentError
end
end
assert_equal I18n.default_locale, I18n.locale
end
end

View File

@@ -1,126 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../')); $:.uniq!
require 'test_helper'
include I18n::Locale
class I18nFallbacksDefaultsTest < Test::Unit::TestCase
def teardown
I18n.default_locale = :en
end
test "defaults reflect the I18n.default_locale if no default has been set manually" do
I18n.default_locale = :'en-US'
fallbacks = Fallbacks.new
assert_equal [:'en-US', :en], fallbacks.defaults
end
test "defaults reflect a manually passed default locale if any" do
fallbacks = Fallbacks.new(:'fi-FI')
assert_equal [:'fi-FI', :fi], fallbacks.defaults
I18n.default_locale = :'de-DE'
assert_equal [:'fi-FI', :fi], fallbacks.defaults
end
test "defaults allows to set multiple defaults" do
fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
assert_equal [:'fi-FI', :fi, :'se-FI', :se], fallbacks.defaults
end
end
class I18nFallbacksComputationTest < Test::Unit::TestCase
def setup
@fallbacks = Fallbacks.new(:'en-US')
end
test "with no mappings defined it returns [:es, :en-US] for :es" do
assert_equal [:es, :"en-US", :en], @fallbacks[:es]
end
test "with no mappings defined it returns [:es-ES, :es, :en-US] for :es-ES" do
assert_equal [:"es-ES", :es, :"en-US", :en], @fallbacks[:"es-ES"]
end
test "with no mappings defined it returns [:es-MX, :es, :en-US] for :es-MX" do
assert_equal [:"es-MX", :es, :"en-US", :en], @fallbacks[:"es-MX"]
end
test "with no mappings defined it returns [:es-Latn-ES, :es-Latn, :es, :en-US] for :es-Latn-ES" do
assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en], @fallbacks[:'es-Latn-ES']
end
test "with no mappings defined it returns [:en, :en-US] for :en" do
assert_equal [:en, :"en-US"], @fallbacks[:en]
end
test "with no mappings defined it returns [:en-US, :en] for :en-US (special case: locale == default)" do
assert_equal [:"en-US", :en], @fallbacks[:"en-US"]
end
# Most people who speak Catalan also live in Spain, so it is safe to assume
# that they also speak Spanish as spoken in Spain.
test "with a Catalan mapping defined it returns [:ca, :es-ES, :es, :en-US] for :ca" do
@fallbacks.map(:ca => :"es-ES")
assert_equal [:ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:ca]
end
test "with a Catalan mapping defined it returns [:ca-ES, :ca, :es-ES, :es, :en-US] for :ca-ES" do
@fallbacks.map(:ca => :"es-ES")
assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:"ca-ES"]
end
# People who speak Arabic as spoken in Palestine often times also speak
# Hebrew as spoken in Israel. However it is in no way safe to assume that
# everybody who speaks Arabic also speaks Hebrew.
test "with a Hebrew mapping defined it returns [:ar, :en-US] for :ar" do
@fallbacks.map(:"ar-PS" => :"he-IL")
assert_equal [:ar, :"en-US", :en], @fallbacks[:ar]
end
test "with a Hebrew mapping defined it returns [:ar-EG, :ar, :en-US] for :ar-EG" do
@fallbacks.map(:"ar-PS" => :"he-IL")
assert_equal [:"ar-EG", :ar, :"en-US", :en], @fallbacks[:"ar-EG"]
end
test "with a Hebrew mapping defined it returns [:ar-PS, :ar, :he-IL, :he, :en-US] for :ar-PS" do
@fallbacks.map(:"ar-PS" => :"he-IL")
assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en], @fallbacks[:"ar-PS"]
end
# Sami people live in several scandinavian countries. In Finnland many people
# know Swedish and Finnish. Thus, it can be assumed that Sami living in
# Finnland also speak Swedish and Finnish.
test "with a Sami mapping defined it returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US] for :sms-FI" do
@fallbacks.map(:sms => [:"se-FI", :"fi-FI"])
assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en], @fallbacks[:"sms-FI"]
end
# Austrian people understand German as spoken in Germany
test "with a German mapping defined it returns [:de, :en-US] for de" do
@fallbacks.map(:"de-AT" => :"de-DE")
assert_equal [:de, :"en-US", :en], @fallbacks[:"de"]
end
test "with a German mapping defined it returns [:de-DE, :de, :en-US] for de-DE" do
@fallbacks.map(:"de-AT" => :"de-DE")
assert_equal [:"de-DE", :de, :"en-US", :en], @fallbacks[:"de-DE"]
end
test "with a German mapping defined it returns [:de-AT, :de, :de-DE, :en-US] for de-AT" do
@fallbacks.map(:"de-AT" => :"de-DE")
assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en], @fallbacks[:"de-AT"]
end
# Mapping :de => :en, :he => :en
test "with a mapping :de => :en, :he => :en defined it returns [:de, :en] for :de" do
assert_equal [:de, :"en-US", :en], @fallbacks[:de]
end
test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
assert_equal [:he, :"en-US", :en], @fallbacks[:he]
end
end

View File

@@ -1,143 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../')); $:.uniq!
require 'test_helper'
class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase
include I18n::Locale
test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
assert_equal ['de', nil, nil, nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de')
end
test "Rfc4646::Parser given a valid tag 'de-DE' returns an array of subtags" do
assert_equal ['de', nil, 'DE', nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de-DE')
end
test "Rfc4646::Parser given a valid lowercase tag 'de-latn-de-variant-x-phonebk' returns an array of subtags" do
assert_equal ['de', 'latn', 'de', 'variant', nil, 'x-phonebk', nil], Tag::Rfc4646::Parser.match('de-latn-de-variant-x-phonebk')
end
test "Rfc4646::Parser given a valid uppercase tag 'DE-LATN-DE-VARIANT-X-PHONEBK' returns an array of subtags" do
assert_equal ['DE', 'LATN', 'DE', 'VARIANT', nil, 'X-PHONEBK', nil], Tag::Rfc4646::Parser.match('DE-LATN-DE-VARIANT-X-PHONEBK')
end
test "Rfc4646::Parser given an invalid tag 'a-DE' it returns false" do
assert_equal false, Tag::Rfc4646::Parser.match('a-DE')
end
test "Rfc4646::Parser given an invalid tag 'de-419-DE' it returns false" do
assert_equal false, Tag::Rfc4646::Parser.match('de-419-DE')
end
end
# Tag for the locale 'de-Latn-DE-Variant-a-ext-x-phonebk-i-klingon'
class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
include I18n::Locale
def setup
subtags = %w(de Latn DE variant a-ext x-phonebk i-klingon)
@tag = Tag::Rfc4646.new *subtags
end
test "returns 'de' as the language subtag in lowercase" do
assert_equal 'de', @tag.language
end
test "returns 'Latn' as the script subtag in titlecase" do
assert_equal 'Latn', @tag.script
end
test "returns 'DE' as the region subtag in uppercase" do
assert_equal 'DE', @tag.region
end
test "returns 'variant' as the variant subtag in lowercase" do
assert_equal 'variant', @tag.variant
end
test "returns 'a-ext' as the extension subtag" do
assert_equal 'a-ext', @tag.extension
end
test "returns 'x-phonebk' as the privateuse subtag" do
assert_equal 'x-phonebk', @tag.privateuse
end
test "returns 'i-klingon' as the grandfathered subtag" do
assert_equal 'i-klingon', @tag.grandfathered
end
test "returns a formatted tag string from #to_s" do
assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon', @tag.to_s
end
test "returns an array containing the formatted subtags from #to_a" do
assert_equal %w(de Latn DE variant a-ext x-phonebk i-klingon), @tag.to_a
end
end
# Tag inheritance
class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
test "#parent returns 'de-Latn-DE-variant-a-ext-x-phonebk' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk', tag.parent.to_s
end
test "#parent returns 'de-Latn-DE-variant-a-ext' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk'" do
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk)
assert_equal 'de-Latn-DE-variant-a-ext', tag.parent.to_s
end
test "#parent returns 'de-Latn-DE-variant' as the parent of 'de-Latn-DE-variant-a-ext'" do
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext)
assert_equal 'de-Latn-DE-variant', tag.parent.to_s
end
test "#parent returns 'de-Latn-DE' as the parent of 'de-Latn-DE-variant'" do
tag = Tag::Rfc4646.new *%w(de Latn DE variant)
assert_equal 'de-Latn-DE', tag.parent.to_s
end
test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
tag = Tag::Rfc4646.new *%w(de Latn DE)
assert_equal 'de-Latn', tag.parent.to_s
end
test "#parent returns 'de' as the parent of 'de-Latn'" do
tag = Tag::Rfc4646.new *%w(de Latn)
assert_equal 'de', tag.parent.to_s
end
# TODO RFC4647 says: "If no language tag matches the request, the "default" value is returned."
# where should we set the default language?
# test "#parent returns '' as the parent of 'de'" do
# tag = Tag::Rfc4646.new *%w(de)
# assert_equal '', tag.parent.to_s
# end
test "#parent returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
de-Latn-DE-variant-a-ext-x-phonebk
de-Latn-DE-variant-a-ext
de-Latn-DE-variant
de-Latn-DE
de-Latn
de)
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
end
test "returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
de-Latn-DE-variant-a-ext-x-phonebk
de-Latn-DE-variant-a-ext
de-Latn-DE-variant
de-Latn-DE
de-Latn
de)
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
end
end

View File

@@ -1,33 +0,0 @@
# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../')); $:.uniq!
require 'test_helper'
class I18nLocaleTagSimpleTest < Test::Unit::TestCase
include I18n::Locale
test "returns 'de' as the language subtag in lowercase" do
assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').subtags
end
test "returns a formatted tag string from #to_s" do
assert_equal 'de-Latn-DE', Tag::Simple.new('de-Latn-DE').to_s
end
test "returns an array containing the formatted subtags from #to_a" do
assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').to_a
end
# Tag inheritance
test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
assert_equal 'de-Latn', Tag::Simple.new('de-Latn-DE').parent.to_s
end
test "#parent returns 'de' as the parent of 'de-Latn'" do
assert_equal 'de', Tag::Simple.new('de-Latn').parent.to_s
end
test "#self_and_parents returns an array of 3 tags for 'de-Latn-DE'" do
assert_equal %w(de-Latn-DE de-Latn de), Tag::Simple.new('de-Latn-DE').self_and_parents.map { |tag| tag.to_s}
end
end

View File

@@ -1,152 +0,0 @@
de:
calendars:
gregorian:
days:
format:
abbreviated:
fri: Fr.
mon: Mo.
sat: Sa.
sun: So.
thu: Do.
tue: Di.
wed: Mi.
narrow: :"calendars.gregorian.days.stand-alone.narrow"
wide:
fri: Freitag
mon: Montag
sat: Samstag
sun: Sonntag
thu: Donnerstag
tue: Dienstag
wed: Mittwoch
stand-alone:
abbreviated: :"calendars.gregorian.days.format.abbreviated"
narrow:
fri: F
mon: M
sat: S
sun: S
thu: D
tue: D
wed: M
wide: :"calendars.gregorian.days.format.wide"
fields:
day: Tag
dayperiod: Tageshälfte
era: Epoche
hour: Stunde
minute: Minute
month: Monat
second: Sekunde
week: Woche
weekday: Wochentag
year: Jahr
zone: Zone
formats:
date:
default: :"calendars.gregorian.formats.date.medium"
full:
pattern: "EEEE, d. MMMM y"
long:
pattern: "d. MMMM y"
medium:
pattern: dd.MM.yyyy
short:
pattern: dd.MM.yy
datetime:
default: :"calendars.gregorian.formats.datetime.medium"
full:
pattern: "%{date} %{time}"
long:
pattern: "%{date} %{time}"
medium:
pattern: "%{date} %{time}"
short:
pattern: "%{date} %{time}"
time:
default: :"calendars.gregorian.formats.time.medium"
full:
pattern: "HH:mm:ss zzzz"
long:
pattern: "HH:mm:ss z"
medium:
pattern: "HH:mm:ss"
short:
pattern: "HH:mm"
months:
format:
abbreviated:
1: Jan
10: Okt
11: Nov
12: Dez
2: Feb
3: Mär
4: Apr
5: Mai
6: Jun
7: Jul
8: Aug
9: Sep
narrow: :"calendars.gregorian.months.stand-alone.narrow"
wide:
1: Januar
10: Oktober
11: November
12: Dezember
2: Februar
3: März
4: April
5: Mai
6: Juni
7: Juli
8: August
9: September
stand-alone:
abbreviated:
10: Okt
11: Nov
12: Dez
3: Mär
7: Jul
8: Aug
9: Sep
narrow:
1: J
10: O
11: N
12: D
2: F
3: M
4: A
5: M
6: J
7: J
8: A
9: S
wide: :"calendars.gregorian.months.format.wide"
periods:
am: vorm.
pm: nachm.
quarters:
format:
abbreviated:
1: Q1
2: Q2
3: Q3
4: Q4
narrow: :"calendars.gregorian.quarters.stand-alone.narrow"
wide:
1: "1. Quartal"
2: "2. Quartal"
3: "3. Quartal"
4: "4. Quartal"
stand-alone:
abbreviated: :"calendars.gregorian.quarters.format.abbreviated"
narrow:
1: 1
2: 2
3: 3
4: 4
wide: :"calendars.gregorian.quarters.format.wide"

View File

@@ -1,8 +0,0 @@
de:
currencies:
EUR:
one: Euro
other: Euro
IEP:
one: "Irisches Pfund"
other: "Irische Pfund"

View File

@@ -1,31 +0,0 @@
de:
numbers:
formats:
currency:
patterns:
default: "#,##0.00 ¤"
unit:
one: "{0} {1}"
other: "{0} {1}"
decimal:
patterns:
default: "#,##0.###"
percent:
patterns:
default: "#,##0 %"
scientific:
patterns:
default: "#E0"
symbols:
decimal: ","
exponential: E
group: "."
infinity:
list: ;
minus_sign: "-"
nan: NaN
native_zero_digit: 0
pattern_digit: "#"
per_mille:
percent_sign: "%"
plus_sign: +

View File

@@ -1,72 +0,0 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: version 0.0.1\n"
"POT-Creation-Date: 2009-02-26 19:50+0100\n"
"PO-Revision-Date: 2009-02-18 14:53+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
# #: app/helpers/translation_helper.rb:3
# msgid "%{relative_time} ago"
# msgstr "vor %{relative_time}"
#: app/views/cars/show.html.erb:5
msgid "Axis"
msgid_plural "Axis"
msgstr[0] "Achse"
msgstr[1] "Achsen"
#: app/controllers/cars_controller.rb:47
msgid "Car was successfully created."
msgstr "Auto wurde erfolgreich gespeichert"
#: app/controllers/cars_controller.rb:64
msgid "Car was successfully updated."
msgstr "Auto wurde erfolgreich aktualisiert"
#: app/views/cars/show.html.erb:1 locale/model_attributes.rb:3
msgid "Car|Model"
msgstr "Modell"
#: app/views/cars/show.html.erb:3 locale/model_attributes.rb:4
msgid "Car|Wheels count"
msgstr "Räderzahl"
#: app/views/cars/show.html.erb:7
msgid "Created"
msgstr "Erstellt"
#: app/views/cars/show.html.erb:9
msgid "Month"
msgstr "Monat"
#: locale/model_attributes.rb:2
msgid "car"
msgstr "Auto"
#: locale/testlog_phrases.rb:2
msgid "this is a dynamic translation which was found thorugh gettext_test_log!"
msgstr ""
"Dies ist eine dynamische Übersetzung, die durch gettext_test_log "
"gefunden wurde!"
#: app/views/cars/nowhere_really
msgid "Car|wheel"
msgid_plural "Car|wheels"
msgstr[0] "Rad"
msgstr[1] "Räder"
msgid "On %{count} wheel."
msgid_plural "On %{count} wheels."
msgstr[0] "Auf %{count} Achse."
msgstr[1] "Auf %{count} Achsen."

View File

@@ -1,3 +0,0 @@
# encoding: utf-8
{ :en => { :fuh => { :bah => "bas" } } }

View File

@@ -1,3 +0,0 @@
en:
foo:
bar: baz

View File

@@ -1,113 +0,0 @@
# encoding: utf-8
{
:af => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:am => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:ar => { :i18n => { :plural => { :keys => [:zero, :one, :two, :few, :many, :other], :rule => lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : [3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99].include?(n % 100) ? :many : :other } } } },
:az => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:be => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
:bg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:bh => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:bn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:bo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:bs => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
:ca => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:cs => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
:cy => { :i18n => { :plural => { :keys => [:one, :two, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } } },
:da => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:de => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:dz => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:el => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:en => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:eo => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:es => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:et => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:eu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:fa => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
: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 } } } },
: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 } } } },
:gl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:gu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:guw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:ha => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:he => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:hi => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:hr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
:hu => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:id => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:is => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:it => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:iw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:ja => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:jv => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:ka => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:km => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:kn => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:ko => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:ku => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:lb => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:ln => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:lt => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n % 10 == 1 && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :one : [2, 3, 4, 5, 6, 7, 8, 9].include?(n % 10) && ![11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :few : :other } } } },
:lv => { :i18n => { :plural => { :keys => [:zero, :one, :other], :rule => lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } } },
:mg => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:mk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n % 10 == 1 ? :one : :other } } } },
:ml => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:mn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:mo => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
:mr => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:ms => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:mt => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 || [2, 3, 4, 5, 6, 7, 8, 9, 10].include?(n % 100) ? :few : [11, 12, 13, 14, 15, 16, 17, 18, 19].include?(n % 100) ? :many : :other } } } },
:my => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:nah => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:nb => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:ne => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:nl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:nn => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:no => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:nso => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:om => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
: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 } } } },
: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 } } } },
:ro => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } } },
:ru => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
:se => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
:sh => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
:sk => { :i18n => { :plural => { :keys => [:one, :few, :other], :rule => lambda { |n| n == 1 ? :one : [2, 3, 4].include?(n) ? :few : :other } } } },
:sl => { :i18n => { :plural => { :keys => [:one, :two, :few, :other], :rule => lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : [3, 4].include?(n % 100) ? :few : :other } } } },
:sma => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
:smi => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
:smj => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
:smn => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
:sms => { :i18n => { :plural => { :keys => [:one, :two, :other], :rule => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } } },
:so => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:sq => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:sr => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
:sv => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:sw => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:ta => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:te => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:th => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:ti => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:tk => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:tl => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:to => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:tr => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:uk => { :i18n => { :plural => { :keys => [:one, :few, :many, :other], :rule => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ? :few : n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ? :many : :other } } } },
:ur => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } },
:vi => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:wa => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| [0, 1].include?(n) ? :one : :other } } } },
:yo => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:zh => { :i18n => { :plural => { :keys => [:other], :rule => lambda { |n| :other } } } },
:zu => { :i18n => { :plural => { :keys => [:one, :other], :rule => lambda { |n| n == 1 ? :one : :other } } } }
}

View File

@@ -1,85 +0,0 @@
# encoding: utf-8
$KCODE = 'u' unless RUBY_VERSION >= '1.9'
$:.unshift File.expand_path("../lib", File.dirname(__FILE__))
$:.unshift File.expand_path(File.dirname(__FILE__))
$:.uniq!
require 'rubygems'
require 'test/unit'
require 'time'
require 'yaml'
require 'i18n'
require 'test_setup_requirements'
setup_mocha
class Test::Unit::TestCase
def self.test(name, &block)
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
defined = instance_method(test_name) rescue false
raise "#{test_name} is already defined in #{self}" if defined
if block_given?
define_method(test_name, &block)
else
define_method(test_name) do
flunk "No implementation provided for #{name}"
end
end
end
def self.with_mocha
yield if Object.respond_to?(:expects)
end
def teardown
I18n.locale = nil
I18n.default_locale = :en
I18n.load_path = []
I18n.available_locales = nil
I18n.backend = nil
end
def translations
I18n.backend.instance_variable_get(:@translations)
end
def store_translations(*args)
data = args.pop
locale = args.pop || :en
I18n.backend.store_translations(locale, data)
end
def locales_dir
File.dirname(__FILE__) + '/test_data/locales'
end
def euc_jp(string)
string.encode!(Encoding::EUC_JP)
end
def can_store_procs?
I18n.backend.class != I18n::Backend::ActiveRecord or
I18n::Backend::ActiveRecord.included_modules.include?(I18n::Backend::ActiveRecord::StoreProcs)
end
def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval("$#{stream} = #{stream.upcase}")
end
result
end
end
Object.class_eval do
def meta_class
class << self; self; end
end
end unless Object.method_defined?(:meta_class)

View File

@@ -1,71 +0,0 @@
require 'optparse'
options = { :with => [] }
OptionParser.new do |o|
o.on('-w', '--with DEPENDENCIES', 'Define dependencies') do |dep|
options[:with] = dep.split(',').map { |group| group.to_sym }
end
end.parse!
options[:with].each do |dep|
case dep
when :ar23, :'activerecord-2.3'
gem 'activerecord', '~> 2.3'
when :ar3, :'activerecord-3'
gem 'activerecord', '~> 3'
end
end
# Do not load the i18n gem from libraries like active_support, we'll load it from here :)
alias :gem_for_ruby_19 :gem # for 1.9. gives a super ugly seg fault otherwise
def gem(gem_name, *version_requirements)
if gem_name =='i18n'
puts "skipping loading the i18n gem ..."
return
end
super(gem_name, *version_requirements)
end
def setup_mocha
begin
require 'mocha'
rescue LoadError
puts "skipping tests using mocha as mocha can't be found"
end
end
def setup_active_record
begin
require 'active_record'
ActiveRecord::Base.connection
true
rescue LoadError => e
puts "can't use ActiveRecord backend because: #{e.message}"
rescue ActiveRecord::ConnectionNotEstablished
require 'i18n/backend/active_record'
require 'i18n/backend/active_record/store_procs'
connect_active_record
true
end
end
def connect_active_record
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define(:version => 1) do
create_table :translations do |t|
t.string :locale
t.string :key
t.string :value
t.string :interpolations
t.boolean :is_proc, :default => false
end
end
end
def setup_rufus_tokyo
require 'rubygems'
require 'rufus/tokyo'
rescue LoadError => e
puts "can't use KeyValue backend because: #{e.message}"
end