thedarkone-i18n 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +57 -0
- data/README.textile +43 -9
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/lib/i18n.rb +87 -16
- data/lib/i18n/backend/base.rb +251 -0
- data/lib/i18n/backend/cache.rb +71 -0
- data/lib/i18n/backend/chain.rb +64 -0
- data/lib/i18n/backend/fallbacks.rb +53 -0
- data/lib/i18n/backend/fast.rb +53 -22
- data/lib/i18n/backend/fast/interpolation_compiler.rb +84 -0
- data/lib/i18n/backend/gettext.rb +65 -0
- data/lib/i18n/backend/lazy_reloading.rb +60 -0
- data/lib/i18n/backend/pluralization.rb +56 -0
- data/lib/i18n/backend/simple.rb +17 -240
- data/lib/i18n/exceptions.rb +13 -5
- data/lib/i18n/gettext.rb +25 -0
- data/lib/i18n/helpers/gettext.rb +35 -0
- data/lib/i18n/locale/fallbacks.rb +100 -0
- data/lib/i18n/locale/tag.rb +27 -0
- data/lib/i18n/locale/tag/parents.rb +24 -0
- data/lib/i18n/locale/tag/rfc4646.rb +78 -0
- data/lib/i18n/locale/tag/simple.rb +44 -0
- data/test/all.rb +5 -7
- data/test/api/basics.rb +15 -0
- data/test/api/interpolation.rb +85 -0
- data/test/api/lambda.rb +52 -0
- data/test/api/link.rb +47 -0
- data/test/api/localization/date.rb +65 -0
- data/test/api/localization/date_time.rb +63 -0
- data/test/api/localization/lambda.rb +26 -0
- data/test/api/localization/time.rb +63 -0
- data/test/api/pluralization.rb +37 -0
- data/test/api/translation.rb +51 -0
- data/test/backend/cache/cache_test.rb +57 -0
- data/test/backend/chain/api_test.rb +80 -0
- data/test/backend/chain/chain_test.rb +64 -0
- data/test/backend/fallbacks/api_test.rb +79 -0
- data/test/backend/fallbacks/fallbacks_test.rb +29 -0
- data/test/backend/fast/all.rb +5 -0
- data/test/backend/fast/api_test.rb +91 -0
- data/test/backend/fast/interpolation_compiler_test.rb +84 -0
- data/test/backend/fast/lookup_test.rb +24 -0
- data/test/backend/fast/setup.rb +22 -0
- data/test/backend/fast/translations_test.rb +89 -0
- data/test/backend/lazy_reloading/reloading_test.rb +67 -0
- data/test/backend/pluralization/api_test.rb +81 -0
- data/test/backend/pluralization/pluralization_test.rb +39 -0
- data/test/backend/simple/all.rb +5 -0
- data/test/backend/simple/api_test.rb +90 -0
- data/test/backend/simple/lookup_test.rb +24 -0
- data/test/backend/simple/setup.rb +151 -0
- data/test/backend/simple/translations_test.rb +89 -0
- data/test/fixtures/locales/de.po +61 -0
- data/test/fixtures/locales/en.rb +3 -0
- data/test/fixtures/locales/en.yml +3 -0
- data/test/fixtures/locales/plurals.rb +112 -0
- data/test/gettext/api_test.rb +78 -0
- data/test/gettext/backend_test.rb +35 -0
- data/test/i18n_exceptions_test.rb +6 -25
- data/test/i18n_load_path_test.rb +23 -0
- data/test/i18n_test.rb +56 -18
- data/test/locale/fallbacks_test.rb +128 -0
- data/test/locale/tag/rfc4646_test.rb +147 -0
- data/test/locale/tag/simple_test.rb +35 -0
- data/test/test_helper.rb +72 -0
- data/test/with_options.rb +34 -0
- metadata +109 -19
- data/i18n.gemspec +0 -31
- data/lib/i18n/backend/fast/pluralization_compiler.rb +0 -50
- data/test/backend_test.rb +0 -633
- data/test/fast_backend_test.rb +0 -34
- data/test/locale/en.rb +0 -1
- data/test/locale/en.yml +0 -3
- data/test/pluralization_compiler_test.rb +0 -35
data/test/test_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift "lib"
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'mocha'
|
8
|
+
require 'i18n'
|
9
|
+
require 'time'
|
10
|
+
require 'yaml'
|
11
|
+
|
12
|
+
require File.dirname(__FILE__) + '/with_options'
|
13
|
+
require File.dirname(__FILE__) + '/backend/simple/setup'
|
14
|
+
require File.dirname(__FILE__) + '/backend/fast/setup'
|
15
|
+
|
16
|
+
Dir[File.dirname(__FILE__) + '/api/**/*.rb'].each do |filename|
|
17
|
+
require filename
|
18
|
+
end
|
19
|
+
|
20
|
+
$KCODE = 'u' unless RUBY_VERSION >= '1.9'
|
21
|
+
|
22
|
+
class Test::Unit::TestCase
|
23
|
+
def self.test(name, &block)
|
24
|
+
define_method("test: " + name, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def euc_jp(string)
|
28
|
+
string.encode!(Encoding::EUC_JP)
|
29
|
+
end
|
30
|
+
|
31
|
+
def locales_dir
|
32
|
+
File.dirname(__FILE__) + '/fixtures/locales'
|
33
|
+
end
|
34
|
+
|
35
|
+
def backend_store_translations(*args)
|
36
|
+
I18n.backend.store_translations(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def backend_get_translations
|
40
|
+
I18n.backend.instance_variable_get :@translations
|
41
|
+
end
|
42
|
+
|
43
|
+
def date
|
44
|
+
Date.new(2008, 3, 1)
|
45
|
+
end
|
46
|
+
|
47
|
+
def morning_datetime
|
48
|
+
DateTime.new(2008, 3, 1, 6)
|
49
|
+
end
|
50
|
+
alias :datetime :morning_datetime
|
51
|
+
|
52
|
+
def evening_datetime
|
53
|
+
DateTime.new(2008, 3, 1, 18)
|
54
|
+
end
|
55
|
+
|
56
|
+
def morning_time
|
57
|
+
Time.parse('2008-03-01 6:00 UTC')
|
58
|
+
end
|
59
|
+
alias :time :morning_time
|
60
|
+
|
61
|
+
def evening_time
|
62
|
+
Time.parse('2008-03-01 18:00 UTC')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Object
|
67
|
+
def meta_class
|
68
|
+
class << self; self; end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# this is only here so we can test I18n works nicely with ActiveSupports
|
4
|
+
# with_options. Maybe we can just remove it?
|
5
|
+
|
6
|
+
class Object
|
7
|
+
def with_options(options)
|
8
|
+
yield ActiveSupport::OptionMerger.new(self, options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ActiveSupport
|
13
|
+
class OptionMerger #:nodoc:
|
14
|
+
instance_methods.each do |method|
|
15
|
+
undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(context, options)
|
19
|
+
@context, @options = context, options
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def method_missing(method, *arguments, &block)
|
24
|
+
if arguments.last.is_a?(Proc)
|
25
|
+
proc = arguments.pop
|
26
|
+
arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
|
27
|
+
else
|
28
|
+
arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
|
29
|
+
end
|
30
|
+
|
31
|
+
@context.__send__(method, *arguments, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thedarkone-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Fuchs
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2009-
|
17
|
+
date: 2009-08-19 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -24,19 +24,75 @@ executables: []
|
|
24
24
|
|
25
25
|
extensions: []
|
26
26
|
|
27
|
-
extra_rdoc_files:
|
28
|
-
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.textile
|
29
29
|
files:
|
30
|
-
-
|
31
|
-
- lib/i18n/backend/simple.rb
|
32
|
-
- lib/i18n/backend/fast.rb
|
33
|
-
- lib/i18n/backend/fast/pluralization_compiler.rb
|
34
|
-
- lib/i18n/exceptions.rb
|
35
|
-
- lib/i18n.rb
|
30
|
+
- CHANGELOG.textile
|
36
31
|
- MIT-LICENSE
|
37
32
|
- README.textile
|
33
|
+
- Rakefile
|
34
|
+
- VERSION
|
35
|
+
- lib/i18n.rb
|
36
|
+
- lib/i18n/backend/base.rb
|
37
|
+
- lib/i18n/backend/cache.rb
|
38
|
+
- lib/i18n/backend/chain.rb
|
39
|
+
- lib/i18n/backend/fallbacks.rb
|
40
|
+
- lib/i18n/backend/fast.rb
|
41
|
+
- lib/i18n/backend/fast/interpolation_compiler.rb
|
42
|
+
- lib/i18n/backend/gettext.rb
|
43
|
+
- lib/i18n/backend/lazy_reloading.rb
|
44
|
+
- lib/i18n/backend/pluralization.rb
|
45
|
+
- lib/i18n/backend/simple.rb
|
46
|
+
- lib/i18n/exceptions.rb
|
47
|
+
- lib/i18n/gettext.rb
|
48
|
+
- lib/i18n/helpers/gettext.rb
|
49
|
+
- lib/i18n/locale/fallbacks.rb
|
50
|
+
- lib/i18n/locale/tag.rb
|
51
|
+
- lib/i18n/locale/tag/parents.rb
|
52
|
+
- lib/i18n/locale/tag/rfc4646.rb
|
53
|
+
- lib/i18n/locale/tag/simple.rb
|
54
|
+
- test/all.rb
|
55
|
+
- test/api/basics.rb
|
56
|
+
- test/api/interpolation.rb
|
57
|
+
- test/api/lambda.rb
|
58
|
+
- test/api/link.rb
|
59
|
+
- test/api/localization/date.rb
|
60
|
+
- test/api/localization/date_time.rb
|
61
|
+
- test/api/localization/lambda.rb
|
62
|
+
- test/api/localization/time.rb
|
63
|
+
- test/api/pluralization.rb
|
64
|
+
- test/api/translation.rb
|
65
|
+
- test/backend/cache/cache_test.rb
|
66
|
+
- test/backend/chain/api_test.rb
|
67
|
+
- test/backend/chain/chain_test.rb
|
68
|
+
- test/backend/fallbacks/api_test.rb
|
69
|
+
- test/backend/fallbacks/fallbacks_test.rb
|
70
|
+
- test/backend/fast/all.rb
|
71
|
+
- test/backend/fast/api_test.rb
|
72
|
+
- test/backend/fast/interpolation_compiler_test.rb
|
73
|
+
- test/backend/fast/lookup_test.rb
|
74
|
+
- test/backend/fast/setup.rb
|
75
|
+
- test/backend/fast/translations_test.rb
|
76
|
+
- test/backend/lazy_reloading/reloading_test.rb
|
77
|
+
- test/backend/pluralization/api_test.rb
|
78
|
+
- test/backend/pluralization/pluralization_test.rb
|
79
|
+
- test/fixtures/locales/de.po
|
80
|
+
- test/fixtures/locales/en.rb
|
81
|
+
- test/fixtures/locales/en.yml
|
82
|
+
- test/fixtures/locales/plurals.rb
|
83
|
+
- test/gettext/api_test.rb
|
84
|
+
- test/gettext/backend_test.rb
|
85
|
+
- test/i18n_exceptions_test.rb
|
86
|
+
- test/i18n_load_path_test.rb
|
87
|
+
- test/i18n_test.rb
|
88
|
+
- test/locale/fallbacks_test.rb
|
89
|
+
- test/locale/tag/rfc4646_test.rb
|
90
|
+
- test/locale/tag/simple_test.rb
|
91
|
+
- test/test_helper.rb
|
92
|
+
- test/with_options.rb
|
38
93
|
has_rdoc: false
|
39
94
|
homepage: http://rails-i18n.org
|
95
|
+
licenses:
|
40
96
|
post_install_message:
|
41
97
|
rdoc_options: []
|
42
98
|
|
@@ -56,17 +112,51 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
112
|
version:
|
57
113
|
requirements: []
|
58
114
|
|
59
|
-
rubyforge_project:
|
60
|
-
rubygems_version: 1.
|
115
|
+
rubyforge_project: i18n
|
116
|
+
rubygems_version: 1.3.5
|
61
117
|
signing_key:
|
62
|
-
specification_version:
|
63
|
-
summary: Internationalization support for Ruby
|
118
|
+
specification_version: 3
|
119
|
+
summary: New wave Internationalization support for Ruby
|
64
120
|
test_files:
|
65
121
|
- test/all.rb
|
122
|
+
- test/api/basics.rb
|
123
|
+
- test/api/interpolation.rb
|
124
|
+
- test/api/lambda.rb
|
125
|
+
- test/api/link.rb
|
126
|
+
- test/api/localization/date.rb
|
127
|
+
- test/api/localization/date_time.rb
|
128
|
+
- test/api/localization/lambda.rb
|
129
|
+
- test/api/localization/time.rb
|
130
|
+
- test/api/pluralization.rb
|
131
|
+
- test/api/translation.rb
|
132
|
+
- test/backend/cache/cache_test.rb
|
133
|
+
- test/backend/chain/api_test.rb
|
134
|
+
- test/backend/chain/chain_test.rb
|
135
|
+
- test/backend/fallbacks/api_test.rb
|
136
|
+
- test/backend/fallbacks/fallbacks_test.rb
|
137
|
+
- test/backend/fast/all.rb
|
138
|
+
- test/backend/fast/api_test.rb
|
139
|
+
- test/backend/fast/interpolation_compiler_test.rb
|
140
|
+
- test/backend/fast/lookup_test.rb
|
141
|
+
- test/backend/fast/setup.rb
|
142
|
+
- test/backend/fast/translations_test.rb
|
143
|
+
- test/backend/lazy_reloading/reloading_test.rb
|
144
|
+
- test/backend/pluralization/api_test.rb
|
145
|
+
- test/backend/pluralization/pluralization_test.rb
|
146
|
+
- test/backend/simple/all.rb
|
147
|
+
- test/backend/simple/api_test.rb
|
148
|
+
- test/backend/simple/lookup_test.rb
|
149
|
+
- test/backend/simple/setup.rb
|
150
|
+
- test/backend/simple/translations_test.rb
|
151
|
+
- test/fixtures/locales/en.rb
|
152
|
+
- test/fixtures/locales/plurals.rb
|
153
|
+
- test/gettext/api_test.rb
|
154
|
+
- test/gettext/backend_test.rb
|
66
155
|
- test/i18n_exceptions_test.rb
|
156
|
+
- test/i18n_load_path_test.rb
|
67
157
|
- test/i18n_test.rb
|
68
|
-
- test/locale/
|
69
|
-
- test/locale/
|
70
|
-
- test/
|
71
|
-
- test/
|
72
|
-
- test/
|
158
|
+
- test/locale/fallbacks_test.rb
|
159
|
+
- test/locale/tag/rfc4646_test.rb
|
160
|
+
- test/locale/tag/simple_test.rb
|
161
|
+
- test/test_helper.rb
|
162
|
+
- test/with_options.rb
|
data/i18n.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "i18n"
|
3
|
-
s.version = "0.1.4"
|
4
|
-
s.date = "2009-01-09"
|
5
|
-
s.summary = "Internationalization support for Ruby"
|
6
|
-
s.email = "rails-i18n@googlegroups.com"
|
7
|
-
s.homepage = "http://rails-i18n.org"
|
8
|
-
s.description = "Add Internationalization support to your Ruby application."
|
9
|
-
s.has_rdoc = false
|
10
|
-
s.authors = ['Sven Fuchs', 'Joshua Harvey', 'Matt Aimonetti', 'Stephan Soller', 'Saimon Moore', 'thedarkone2@gmail.com']
|
11
|
-
s.files = [
|
12
|
-
'i18n.gemspec',
|
13
|
-
'lib/i18n/backend/simple.rb',
|
14
|
-
'lib/i18n/backend/fast.rb',
|
15
|
-
'lib/i18n/backend/fast/pluralization_compiler.rb',
|
16
|
-
'lib/i18n/exceptions.rb',
|
17
|
-
'lib/i18n.rb',
|
18
|
-
'MIT-LICENSE',
|
19
|
-
'README.textile'
|
20
|
-
]
|
21
|
-
s.test_files = [
|
22
|
-
'test/all.rb',
|
23
|
-
'test/i18n_exceptions_test.rb',
|
24
|
-
'test/i18n_test.rb',
|
25
|
-
'test/locale/en.rb',
|
26
|
-
'test/locale/en.yml',
|
27
|
-
'test/backend_test.rb',
|
28
|
-
'test/fast_backend_test.rb',
|
29
|
-
'test/pluralization_compiler_test.rb'
|
30
|
-
]
|
31
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module I18n
|
2
|
-
module Backend
|
3
|
-
class Fast < Simple
|
4
|
-
module PluralizationCompiler
|
5
|
-
extend self
|
6
|
-
|
7
|
-
def compile_if_an_interpolation(string)
|
8
|
-
if interpolated_str?(string)
|
9
|
-
string.instance_eval <<-RUBY_EVAL, __FILE__, __LINE__
|
10
|
-
def i18n_interpolate(values = {})
|
11
|
-
"#{compiled_interpolation_body(string)}"
|
12
|
-
end
|
13
|
-
RUBY_EVAL
|
14
|
-
end
|
15
|
-
|
16
|
-
string
|
17
|
-
end
|
18
|
-
|
19
|
-
def interpolated_str?(str)
|
20
|
-
str.kind_of?(String) && str.scan(Simple::MATCH).find{|escape_chars, interpolation| !escape_chars && interpolation}
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
def compiled_interpolation_body(str)
|
25
|
-
str.gsub(Simple::MATCH) do
|
26
|
-
escaped, pattern, key = $1, $2, $3.to_sym
|
27
|
-
|
28
|
-
if escaped
|
29
|
-
pattern
|
30
|
-
else
|
31
|
-
eskey = escape_key_sym(key)
|
32
|
-
if Simple::INTERPOLATION_RESERVED_KEYS.include?(key)
|
33
|
-
"\#{raise(ReservedInterpolationKey.new(#{eskey}, self))}"
|
34
|
-
else
|
35
|
-
"\#{values[#{eskey}] || (values.has_key?(#{eskey}) && values[#{eskey}].to_s) || raise(MissingInterpolationArgument.new(#{eskey}, self))}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def escape_key_sym(key)
|
43
|
-
# rely on Ruby to do all the hard work :)
|
44
|
-
key.to_sym.inspect
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/test/backend_test.rb
DELETED
@@ -1,633 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$:.unshift "lib"
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'test/unit'
|
6
|
-
require 'mocha'
|
7
|
-
require 'i18n'
|
8
|
-
require 'time'
|
9
|
-
require 'yaml'
|
10
|
-
|
11
|
-
module I18nBackendTestSetup
|
12
|
-
def setup_backend
|
13
|
-
# backend_reset_translations!
|
14
|
-
@backend = new_backend
|
15
|
-
@backend.store_translations 'en', :foo => {:bar => 'bar', :baz => 'baz'}
|
16
|
-
@locale_dir = File.dirname(__FILE__) + '/locale'
|
17
|
-
end
|
18
|
-
alias :setup :setup_backend
|
19
|
-
|
20
|
-
# def backend_reset_translations!
|
21
|
-
# I18n::Backend::Simple::ClassMethods.send :class_variable_set, :@@translations, {}
|
22
|
-
# end
|
23
|
-
|
24
|
-
def backend_get_translations
|
25
|
-
# I18n::Backend::Simple::ClassMethods.send :class_variable_get, :@@translations
|
26
|
-
@backend.instance_variable_get :@translations
|
27
|
-
end
|
28
|
-
|
29
|
-
def add_datetime_translations
|
30
|
-
@backend.store_translations :'de', {
|
31
|
-
:date => {
|
32
|
-
:formats => {
|
33
|
-
:default => "%d.%m.%Y",
|
34
|
-
:short => "%d. %b",
|
35
|
-
:long => "%d. %B %Y",
|
36
|
-
},
|
37
|
-
:day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
|
38
|
-
:abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
|
39
|
-
:month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
|
40
|
-
:abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
|
41
|
-
:order => [:day, :month, :year]
|
42
|
-
},
|
43
|
-
:time => {
|
44
|
-
:formats => {
|
45
|
-
:default => "%a, %d. %b %Y %H:%M:%S %z",
|
46
|
-
:short => "%d. %b %H:%M",
|
47
|
-
:long => "%d. %B %Y %H:%M",
|
48
|
-
},
|
49
|
-
:am => 'am',
|
50
|
-
:pm => 'pm'
|
51
|
-
},
|
52
|
-
:datetime => {
|
53
|
-
:distance_in_words => {
|
54
|
-
:half_a_minute => 'half a minute',
|
55
|
-
:less_than_x_seconds => {
|
56
|
-
:one => 'less than 1 second',
|
57
|
-
:other => 'less than {{count}} seconds'
|
58
|
-
},
|
59
|
-
:x_seconds => {
|
60
|
-
:one => '1 second',
|
61
|
-
:other => '{{count}} seconds'
|
62
|
-
},
|
63
|
-
:less_than_x_minutes => {
|
64
|
-
:one => 'less than a minute',
|
65
|
-
:other => 'less than {{count}} minutes'
|
66
|
-
},
|
67
|
-
:x_minutes => {
|
68
|
-
:one => '1 minute',
|
69
|
-
:other => '{{count}} minutes'
|
70
|
-
},
|
71
|
-
:about_x_hours => {
|
72
|
-
:one => 'about 1 hour',
|
73
|
-
:other => 'about {{count}} hours'
|
74
|
-
},
|
75
|
-
:x_days => {
|
76
|
-
:one => '1 day',
|
77
|
-
:other => '{{count}} days'
|
78
|
-
},
|
79
|
-
:about_x_months => {
|
80
|
-
:one => 'about 1 month',
|
81
|
-
:other => 'about {{count}} months'
|
82
|
-
},
|
83
|
-
:x_months => {
|
84
|
-
:one => '1 month',
|
85
|
-
:other => '{{count}} months'
|
86
|
-
},
|
87
|
-
:about_x_years => {
|
88
|
-
:one => 'about 1 year',
|
89
|
-
:other => 'about {{count}} year'
|
90
|
-
},
|
91
|
-
:over_x_years => {
|
92
|
-
:one => 'over 1 year',
|
93
|
-
:other => 'over {{count}} years'
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
module I18nBackendTranslationsTest
|
102
|
-
def test_store_translations_adds_translations # no, really :-)
|
103
|
-
@backend.store_translations :'en', :foo => 'bar'
|
104
|
-
assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_store_translations_deep_merges_translations
|
108
|
-
@backend.store_translations :'en', :foo => {:bar => 'bar'}
|
109
|
-
@backend.store_translations :'en', :foo => {:baz => 'baz'}
|
110
|
-
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_store_translations_forces_locale_to_sym
|
114
|
-
@backend.store_translations 'en', :foo => 'bar'
|
115
|
-
assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_store_translations_converts_keys_to_symbols
|
119
|
-
# backend_reset_translations!
|
120
|
-
@backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
|
121
|
-
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
module I18nBackendAvailableLocalesTest
|
126
|
-
def test_available_locales
|
127
|
-
@backend = new_backend
|
128
|
-
@backend.store_translations 'de', :foo => 'bar'
|
129
|
-
@backend.store_translations 'en', :foo => 'foo'
|
130
|
-
|
131
|
-
assert_equal ['de', 'en'], @backend.available_locales.map{|locale| locale.to_s }.sort
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
module I18nBackendTranslateTest
|
136
|
-
def test_translate_calls_lookup_with_locale_given
|
137
|
-
@backend.expects(:lookup).with('de', :bar, [:foo]).returns 'bar'
|
138
|
-
@backend.translate 'de', :bar, :scope => [:foo]
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_given_no_keys_it_returns_the_default
|
142
|
-
assert_equal 'default', @backend.translate('en', nil, :default => 'default')
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_translate_given_a_symbol_as_a_default_translates_the_symbol
|
146
|
-
assert_equal 'bar', @backend.translate('en', nil, :scope => [:foo], :default => :bar)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_translate_given_an_array_as_default_uses_the_first_match
|
150
|
-
assert_equal 'bar', @backend.translate('en', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
|
154
|
-
assert_raise I18n::MissingTranslationData do
|
155
|
-
@backend.translate('en', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_translate_an_array_of_keys_translates_all_of_them
|
160
|
-
assert_equal %w(bar baz), @backend.translate('en', [:bar, :baz], :scope => [:foo])
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_translate_calls_pluralize
|
164
|
-
@backend.expects(:pluralize).with('en', 'bar', 1).returns('pluralized')
|
165
|
-
@backend.translate 'en', :bar, :scope => [:foo], :count => 1
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_translate_calls_interpolate
|
169
|
-
@backend.expects(:interpolate).returns('interpolated')
|
170
|
-
@backend.translate 'en', :bar, :scope => [:foo]
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_translate_calls_interpolate_including_count_as_a_value
|
174
|
-
@backend.expects(:interpolate).returns('interpolated')
|
175
|
-
@backend.translate 'en', :bar, :scope => [:foo], :count => 1
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_translate_given_nil_as_a_locale_raises_an_argument_error
|
179
|
-
assert_raise(I18n::InvalidLocale){ @backend.translate nil, :bar }
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_translate_with_a_bogus_key_and_no_default_raises_missing_translation_data
|
183
|
-
assert_raise(I18n::MissingTranslationData){ @backend.translate 'de', :bogus }
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
module I18nBackendLookupTest
|
188
|
-
# useful because this way we can use the backend with no key for interpolation/pluralization
|
189
|
-
def test_lookup_given_nil_as_a_key_returns_nil
|
190
|
-
assert_nil @backend.send(:lookup, 'en', nil)
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
|
194
|
-
assert_equal 'bar', @backend.send(:lookup, 'en', :bar, [:foo])
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
module I18nBackendPluralizeTest
|
199
|
-
def test_pluralize_given_nil_returns_the_given_entry
|
200
|
-
entry = {:one => 'bar', :other => 'bars'}
|
201
|
-
assert_equal entry, @backend.send(:pluralize, nil, entry, nil)
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_pluralize_given_0_returns_zero_string_if_zero_key_given
|
205
|
-
assert_equal 'zero', @backend.send(:pluralize, nil, {:zero => 'zero', :one => 'bar', :other => 'bars'}, 0)
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_pluralize_given_0_returns_plural_string_if_no_zero_key_given
|
209
|
-
assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 0)
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_pluralize_given_1_returns_singular_string
|
213
|
-
assert_equal 'bar', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 1)
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_pluralize_given_2_returns_plural_string
|
217
|
-
assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 2)
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_pluralize_given_3_returns_plural_string
|
221
|
-
assert_equal 'bars', @backend.send(:pluralize, nil, {:one => 'bar', :other => 'bars'}, 3)
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_interpolate_given_incomplete_pluralization_data_raises_invalid_pluralization_data
|
225
|
-
assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, {:one => 'bar'}, 2) }
|
226
|
-
end
|
227
|
-
|
228
|
-
# def test_interpolate_given_a_string_raises_invalid_pluralization_data
|
229
|
-
# assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, 'bar', 2) }
|
230
|
-
# end
|
231
|
-
#
|
232
|
-
# def test_interpolate_given_an_array_raises_invalid_pluralization_data
|
233
|
-
# assert_raise(I18n::InvalidPluralizationData){ @backend.send(:pluralize, nil, ['bar'], 2) }
|
234
|
-
# end
|
235
|
-
end
|
236
|
-
|
237
|
-
module I18nBackendInterpolateTest
|
238
|
-
def interpolate_on_backend(str, values)
|
239
|
-
I18n::Backend::Fast::PluralizationCompiler.compile_if_an_interpolation(str) if @backend.kind_of?(I18n::Backend::Fast)
|
240
|
-
@backend.send(:interpolate, str, values)
|
241
|
-
end
|
242
|
-
|
243
|
-
def test_interpolate_given_a_value_hash_interpolates_the_values_to_the_string
|
244
|
-
assert_equal 'Hi David!', interpolate_on_backend('Hi {{name}}!', :name => 'David')
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_interpolate_given_a_value_hash_interpolates_into_unicode_string
|
248
|
-
assert_equal 'Häi David!', interpolate_on_backend('Häi {{name}}!', :name => 'David')
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_interpolate_given_an_unicode_value_hash_interpolates_to_the_string
|
252
|
-
assert_equal 'Hi ゆきひろ!', interpolate_on_backend('Hi {{name}}!', :name => 'ゆきひろ')
|
253
|
-
end
|
254
|
-
|
255
|
-
def test_interpolate_given_an_unicode_value_hash_interpolates_into_unicode_string
|
256
|
-
assert_equal 'こんにちは、ゆきひろさん!', interpolate_on_backend('こんにちは、{{name}}さん!', :name => 'ゆきひろ')
|
257
|
-
end
|
258
|
-
|
259
|
-
if Kernel.const_defined?(:Encoding)
|
260
|
-
def test_interpolate_given_a_non_unicode_multibyte_value_hash_interpolates_into_a_string_with_the_same_encoding
|
261
|
-
assert_equal euc_jp('Hi ゆきひろ!'), interpolate_on_backend('Hi {{name}}!', :name => euc_jp('ゆきひろ'))
|
262
|
-
end
|
263
|
-
|
264
|
-
def test_interpolate_given_an_unicode_value_hash_into_a_non_unicode_multibyte_string_raises_encoding_compatibility_error
|
265
|
-
assert_raise(Encoding::CompatibilityError) do
|
266
|
-
interpolate_on_backend(euc_jp('こんにちは、{{name}}さん!'), :name => 'ゆきひろ')
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
def test_interpolate_given_a_non_unicode_multibyte_value_hash_into_an_unicode_string_raises_encoding_compatibility_error
|
271
|
-
assert_raise(Encoding::CompatibilityError) do
|
272
|
-
interpolate_on_backend('こんにちは、{{name}}さん!', :name => euc_jp('ゆきひろ'))
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_interpolate_given_nil_as_a_string_returns_nil
|
278
|
-
assert_nil interpolate_on_backend(nil, :name => 'David')
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_interpolate_given_an_non_string_as_a_string_returns_nil
|
282
|
-
assert_equal [], interpolate_on_backend([], :name => 'David')
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_interpolate_given_a_values_hash_with_nil_values_interpolates_the_string
|
286
|
-
assert_equal 'Hi !', interpolate_on_backend('Hi {{name}}!', {:name => nil})
|
287
|
-
end
|
288
|
-
|
289
|
-
def test_interpolate_given_an_empty_values_hash_raises_missing_interpolation_argument
|
290
|
-
assert_raise(I18n::MissingInterpolationArgument) { interpolate_on_backend('Hi {{name}}!', {}) }
|
291
|
-
end
|
292
|
-
|
293
|
-
def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
|
294
|
-
assert_raise(I18n::ReservedInterpolationKey) { interpolate_on_backend('{{default}}', {:default => nil}) }
|
295
|
-
end
|
296
|
-
|
297
|
-
private
|
298
|
-
|
299
|
-
def euc_jp(string)
|
300
|
-
string.encode!(Encoding::EUC_JP)
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
module I18nBackendLocalizeDateTest
|
305
|
-
def setup
|
306
|
-
@backend = new_backend
|
307
|
-
add_datetime_translations
|
308
|
-
@date = Date.new 2008, 1, 1
|
309
|
-
end
|
310
|
-
|
311
|
-
def test_translate_given_the_short_format_it_uses_it
|
312
|
-
assert_equal '01. Jan', @backend.localize('de', @date, :short)
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_translate_given_the_long_format_it_uses_it
|
316
|
-
assert_equal '01. Januar 2008', @backend.localize('de', @date, :long)
|
317
|
-
end
|
318
|
-
|
319
|
-
def test_translate_given_the_default_format_it_uses_it
|
320
|
-
assert_equal '01.01.2008', @backend.localize('de', @date, :default)
|
321
|
-
end
|
322
|
-
|
323
|
-
def test_translate_given_a_day_name_format_it_returns_a_day_name
|
324
|
-
assert_equal 'Dienstag', @backend.localize('de', @date, '%A')
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_translate_given_an_abbr_day_name_format_it_returns_an_abbrevated_day_name
|
328
|
-
assert_equal 'Di', @backend.localize('de', @date, '%a')
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_translate_given_a_month_name_format_it_returns_a_month_name
|
332
|
-
assert_equal 'Januar', @backend.localize('de', @date, '%B')
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_translate_given_an_abbr_month_name_format_it_returns_an_abbrevated_month_name
|
336
|
-
assert_equal 'Jan', @backend.localize('de', @date, '%b')
|
337
|
-
end
|
338
|
-
|
339
|
-
def test_translate_given_no_format_it_does_not_fail
|
340
|
-
assert_nothing_raised{ @backend.localize 'de', @date }
|
341
|
-
end
|
342
|
-
|
343
|
-
def test_translate_given_an_unknown_format_it_does_not_fail
|
344
|
-
assert_nothing_raised{ @backend.localize 'de', @date, '%x' }
|
345
|
-
end
|
346
|
-
|
347
|
-
def test_localize_nil_raises_argument_error
|
348
|
-
assert_raise(I18n::ArgumentError) { @backend.localize 'de', nil }
|
349
|
-
end
|
350
|
-
|
351
|
-
def test_localize_object_raises_argument_error
|
352
|
-
assert_raise(I18n::ArgumentError) { @backend.localize 'de', Object.new }
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
module I18nBackendLocalizeDateTimeTest
|
357
|
-
def setup
|
358
|
-
@backend = new_backend
|
359
|
-
add_datetime_translations
|
360
|
-
@morning = DateTime.new 2008, 1, 1, 6
|
361
|
-
@evening = DateTime.new 2008, 1, 1, 18
|
362
|
-
end
|
363
|
-
|
364
|
-
def test_translate_given_the_short_format_it_uses_it
|
365
|
-
assert_equal '01. Jan 06:00', @backend.localize('de', @morning, :short)
|
366
|
-
end
|
367
|
-
|
368
|
-
def test_translate_given_the_long_format_it_uses_it
|
369
|
-
assert_equal '01. Januar 2008 06:00', @backend.localize('de', @morning, :long)
|
370
|
-
end
|
371
|
-
|
372
|
-
def test_translate_given_the_default_format_it_uses_it
|
373
|
-
assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de', @morning, :default)
|
374
|
-
end
|
375
|
-
|
376
|
-
def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
|
377
|
-
assert_equal 'Dienstag', @backend.localize('de', @morning, '%A')
|
378
|
-
end
|
379
|
-
|
380
|
-
def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
|
381
|
-
assert_equal 'Di', @backend.localize('de', @morning, '%a')
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
|
385
|
-
assert_equal 'Januar', @backend.localize('de', @morning, '%B')
|
386
|
-
end
|
387
|
-
|
388
|
-
def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
|
389
|
-
assert_equal 'Jan', @backend.localize('de', @morning, '%b')
|
390
|
-
end
|
391
|
-
|
392
|
-
def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
|
393
|
-
assert_equal 'am', @backend.localize('de', @morning, '%p')
|
394
|
-
assert_equal 'pm', @backend.localize('de', @evening, '%p')
|
395
|
-
end
|
396
|
-
|
397
|
-
def test_translate_given_no_format_it_does_not_fail
|
398
|
-
assert_nothing_raised{ @backend.localize 'de', @morning }
|
399
|
-
end
|
400
|
-
|
401
|
-
def test_translate_given_an_unknown_format_it_does_not_fail
|
402
|
-
assert_nothing_raised{ @backend.localize 'de', @morning, '%x' }
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
module I18nBackendLocalizeTimeTest
|
407
|
-
def setup
|
408
|
-
@old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
|
409
|
-
@backend = new_backend
|
410
|
-
add_datetime_translations
|
411
|
-
@morning = Time.parse '2008-01-01 6:00 UTC'
|
412
|
-
@evening = Time.parse '2008-01-01 18:00 UTC'
|
413
|
-
end
|
414
|
-
|
415
|
-
def teardown
|
416
|
-
@old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
|
417
|
-
end
|
418
|
-
|
419
|
-
def test_translate_given_the_short_format_it_uses_it
|
420
|
-
assert_equal '01. Jan 06:00', @backend.localize('de', @morning, :short)
|
421
|
-
end
|
422
|
-
|
423
|
-
def test_translate_given_the_long_format_it_uses_it
|
424
|
-
assert_equal '01. Januar 2008 06:00', @backend.localize('de', @morning, :long)
|
425
|
-
end
|
426
|
-
|
427
|
-
# TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
|
428
|
-
# def test_translate_given_the_default_format_it_uses_it
|
429
|
-
# assert_equal 'Di, 01. Jan 2008 06:00:00 +0000', @backend.localize('de', @morning, :default)
|
430
|
-
# end
|
431
|
-
|
432
|
-
def test_translate_given_a_day_name_format_it_returns_the_correct_day_name
|
433
|
-
assert_equal 'Dienstag', @backend.localize('de', @morning, '%A')
|
434
|
-
end
|
435
|
-
|
436
|
-
def test_translate_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
|
437
|
-
assert_equal 'Di', @backend.localize('de', @morning, '%a')
|
438
|
-
end
|
439
|
-
|
440
|
-
def test_translate_given_a_month_name_format_it_returns_the_correct_month_name
|
441
|
-
assert_equal 'Januar', @backend.localize('de', @morning, '%B')
|
442
|
-
end
|
443
|
-
|
444
|
-
def test_translate_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
|
445
|
-
assert_equal 'Jan', @backend.localize('de', @morning, '%b')
|
446
|
-
end
|
447
|
-
|
448
|
-
def test_translate_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
|
449
|
-
assert_equal 'am', @backend.localize('de', @morning, '%p')
|
450
|
-
assert_equal 'pm', @backend.localize('de', @evening, '%p')
|
451
|
-
end
|
452
|
-
|
453
|
-
def test_translate_given_no_format_it_does_not_fail
|
454
|
-
assert_nothing_raised{ @backend.localize 'de', @morning }
|
455
|
-
end
|
456
|
-
|
457
|
-
def test_translate_given_an_unknown_format_it_does_not_fail
|
458
|
-
assert_nothing_raised{ @backend.localize 'de', @morning, '%x' }
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
module I18nBackendHelperMethodsTest
|
463
|
-
def test_deep_symbolize_keys_works
|
464
|
-
result = @backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
|
465
|
-
expected = {:foo => {:bar => {:baz => 'bar'}}}
|
466
|
-
assert_equal expected, result
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
module I18nBackendLoadTranslationsTest
|
471
|
-
def test_load_translations_with_unknown_file_type_raises_exception
|
472
|
-
assert_raise(I18n::UnknownFileType) { @backend.load_translations "#{@locale_dir}/en.xml" }
|
473
|
-
end
|
474
|
-
|
475
|
-
def test_load_translations_with_ruby_file_type_does_not_raise_exception
|
476
|
-
assert_nothing_raised { @backend.load_translations "#{@locale_dir}/en.rb" }
|
477
|
-
end
|
478
|
-
|
479
|
-
def test_load_rb_loads_data_from_ruby_file
|
480
|
-
data = @backend.send :load_rb, "#{@locale_dir}/en.rb"
|
481
|
-
assert_equal({:'en-Ruby' => {:foo => {:bar => "baz"}}}, data)
|
482
|
-
end
|
483
|
-
|
484
|
-
def test_load_rb_loads_data_from_yaml_file
|
485
|
-
data = @backend.send :load_yml, "#{@locale_dir}/en.yml"
|
486
|
-
assert_equal({'en-Yaml' => {'foo' => {'bar' => 'baz'}}}, data)
|
487
|
-
end
|
488
|
-
|
489
|
-
def test_load_translations_loads_from_different_file_formats
|
490
|
-
@backend = new_backend
|
491
|
-
@backend.load_translations "#{@locale_dir}/en.rb", "#{@locale_dir}/en.yml"
|
492
|
-
expected = {
|
493
|
-
:'en-Ruby' => {:foo => {:bar => "baz"}},
|
494
|
-
:'en-Yaml' => {:foo => {:bar => "baz"}}
|
495
|
-
}
|
496
|
-
assert_equal expected, backend_get_translations
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
module I18nBackendLoadPathTest
|
501
|
-
def teardown
|
502
|
-
I18n.load_path = []
|
503
|
-
end
|
504
|
-
|
505
|
-
def test_nested_load_paths_do_not_break_locale_loading
|
506
|
-
@backend = new_backend
|
507
|
-
I18n.load_path = [[File.dirname(__FILE__) + '/locale/en.yml']]
|
508
|
-
assert_nil backend_get_translations
|
509
|
-
assert_nothing_raised { @backend.send :init_translations }
|
510
|
-
assert_not_nil backend_get_translations
|
511
|
-
end
|
512
|
-
|
513
|
-
def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
|
514
|
-
@backend = new_backend
|
515
|
-
I18n.load_path << Dir[File.dirname(__FILE__) + '/locale/*.{rb,yml}']
|
516
|
-
assert_nil backend_get_translations
|
517
|
-
assert_nothing_raised { @backend.send :init_translations }
|
518
|
-
assert_not_nil backend_get_translations
|
519
|
-
end
|
520
|
-
end
|
521
|
-
|
522
|
-
module I18nBackendReloadTranslationsTest
|
523
|
-
def setup
|
524
|
-
@backend = new_backend
|
525
|
-
I18n.load_path = [File.dirname(__FILE__) + '/locale/en.yml']
|
526
|
-
assert_nil backend_get_translations
|
527
|
-
@backend.send :init_translations
|
528
|
-
end
|
529
|
-
|
530
|
-
def teardown
|
531
|
-
I18n.load_path = []
|
532
|
-
end
|
533
|
-
|
534
|
-
def test_setup
|
535
|
-
assert_not_nil backend_get_translations
|
536
|
-
end
|
537
|
-
|
538
|
-
def test_reload_translations_unloads_translations
|
539
|
-
@backend.expects(:stale?).returns(true)
|
540
|
-
@backend.reload!
|
541
|
-
assert_nil backend_get_translations
|
542
|
-
end
|
543
|
-
|
544
|
-
def test_reload_translations_uninitializes_translations
|
545
|
-
@backend.expects(:stale?).returns(true)
|
546
|
-
@backend.reload!
|
547
|
-
assert_equal @backend.initialized?, false
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
module I18nBackendLazyReloadingTest
|
552
|
-
def locale_fixture_path(file)
|
553
|
-
File.join(File.dirname(__FILE__), 'locale', file)
|
554
|
-
end
|
555
|
-
|
556
|
-
def trigger_reload
|
557
|
-
@backend.reload!
|
558
|
-
@backend.available_locales
|
559
|
-
end
|
560
|
-
|
561
|
-
def assert_triggers_translations_reload
|
562
|
-
yield
|
563
|
-
@backend.expects(:init_translations)
|
564
|
-
trigger_reload
|
565
|
-
end
|
566
|
-
|
567
|
-
def assert_does_not_trigger_translations_reload
|
568
|
-
yield
|
569
|
-
@backend.expects(:init_translations).never
|
570
|
-
trigger_reload
|
571
|
-
end
|
572
|
-
|
573
|
-
def setup
|
574
|
-
@backend = new_backend
|
575
|
-
I18n.load_path = [locale_fixture_path('en.yml')]
|
576
|
-
@backend.send(:init_translations)
|
577
|
-
end
|
578
|
-
|
579
|
-
def test_does_not_perform_reload_if_translation_files_are_not_updated
|
580
|
-
assert_does_not_trigger_translations_reload do
|
581
|
-
@backend.reload!
|
582
|
-
end
|
583
|
-
end
|
584
|
-
|
585
|
-
def test_performs_reload_if_new_translation_is_added
|
586
|
-
assert_triggers_translations_reload do
|
587
|
-
I18n.load_path << locale_fixture_path('en.rb')
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
def test_performs_reload_if_translation_is_removed
|
592
|
-
assert_triggers_translations_reload do
|
593
|
-
I18n.load_path.clear
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
def test_performs_reload_if_translation_file_is_updated
|
598
|
-
assert_triggers_translations_reload do
|
599
|
-
File.expects(:mtime).with(I18n.load_path.first).returns(Time.now - 10)
|
600
|
-
end
|
601
|
-
end
|
602
|
-
end
|
603
|
-
|
604
|
-
test_modules = %w(I18nBackendTranslationsTest
|
605
|
-
I18nBackendAvailableLocalesTest
|
606
|
-
I18nBackendTranslateTest
|
607
|
-
I18nBackendLookupTest
|
608
|
-
I18nBackendPluralizeTest
|
609
|
-
I18nBackendInterpolateTest
|
610
|
-
I18nBackendLocalizeDateTest
|
611
|
-
I18nBackendLocalizeDateTimeTest
|
612
|
-
I18nBackendLocalizeTimeTest
|
613
|
-
I18nBackendHelperMethodsTest
|
614
|
-
I18nBackendLoadTranslationsTest
|
615
|
-
I18nBackendLoadPathTest
|
616
|
-
I18nBackendReloadTranslationsTest
|
617
|
-
I18nBackendLazyReloadingTest)
|
618
|
-
|
619
|
-
test_cases = test_modules.map do |test_module|
|
620
|
-
%w(Simple Fast).map do |backend_type|
|
621
|
-
Class.new(Test::Unit::TestCase) do
|
622
|
-
|
623
|
-
class_eval <<-RUBY_EVAL, __FILE__, __LINE__
|
624
|
-
def new_backend
|
625
|
-
I18n::Backend::#{backend_type}.new
|
626
|
-
end
|
627
|
-
RUBY_EVAL
|
628
|
-
|
629
|
-
include I18nBackendTestSetup
|
630
|
-
include Object.const_get(test_module)
|
631
|
-
end
|
632
|
-
end
|
633
|
-
end
|