i18n 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of i18n might be problematic. Click here for more details.
- data/CHANGELOG.textile +19 -0
- data/README.textile +41 -15
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/i18n.rb +1 -1
- data/lib/i18n/backend/active_record.rb +6 -5
- data/lib/i18n/backend/active_record/missing.rb +64 -0
- data/lib/i18n/backend/active_record/translation.rb +2 -2
- data/lib/i18n/backend/base.rb +2 -2
- data/lib/i18n/backend/chain.rb +3 -3
- data/lib/i18n/helpers/gettext.rb +1 -1
- data/test/all.rb +4 -4
- data/test/api/basics.rb +8 -8
- data/test/api/defaults.rb +40 -0
- data/test/api/interpolation.rb +65 -67
- data/test/api/link.rb +31 -38
- data/test/api/localization/date.rb +69 -50
- data/test/api/localization/date_time.rb +66 -42
- data/test/api/localization/procs.rb +54 -0
- data/test/api/localization/time.rb +71 -52
- data/test/api/lookup.rb +38 -0
- data/test/api/pluralization.rb +22 -24
- data/test/api/procs.rb +40 -0
- data/test/cases/api/active_record_test.rb +28 -0
- data/test/cases/api/all_features_test.rb +37 -0
- data/test/cases/api/chain_test.rb +26 -0
- data/test/cases/api/fallbacks_test.rb +33 -0
- data/test/cases/api/pluralization_test.rb +33 -0
- data/test/cases/api/simple_test.rb +21 -0
- data/test/{backend/active_record_missing/active_record_missing_test.rb → cases/backend/active_record/missing_test.rb} +5 -8
- data/test/{backend/active_record → cases/backend}/active_record_test.rb +13 -3
- data/test/{backend/cache → cases/backend}/cache_test.rb +7 -7
- data/test/{backend/chain → cases/backend}/chain_test.rb +1 -1
- data/test/{backend/fallbacks → cases/backend}/fallbacks_test.rb +5 -5
- data/test/{backend/simple → cases/backend}/helpers_test.rb +1 -1
- data/test/{backend/metadata → cases/backend}/metadata_test.rb +12 -10
- data/test/{backend/pluralization → cases/backend}/pluralization_test.rb +10 -10
- data/test/cases/backend/simple_test.rb +77 -0
- data/test/{core_ext → cases/core_ext}/string/interpolate_test.rb +15 -15
- data/test/{gettext → cases/gettext}/api_test.rb +1 -4
- data/test/{gettext → cases/gettext}/backend_test.rb +9 -2
- data/test/{i18n_exceptions_test.rb → cases/i18n_exceptions_test.rb} +1 -1
- data/test/{i18n_load_path_test.rb → cases/i18n_load_path_test.rb} +2 -2
- data/test/{i18n_test.rb → cases/i18n_test.rb} +1 -1
- data/test/{locale → cases/locale}/fallbacks_test.rb +1 -3
- data/test/{locale → cases/locale}/tag/rfc4646_test.rb +1 -3
- data/test/{locale → cases/locale}/tag/simple_test.rb +1 -3
- data/test/fixtures/locales/de.po +5 -0
- data/test/test_helper.rb +45 -30
- data/vendor/po_parser.rb +329 -0
- metadata +60 -69
- data/lib/i18n/backend/active_record_missing.rb +0 -55
- data/test/api/lambda.rb +0 -52
- data/test/api/localization/lambda.rb +0 -26
- data/test/api/translation.rb +0 -51
- data/test/backend/active_record/all.rb +0 -3
- data/test/backend/active_record/api_test.rb +0 -54
- data/test/backend/active_record/setup.rb +0 -166
- data/test/backend/all/api_test.rb +0 -88
- data/test/backend/chain/api_test.rb +0 -80
- data/test/backend/fallbacks/api_test.rb +0 -84
- data/test/backend/pluralization/api_test.rb +0 -86
- data/test/backend/simple/all.rb +0 -5
- data/test/backend/simple/api_test.rb +0 -92
- data/test/backend/simple/lookup_test.rb +0 -24
- data/test/backend/simple/setup.rb +0 -147
- data/test/backend/simple/translations_test.rb +0 -83
- data/test/with_options.rb +0 -34
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
3
3
|
|
4
|
-
class
|
4
|
+
class I18nBackendHelpersTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
@backend = I18n::Backend::Simple.new
|
7
7
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
4
4
|
require 'i18n/backend/metadata'
|
5
5
|
|
6
|
-
class
|
6
|
+
class I18nBackendMetadataTest < Test::Unit::TestCase
|
7
7
|
class Backend
|
8
8
|
include I18n::Backend::Base
|
9
9
|
include I18n::Backend::Metadata
|
@@ -11,15 +11,7 @@ class I18nTranslationMetadataTest < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
def setup
|
13
13
|
I18n.backend = Backend.new
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def translations
|
18
|
-
I18n.backend.instance_variable_get(:@translations)
|
19
|
-
end
|
20
|
-
|
21
|
-
def store_metadata(key, name, value)
|
22
|
-
translations[:en][key].translation_metadata[name] = value
|
14
|
+
store_translations(:en, :foo => 'Hi {{name}}')
|
23
15
|
end
|
24
16
|
|
25
17
|
define_method "test: translation strings carry metadata" do
|
@@ -61,5 +53,15 @@ class I18nTranslationMetadataTest < Test::Unit::TestCase
|
|
61
53
|
define_method "test: pluralizatoin adds the count to metadata on Strings" do
|
62
54
|
assert_equal(1, I18n.t(:missing, :count => 1, :default => { :one => 'foo' }).translation_metadata[:count])
|
63
55
|
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def translations
|
60
|
+
I18n.backend.instance_variable_get(:@translations)
|
61
|
+
end
|
62
|
+
|
63
|
+
def store_metadata(key, name, value)
|
64
|
+
translations[:en][key].translation_metadata[name] = value
|
65
|
+
end
|
64
66
|
end
|
65
67
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
4
4
|
require 'i18n/backend/pluralization'
|
5
5
|
|
6
|
-
class
|
6
|
+
class I18nBackendPluralizationTest < Test::Unit::TestCase
|
7
7
|
class Backend
|
8
8
|
include I18n::Backend::Base
|
9
9
|
include I18n::Backend::Pluralization
|
@@ -11,32 +11,32 @@ class I18nPluralizationBackendTest < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
def setup
|
13
13
|
I18n.backend = Backend.new
|
14
|
-
@
|
15
|
-
|
14
|
+
@rule = lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other }
|
15
|
+
store_translations(:foo, :i18n => { :plural => { :rule => @rule } })
|
16
16
|
@entry = { :zero => 'zero', :one => 'one', :few => 'few', :many => 'many', :other => 'other' }
|
17
17
|
end
|
18
18
|
|
19
|
-
define_method
|
20
|
-
assert_equal @
|
19
|
+
define_method "test: pluralization picks a pluralizer from :'i18n.pluralize'" do
|
20
|
+
assert_equal @rule, I18n.backend.send(:pluralizer, :foo)
|
21
21
|
end
|
22
22
|
|
23
|
-
define_method
|
23
|
+
define_method "test: pluralization picks :one for 1" do
|
24
24
|
assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :foo)
|
25
25
|
end
|
26
26
|
|
27
|
-
define_method
|
27
|
+
define_method "test: pluralization picks :few for 2" do
|
28
28
|
assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :foo)
|
29
29
|
end
|
30
30
|
|
31
|
-
define_method
|
31
|
+
define_method "test: pluralization picks :many for 11" do
|
32
32
|
assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :foo)
|
33
33
|
end
|
34
34
|
|
35
|
-
define_method
|
35
|
+
define_method "test: pluralization picks zero for 0 if the key is contained in the data" do
|
36
36
|
assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :foo)
|
37
37
|
end
|
38
38
|
|
39
|
-
define_method
|
39
|
+
define_method "test: pluralization picks few for 0 if the key is not contained in the data" do
|
40
40
|
@entry.delete(:zero)
|
41
41
|
assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :foo)
|
42
42
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
4
|
+
|
5
|
+
class I18nBackendSimpleTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
I18n.backend = I18n::Backend::Simple.new
|
8
|
+
I18n.load_path = [locales_dir + '/en.yml']
|
9
|
+
end
|
10
|
+
|
11
|
+
# useful because this way we can use the backend with no key for interpolation/pluralization
|
12
|
+
define_method "test simple backend lookup: given nil as a key it returns nil" do
|
13
|
+
assert_nil I18n.backend.send(:lookup, :en, nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
# loading translations
|
17
|
+
|
18
|
+
define_method "test simple load_translations: given an unknown file type it raises I18n::UnknownFileType" do
|
19
|
+
assert_raises(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
|
20
|
+
end
|
21
|
+
|
22
|
+
define_method "test simple load_translations: given a Ruby file name it does not raise anything" do
|
23
|
+
assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
|
24
|
+
end
|
25
|
+
|
26
|
+
define_method "test simple load_rb: loads data from a Ruby file" do
|
27
|
+
data = I18n.backend.send(:load_rb, "#{locales_dir}/en.rb")
|
28
|
+
assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
|
29
|
+
end
|
30
|
+
|
31
|
+
define_method "test simple load_yml: loads data from a YAML file" do
|
32
|
+
data = I18n.backend.send(:load_yml, "#{locales_dir}/en.yml")
|
33
|
+
assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
|
34
|
+
end
|
35
|
+
|
36
|
+
define_method "test simple load_translations: loads data from known file formats" do
|
37
|
+
I18n.backend = I18n::Backend::Simple.new
|
38
|
+
I18n.backend.load_translations("#{locales_dir}/en.rb", "#{locales_dir}/en.yml")
|
39
|
+
expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
|
40
|
+
assert_equal expected, translations
|
41
|
+
end
|
42
|
+
|
43
|
+
# storing translations
|
44
|
+
|
45
|
+
define_method "test simple store_translations: stores translations, ... no, really :-)" do
|
46
|
+
I18n.backend.store_translations :'en', :foo => 'bar'
|
47
|
+
assert_equal Hash[:'en', {:foo => 'bar'}], translations
|
48
|
+
end
|
49
|
+
|
50
|
+
define_method "test simple store_translations: deep_merges with existing translations" do
|
51
|
+
I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
|
52
|
+
I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
|
53
|
+
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
|
54
|
+
end
|
55
|
+
|
56
|
+
define_method "test simple store_translations: converts the given locale to a Symbol" do
|
57
|
+
I18n.backend.store_translations 'en', :foo => 'bar'
|
58
|
+
assert_equal Hash[:'en', {:foo => 'bar'}], translations
|
59
|
+
end
|
60
|
+
|
61
|
+
define_method "test simple store_translations: converts keys to Symbols" do
|
62
|
+
I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
|
63
|
+
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
|
64
|
+
end
|
65
|
+
|
66
|
+
# reloading translations
|
67
|
+
|
68
|
+
define_method "test simple reload_translations: unloads translations" do
|
69
|
+
I18n.backend.reload!
|
70
|
+
assert_nil translations
|
71
|
+
end
|
72
|
+
|
73
|
+
define_method "test simple reload_translations: uninitializes the backend" do
|
74
|
+
I18n.backend.reload!
|
75
|
+
assert_equal I18n.backend.initialized?, false
|
76
|
+
end
|
77
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
4
4
|
|
5
5
|
# thanks to Masao's String extensions these should work the same in
|
6
6
|
# Ruby 1.8 (patched) and Ruby 1.9 (native)
|
@@ -8,36 +8,36 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
8
8
|
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
|
9
9
|
|
10
10
|
class I18nCoreExtStringInterpolationTest < Test::Unit::TestCase
|
11
|
-
define_method
|
11
|
+
define_method "test: String interpolates a single argument" do
|
12
12
|
assert_equal "Masao", "%s" % "Masao"
|
13
13
|
end
|
14
14
|
|
15
|
-
define_method
|
15
|
+
define_method "test: String interpolates an array argument" do
|
16
16
|
assert_equal "1 message", "%d %s" % [1, 'message']
|
17
17
|
end
|
18
18
|
|
19
|
-
define_method
|
19
|
+
define_method "test: String interpolates a hash argument w/ named placeholders" do
|
20
20
|
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh' }
|
21
21
|
end
|
22
22
|
|
23
|
-
define_method
|
23
|
+
define_method "test: String interpolates a hash argument w/ named placeholders (reverse order)" do
|
24
24
|
assert_equal "Mutoh, Masao", "%{last}, %{first}" % { :first => 'Masao', :last => 'Mutoh' }
|
25
25
|
end
|
26
26
|
|
27
|
-
define_method
|
27
|
+
define_method "test: String interpolates named placeholders with sprintf syntax" do
|
28
28
|
assert_equal "10, 43.4", "%<integer>d, %<float>.1f" % {:integer => 10, :float => 43.4}
|
29
29
|
end
|
30
30
|
|
31
|
-
define_method
|
31
|
+
define_method "test: String interpolates named placeholders with sprintf syntax, does not recurse" do
|
32
32
|
assert_equal "%<not_translated>s", "%{msg}" % { :msg => '%<not_translated>s', :not_translated => 'should not happen' }
|
33
33
|
end
|
34
34
|
|
35
|
-
define_method
|
35
|
+
define_method "test: String interpolation does not replace anything when no placeholders are given" do
|
36
36
|
assert_equal("aaa", "aaa" % {:num => 1})
|
37
37
|
assert_equal("bbb", "bbb" % [1])
|
38
38
|
end
|
39
39
|
|
40
|
-
define_method
|
40
|
+
define_method "test: String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
|
41
41
|
assert_equal("1", "%<num>d" % {:num => 1})
|
42
42
|
assert_equal("0b1", "%<num>#b" % {:num => 1})
|
43
43
|
assert_equal("foo", "%<msg>s" % {:msg => "foo"})
|
@@ -49,35 +49,35 @@ class I18nCoreExtStringInterpolationTest < Test::Unit::TestCase
|
|
49
49
|
assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
|
50
50
|
end
|
51
51
|
|
52
|
-
define_method
|
52
|
+
define_method "test: String interpolation old-style sprintf still works" do
|
53
53
|
assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0])
|
54
54
|
end
|
55
55
|
|
56
|
-
define_method
|
56
|
+
define_method "test: String interpolation raises an ArgumentError when the string has extra placeholders (Array)" do
|
57
57
|
assert_raises(ArgumentError) do # Ruby 1.9 msg: "too few arguments"
|
58
58
|
"%s %s" % %w(Masao)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
define_method
|
62
|
+
define_method "test: String interpolation raises a KeyError when the string has extra placeholders (Hash)" do
|
63
63
|
assert_raises(KeyError) do # Ruby 1.9 msg: "key not found"
|
64
64
|
"%{first} %{last}" % { :first => 'Masao' }
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
define_method
|
68
|
+
define_method "test: String interpolation does not raise when passed extra values (Array)" do
|
69
69
|
assert_nothing_raised do
|
70
70
|
assert_equal "Masao", "%s" % %w(Masao Mutoh)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
define_method
|
74
|
+
define_method "test: String interpolation does not raise when passed extra values (Hash)" do
|
75
75
|
assert_nothing_raised do
|
76
76
|
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' }
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
define_method
|
80
|
+
define_method "test: % acts as escape character in String interpolation" do
|
81
81
|
assert_equal "%{first}", "%%{first}" % { :first => 'Masao' }
|
82
82
|
assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
|
83
83
|
assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
4
4
|
require 'i18n/backend/gettext'
|
5
5
|
require 'i18n/helpers/gettext'
|
6
6
|
|
@@ -12,9 +12,6 @@ class I18nGettextApiTest < Test::Unit::TestCase
|
|
12
12
|
I18n.backend.store_translations :de, {
|
13
13
|
'Hi Gettext!' => 'Hallo Gettext!',
|
14
14
|
'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
|
15
|
-
# "An apple#{I18n::Gettext::PLURAL_SEPARATOR}{{count}} apples" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
|
16
|
-
# :special => { "A special apple#{I18n::Gettext::PLURAL_SEPARATOR}{{count}} special apples" => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
|
17
|
-
# alternative implementation
|
18
15
|
"An apple" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
|
19
16
|
:special => { "A special apple" => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
|
20
17
|
:foo => { :bar => 'bar-de' }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
4
4
|
require 'i18n/backend/gettext'
|
5
5
|
require 'i18n/helpers/gettext'
|
6
6
|
|
@@ -15,7 +15,7 @@ class I18nGettextBackendTest < Test::Unit::TestCase
|
|
15
15
|
def setup
|
16
16
|
I18n.backend = Backend.new
|
17
17
|
I18n.locale = :en
|
18
|
-
I18n.load_path = [locales_dir
|
18
|
+
I18n.load_path = ["#{locales_dir}/de.po"]
|
19
19
|
end
|
20
20
|
|
21
21
|
def teardown
|
@@ -81,4 +81,11 @@ class I18nGettextBackendTest < Test::Unit::TestCase
|
|
81
81
|
assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
|
82
82
|
assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
|
83
83
|
end
|
84
|
+
|
85
|
+
def test_ngettextpluralizes_entry_with_dots
|
86
|
+
I18n.locale = :de
|
87
|
+
assert_equal 'Auf 1 Achse.', n_("On %{count} wheel.", "On %{count} wheels.", 1)
|
88
|
+
assert_equal 'Auf 2 Achsen.', n_("On %{count} wheel.", "On %{count} wheels.", 2)
|
89
|
+
end
|
90
|
+
|
84
91
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
4
4
|
|
5
5
|
class I18nLoadPathTest < Test::Unit::TestCase
|
6
6
|
# include Tests::Backend::Simple::Setup::Base
|
@@ -8,7 +8,7 @@ class I18nLoadPathTest < Test::Unit::TestCase
|
|
8
8
|
def setup
|
9
9
|
I18n.locale = :en
|
10
10
|
I18n.backend = I18n::Backend::Simple.new
|
11
|
-
|
11
|
+
store_translations(:en, :foo => {:bar => 'bar', :baz => 'baz'})
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_nested_load_paths_do_not_break_locale_loading
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.dirname(__FILE__) + '
|
4
|
-
|
5
|
-
# Rfc4646::Parser
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
6
4
|
|
7
5
|
class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase
|
8
6
|
include I18n::Locale
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.dirname(__FILE__) + '
|
4
|
-
require 'i18n/locale/tag'
|
5
|
-
require 'i18n/locale/tag/simple'
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
6
4
|
|
7
5
|
class I18nLocaleTagSimpleTest < Test::Unit::TestCase
|
8
6
|
include I18n::Locale
|
data/test/fixtures/locales/de.po
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
$: << "lib"
|
4
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
4
5
|
|
5
6
|
require 'rubygems'
|
6
7
|
require 'test/unit'
|
@@ -10,56 +11,70 @@ require 'i18n/core_ext/object/meta_class'
|
|
10
11
|
require 'time'
|
11
12
|
require 'yaml'
|
12
13
|
|
13
|
-
require File.dirname(__FILE__) + '/with_options'
|
14
|
-
require File.dirname(__FILE__) + '/backend/simple/setup'
|
15
|
-
require File.dirname(__FILE__) + '/backend/active_record/setup'
|
16
|
-
|
17
14
|
Dir[File.dirname(__FILE__) + '/api/**/*.rb'].each do |filename|
|
18
15
|
require filename
|
19
16
|
end
|
20
17
|
|
21
18
|
$KCODE = 'u' unless RUBY_VERSION >= '1.9'
|
22
19
|
|
23
|
-
|
20
|
+
# wtf is wrong with this, why's there Kernel#test?
|
21
|
+
# class Module
|
22
|
+
# def self.test(name, &block)
|
23
|
+
# define_method("test: " + name, &block)
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
24
28
|
def self.test(name, &block)
|
25
29
|
define_method("test: " + name, &block)
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
29
|
-
|
32
|
+
def teardown
|
33
|
+
I18n.locale = nil
|
34
|
+
I18n.default_locale = :en
|
35
|
+
I18n.load_path = []
|
36
|
+
I18n.available_locales = nil
|
37
|
+
I18n.backend = nil
|
30
38
|
end
|
31
39
|
|
32
|
-
def
|
33
|
-
|
40
|
+
def translations
|
41
|
+
I18n.backend.instance_variable_get(:@translations)
|
34
42
|
end
|
35
|
-
|
36
|
-
def
|
37
|
-
|
43
|
+
|
44
|
+
def store_translations(*args)
|
45
|
+
data = args.pop
|
46
|
+
locale = args.pop || :en
|
47
|
+
I18n.backend.store_translations(locale, data)
|
38
48
|
end
|
39
|
-
|
40
|
-
def
|
41
|
-
|
49
|
+
|
50
|
+
def locales_dir
|
51
|
+
File.dirname(__FILE__) + '/fixtures/locales'
|
42
52
|
end
|
43
53
|
|
44
|
-
def
|
45
|
-
|
54
|
+
def euc_jp(string)
|
55
|
+
string.encode!(Encoding::EUC_JP)
|
46
56
|
end
|
57
|
+
end
|
47
58
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
alias :datetime :morning_datetime
|
59
|
+
def setup_active_record
|
60
|
+
require 'active_record'
|
61
|
+
require 'i18n/backend/active_record/store_procs'
|
52
62
|
|
53
|
-
|
54
|
-
|
63
|
+
if I18n::Backend::Simple.method_defined?(:interpolate_with_deprecated_syntax)
|
64
|
+
I18n::Backend::Simple.send(:remove_method, :interpolate) rescue NameError
|
55
65
|
end
|
56
66
|
|
57
|
-
|
58
|
-
|
67
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
68
|
+
ActiveRecord::Migration.verbose = false
|
69
|
+
ActiveRecord::Schema.define(:version => 1) do
|
70
|
+
create_table :translations do |t|
|
71
|
+
t.string :locale
|
72
|
+
t.string :key
|
73
|
+
t.string :value
|
74
|
+
t.string :interpolations
|
75
|
+
t.boolean :is_proc, :default => false
|
76
|
+
end
|
59
77
|
end
|
60
|
-
alias :time :morning_time
|
61
78
|
|
62
|
-
|
63
|
-
Time.parse('2008-03-01 18:00 UTC')
|
64
|
-
end
|
79
|
+
I18n::Backend::ActiveRecord::Translation.send(:include, I18n::Backend::ActiveRecord::StoreProcs)
|
65
80
|
end
|