polish 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.md +25 -0
- data/Rakefile +56 -0
- data/TODO +5 -0
- data/init.rb +1 -0
- data/lib/polish.rb +104 -0
- data/lib/polish/action_view_ext/helpers/date_helper.rb +94 -0
- data/lib/polish/backend/advanced.rb +105 -0
- data/lib/polish/locale/actionview.yml +81 -0
- data/lib/polish/locale/activerecord.yml +27 -0
- data/lib/polish/locale/activesupport.yml +11 -0
- data/lib/polish/locale/datetime.yml +25 -0
- data/lib/polish/locale/pluralize.rb +16 -0
- data/lib/vendor/i18n/CHANGELOG.textile +57 -0
- data/lib/vendor/i18n/MIT-LICENSE +20 -0
- data/lib/vendor/i18n/README.textile +42 -0
- data/lib/vendor/i18n/Rakefile +21 -0
- data/lib/vendor/i18n/VERSION +1 -0
- data/lib/vendor/i18n/i18n.gemspec +141 -0
- data/lib/vendor/i18n/lib/i18n.rb +270 -0
- data/lib/vendor/i18n/lib/i18n/backend/base.rb +251 -0
- data/lib/vendor/i18n/lib/i18n/backend/cache.rb +71 -0
- data/lib/vendor/i18n/lib/i18n/backend/chain.rb +64 -0
- data/lib/vendor/i18n/lib/i18n/backend/fallbacks.rb +53 -0
- data/lib/vendor/i18n/lib/i18n/backend/gettext.rb +65 -0
- data/lib/vendor/i18n/lib/i18n/backend/pluralization.rb +56 -0
- data/lib/vendor/i18n/lib/i18n/backend/simple.rb +23 -0
- data/lib/vendor/i18n/lib/i18n/exceptions.rb +61 -0
- data/lib/vendor/i18n/lib/i18n/gettext.rb +25 -0
- data/lib/vendor/i18n/lib/i18n/helpers/gettext.rb +35 -0
- data/lib/vendor/i18n/lib/i18n/locale/fallbacks.rb +100 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag.rb +27 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag/parents.rb +24 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag/rfc4646.rb +78 -0
- data/lib/vendor/i18n/lib/i18n/locale/tag/simple.rb +44 -0
- data/lib/vendor/i18n/lib/i18n/string.rb +95 -0
- data/lib/vendor/i18n/test/all.rb +5 -0
- data/lib/vendor/i18n/test/api/basics.rb +15 -0
- data/lib/vendor/i18n/test/api/interpolation.rb +85 -0
- data/lib/vendor/i18n/test/api/lambda.rb +52 -0
- data/lib/vendor/i18n/test/api/link.rb +47 -0
- data/lib/vendor/i18n/test/api/localization/date.rb +65 -0
- data/lib/vendor/i18n/test/api/localization/date_time.rb +63 -0
- data/lib/vendor/i18n/test/api/localization/lambda.rb +26 -0
- data/lib/vendor/i18n/test/api/localization/time.rb +63 -0
- data/lib/vendor/i18n/test/api/pluralization.rb +37 -0
- data/lib/vendor/i18n/test/api/translation.rb +51 -0
- data/lib/vendor/i18n/test/backend/cache/cache_test.rb +57 -0
- data/lib/vendor/i18n/test/backend/chain/api_test.rb +80 -0
- data/lib/vendor/i18n/test/backend/chain/chain_test.rb +64 -0
- data/lib/vendor/i18n/test/backend/fallbacks/api_test.rb +79 -0
- data/lib/vendor/i18n/test/backend/fallbacks/fallbacks_test.rb +29 -0
- data/lib/vendor/i18n/test/backend/pluralization/api_test.rb +81 -0
- data/lib/vendor/i18n/test/backend/pluralization/pluralization_test.rb +39 -0
- data/lib/vendor/i18n/test/backend/simple/all.rb +5 -0
- data/lib/vendor/i18n/test/backend/simple/api_test.rb +90 -0
- data/lib/vendor/i18n/test/backend/simple/lookup_test.rb +24 -0
- data/lib/vendor/i18n/test/backend/simple/setup.rb +147 -0
- data/lib/vendor/i18n/test/backend/simple/translations_test.rb +89 -0
- data/lib/vendor/i18n/test/fixtures/locales/de.po +61 -0
- data/lib/vendor/i18n/test/fixtures/locales/en.rb +3 -0
- data/lib/vendor/i18n/test/fixtures/locales/en.yml +3 -0
- data/lib/vendor/i18n/test/fixtures/locales/plurals.rb +112 -0
- data/lib/vendor/i18n/test/gettext/api_test.rb +78 -0
- data/lib/vendor/i18n/test/gettext/backend_test.rb +35 -0
- data/lib/vendor/i18n/test/i18n_exceptions_test.rb +97 -0
- data/lib/vendor/i18n/test/i18n_load_path_test.rb +23 -0
- data/lib/vendor/i18n/test/i18n_test.rb +163 -0
- data/lib/vendor/i18n/test/locale/fallbacks_test.rb +128 -0
- data/lib/vendor/i18n/test/locale/tag/rfc4646_test.rb +147 -0
- data/lib/vendor/i18n/test/locale/tag/simple_test.rb +35 -0
- data/lib/vendor/i18n/test/string_test.rb +94 -0
- data/lib/vendor/i18n/test/test_helper.rb +71 -0
- data/lib/vendor/i18n/test/with_options.rb +34 -0
- data/lib/vendor/i18n/vendor/po_parser.rb +329 -0
- data/spec/fixtures/en.yml +4 -0
- data/spec/fixtures/pl.yml +4 -0
- data/spec/i18n/locale/datetime_spec.rb +91 -0
- data/spec/i18n/locale/pluralization_spec.rb +41 -0
- data/spec/locale_spec.rb +124 -0
- data/spec/polish_spec.rb +141 -0
- data/spec/spec_helper.rb +4 -0
- metadata +138 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Tests
|
|
4
|
+
module Backend
|
|
5
|
+
module Api
|
|
6
|
+
module Localization
|
|
7
|
+
module Time
|
|
8
|
+
# TODO should be Mrz, shouldn't it?
|
|
9
|
+
def test_localize_given_the_short_format_it_uses_it
|
|
10
|
+
assert_equal '01. Mar 06:00', I18n.backend.localize('de', morning_time, :short)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_localize_given_the_long_format_it_uses_it
|
|
14
|
+
assert_equal '01. März 2008 06:00', I18n.backend.localize('de', morning_time, :long)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
|
|
18
|
+
# def test_localize_given_the_default_format_it_uses_it
|
|
19
|
+
# assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.backend.localize('de', morning_time, :default)
|
|
20
|
+
# end
|
|
21
|
+
|
|
22
|
+
def test_localize_given_a_day_name_format_it_returns_the_correct_day_name
|
|
23
|
+
assert_equal 'Samstag', I18n.backend.localize('de', morning_time, '%A')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_localize_given_an_abbr_day_name_format_it_returns_the_correct_abbrevated_day_name
|
|
27
|
+
assert_equal 'Sa', I18n.backend.localize('de', morning_time, '%a')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_localize_given_a_month_name_format_it_returns_the_correct_month_name
|
|
31
|
+
assert_equal 'März', I18n.backend.localize('de', morning_time, '%B')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# TODO should be Mrz, shouldn't it?
|
|
35
|
+
def test_localize_given_an_abbr_month_name_format_it_returns_the_correct_abbrevated_month_name
|
|
36
|
+
assert_equal 'Mar', I18n.backend.localize('de', morning_time, '%b')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_localize_given_a_meridian_indicator_format_it_returns_the_correct_meridian_indicator
|
|
40
|
+
assert_equal 'am', I18n.backend.localize('de', morning_time, '%p')
|
|
41
|
+
assert_equal 'pm', I18n.backend.localize('de', evening_time, '%p')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_localize_given_a_format_specified_as_a_proc
|
|
45
|
+
assert_equal '1ter März 2008, 06:00 Uhr', I18n.backend.localize('de', morning_time, :long_ordinalized)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_localize_given_a_format_specified_as_a_proc_with_additional_options
|
|
49
|
+
assert_equal '1ter März 2008, 06:00 Uhr (MEZ)', I18n.backend.localize('de', morning_time, :long_ordinalized, :timezone => 'MEZ')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_localize_given_no_format_it_does_not_fail
|
|
53
|
+
assert_nothing_raised{ I18n.backend.localize 'de', morning_time }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_localize_given_an_unknown_format_it_does_not_fail
|
|
57
|
+
assert_nothing_raised{ I18n.backend.localize 'de', morning_time, '%x' }
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Tests
|
|
4
|
+
module Backend
|
|
5
|
+
module Api
|
|
6
|
+
module Pluralization
|
|
7
|
+
def test_pluralize_given_0_returns_zero_string_if_zero_key_given
|
|
8
|
+
assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_pluralize_given_0_returns_plural_string_if_no_zero_key_given
|
|
12
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_pluralize_given_1_returns_singular_string
|
|
16
|
+
assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_pluralize_given_2_returns_plural_string
|
|
20
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_pluralize_given_3_returns_plural_string
|
|
24
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_pluralize_given_nil_returns_the_given_entry
|
|
28
|
+
assert_equal({ :zero => 'zero' }, I18n.t(:default => { :zero => 'zero' }, :count => nil))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_interpolate_given_incomplete_pluralization_data_raises_invalid_pluralization_data
|
|
32
|
+
assert_raises(I18n::InvalidPluralizationData){ I18n.t(:default => { :one => 'bar' }, :count => 2) }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Tests
|
|
4
|
+
module Backend
|
|
5
|
+
module Api
|
|
6
|
+
module Translation
|
|
7
|
+
def translate(key, options = {})
|
|
8
|
+
I18n.backend.translate('en', key, options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_given_no_keys_it_returns_the_default
|
|
12
|
+
assert_equal 'default', translate(nil, :default => 'default')
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_translate_given_a_symbol_as_a_default_translates_the_symbol
|
|
16
|
+
assert_equal 'bar', translate(nil, :default => :'foo.bar')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_translate_default_with_scope_stays_in_scope_when_looking_up_the_symbol
|
|
20
|
+
assert_equal 'bar', translate(:missing, :default => :bar, :scope => :foo)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_translate_given_an_array_as_default_uses_the_first_match
|
|
24
|
+
assert_equal 'bar', translate(:does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
|
|
28
|
+
assert_raises I18n::MissingTranslationData do
|
|
29
|
+
translate(:does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_translate_an_array_of_keys_translates_all_of_them
|
|
34
|
+
assert_equal %w(bar baz), translate([:bar, :baz], :scope => [:foo])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_translate_with_a_missing_key_and_no_default_raises_missing_translation_data
|
|
38
|
+
assert_raises(I18n::MissingTranslationData) do
|
|
39
|
+
translate(:missing)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_translate_given_nil_as_a_locale_raises_an_argument_error
|
|
44
|
+
assert_raises(I18n::InvalidLocale) do
|
|
45
|
+
I18n.backend.translate(nil, :bar)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
4
|
+
require 'i18n/backend/cache'
|
|
5
|
+
require 'activesupport'
|
|
6
|
+
|
|
7
|
+
class I18nCacheBackendTest < Test::Unit::TestCase
|
|
8
|
+
def setup
|
|
9
|
+
super
|
|
10
|
+
I18n.backend.meta_class.send(:include, I18n::Backend::Cache)
|
|
11
|
+
I18n.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def teardown
|
|
15
|
+
I18n.cache_store = nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_uses_cache
|
|
19
|
+
assert I18n.cache_store.is_a?(ActiveSupport::Cache::MemoryStore)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
define_method :"test translate hits the backend and caches the response" do
|
|
23
|
+
I18n.backend.expects(:lookup).returns('Foo')
|
|
24
|
+
assert_equal 'Foo', I18n.t(:foo)
|
|
25
|
+
|
|
26
|
+
I18n.backend.expects(:lookup).never
|
|
27
|
+
assert_equal 'Foo', I18n.t(:foo)
|
|
28
|
+
|
|
29
|
+
I18n.backend.expects(:lookup).returns('Bar')
|
|
30
|
+
assert_equal 'Bar', I18n.t(:bar)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
define_method :"test still raises MissingTranslationData but also caches it" do
|
|
34
|
+
I18n.backend.expects(:lookup).returns(nil)
|
|
35
|
+
assert_raises(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
|
|
36
|
+
I18n.backend.expects(:lookup).never
|
|
37
|
+
assert_raises(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
define_method :"test uses 'i18n' as a cache key namespace by default" do
|
|
41
|
+
assert_equal 0, I18n.backend.send(:cache_key, :foo).index('i18n')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
define_method :"test adds a custom cache key namespace" do
|
|
45
|
+
with_cache_namespace('bar') do
|
|
46
|
+
assert_equal 0, I18n.backend.send(:cache_key, :foo).index('i18n-bar')
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
protected
|
|
51
|
+
|
|
52
|
+
def with_cache_namespace(namespace)
|
|
53
|
+
I18n.cache_namespace = namespace
|
|
54
|
+
yield
|
|
55
|
+
I18n.cache_namespace = nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
4
|
+
require 'i18n/backend/chain'
|
|
5
|
+
|
|
6
|
+
module ChainSetup
|
|
7
|
+
def setup
|
|
8
|
+
super
|
|
9
|
+
first = I18n::Backend::Simple.new
|
|
10
|
+
I18n.backend = I18n::Backend::Chain.new(first, I18n.backend)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_using_chain_backend
|
|
14
|
+
assert_equal I18n::Backend::Chain, I18n.backend.class
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class I18nChainBackendApiBasicsTest < Test::Unit::TestCase
|
|
19
|
+
include ChainSetup
|
|
20
|
+
include Tests::Backend::Api::Basics
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class I18nChainBackendApiTranslateTest < Test::Unit::TestCase
|
|
24
|
+
include Tests::Backend::Simple::Setup::Base
|
|
25
|
+
include ChainSetup
|
|
26
|
+
include Tests::Backend::Api::Translation
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class I18nChainBackendApiInterpolateTest < Test::Unit::TestCase
|
|
30
|
+
include Tests::Backend::Simple::Setup::Base
|
|
31
|
+
include ChainSetup
|
|
32
|
+
include Tests::Backend::Api::Interpolation
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class I18nChainBackendApiLambdaTest < Test::Unit::TestCase
|
|
36
|
+
include Tests::Backend::Simple::Setup::Base
|
|
37
|
+
include ChainSetup
|
|
38
|
+
include Tests::Backend::Api::Lambda
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class I18nChainBackendApiTranslateLinkedTest < Test::Unit::TestCase
|
|
42
|
+
include Tests::Backend::Simple::Setup::Base
|
|
43
|
+
include ChainSetup
|
|
44
|
+
include Tests::Backend::Api::Link
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class I18nChainBackendApiPluralizationTest < Test::Unit::TestCase
|
|
48
|
+
include Tests::Backend::Simple::Setup::Base
|
|
49
|
+
include ChainSetup
|
|
50
|
+
include Tests::Backend::Api::Pluralization
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class I18nChainBackendApiLocalizeDateTest < Test::Unit::TestCase
|
|
54
|
+
include Tests::Backend::Simple::Setup::Base
|
|
55
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
56
|
+
include ChainSetup
|
|
57
|
+
include Tests::Backend::Api::Localization::Date
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class I18nChainBackendApiLocalizeDateTimeTest < Test::Unit::TestCase
|
|
61
|
+
include Tests::Backend::Simple::Setup::Base
|
|
62
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
63
|
+
include ChainSetup
|
|
64
|
+
include Tests::Backend::Api::Localization::DateTime
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class I18nChainBackendApiLocalizeTimeTest < Test::Unit::TestCase
|
|
68
|
+
include Tests::Backend::Simple::Setup::Base
|
|
69
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
70
|
+
include ChainSetup
|
|
71
|
+
include Tests::Backend::Api::Localization::Time
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class I18nChainBackendApiLocalizeLambdaTest < Test::Unit::TestCase
|
|
75
|
+
include Tests::Backend::Simple::Setup::Base
|
|
76
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
77
|
+
include ChainSetup
|
|
78
|
+
include Tests::Backend::Api::Localization::Lambda
|
|
79
|
+
end
|
|
80
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
4
|
+
require 'i18n/backend/chain'
|
|
5
|
+
|
|
6
|
+
class I18nChainBackendTest < Test::Unit::TestCase
|
|
7
|
+
def setup
|
|
8
|
+
@first = backend(:en => {
|
|
9
|
+
:foo => 'Foo', :formats => { :short => 'short' }, :plural_1 => { :one => '{{count}}' }
|
|
10
|
+
})
|
|
11
|
+
@second = backend(:en => {
|
|
12
|
+
:bar => 'Bar', :formats => { :long => 'long' }, :plural_2 => { :one => 'one' }
|
|
13
|
+
})
|
|
14
|
+
@chain = I18n.backend = I18n::Backend::Chain.new(@first, @second)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
define_method "test: looks up translations from the first chained backend" do
|
|
18
|
+
assert_equal 'Foo', @first.send(:translations)[:en][:foo]
|
|
19
|
+
assert_equal 'Foo', I18n.t(:foo)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
define_method "test: looks up translations from the second chained backend" do
|
|
23
|
+
assert_equal 'Bar', @second.send(:translations)[:en][:bar]
|
|
24
|
+
assert_equal 'Bar', I18n.t(:bar)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
define_method "test: defaults only apply to lookups on the last backend in the chain" do
|
|
28
|
+
assert_equal 'Foo', I18n.t(:foo, :default => 'Bah')
|
|
29
|
+
assert_equal 'Bar', I18n.t(:bar, :default => 'Bah')
|
|
30
|
+
assert_equal 'Bah', I18n.t(:bah, :default => 'Bah') # default kicks in only here
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
define_method "test: default" do
|
|
34
|
+
assert_equal 'Fuh', I18n.t(:default => 'Fuh')
|
|
35
|
+
assert_equal 'Zero', I18n.t(:default => { :zero => 'Zero' }, :count => 0)
|
|
36
|
+
assert_equal({ :zero => 'Zero' }, I18n.t(:default => { :zero => 'Zero' }))
|
|
37
|
+
assert_equal 'Foo', I18n.t(:default => :foo)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
define_method "test: namespace lookup collects results from all backends" do
|
|
41
|
+
assert_equal({ :short => 'short', :long => 'long' }, I18n.t(:formats))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
define_method "test: namespace lookup with only the first backend returning a result" do
|
|
45
|
+
assert_equal({ :one => '{{count}}' }, I18n.t(:plural_1))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
define_method "test: pluralization still works" do
|
|
49
|
+
assert_equal '1', I18n.t(:plural_1, :count => 1)
|
|
50
|
+
assert_equal 'one', I18n.t(:plural_2, :count => 1)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
define_method "test: bulk lookup collects results from all backends" do
|
|
54
|
+
assert_equal ['Foo', 'Bar'], I18n.t([:foo, :bar])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
protected
|
|
58
|
+
|
|
59
|
+
def backend(translations)
|
|
60
|
+
backend = I18n::Backend::Simple.new
|
|
61
|
+
translations.each { |locale, translations| backend.store_translations(locale, translations) }
|
|
62
|
+
backend
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
4
|
+
require 'i18n/backend/fallbacks'
|
|
5
|
+
|
|
6
|
+
module FallbacksSetup
|
|
7
|
+
def setup
|
|
8
|
+
super
|
|
9
|
+
I18n.backend.meta_class.send(:include, I18n::Backend::Fallbacks)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_uses_fallbacks
|
|
13
|
+
assert I18n.backend.meta_class.included_modules.include?(I18n::Backend::Fallbacks)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class I18nFallbacksBackendApiBasicsTest < Test::Unit::TestCase
|
|
18
|
+
include FallbacksSetup
|
|
19
|
+
include Tests::Backend::Api::Basics
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class I18nFallbacksBackendApiTranslateTest < Test::Unit::TestCase
|
|
23
|
+
include Tests::Backend::Simple::Setup::Base
|
|
24
|
+
include FallbacksSetup
|
|
25
|
+
include Tests::Backend::Api::Translation
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class I18nFallbacksBackendApiInterpolateTest < Test::Unit::TestCase
|
|
29
|
+
include Tests::Backend::Simple::Setup::Base
|
|
30
|
+
include FallbacksSetup
|
|
31
|
+
include Tests::Backend::Api::Interpolation
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class I18nFallbacksBackendApiLambdaTest < Test::Unit::TestCase
|
|
35
|
+
include Tests::Backend::Simple::Setup::Base
|
|
36
|
+
include FallbacksSetup
|
|
37
|
+
include Tests::Backend::Api::Lambda
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class I18nFallbacksBackendApiTranslateLinkedTest < Test::Unit::TestCase
|
|
41
|
+
include Tests::Backend::Simple::Setup::Base
|
|
42
|
+
include FallbacksSetup
|
|
43
|
+
include Tests::Backend::Api::Link
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class I18nFallbacksBackendApiPluralizationTest < Test::Unit::TestCase
|
|
47
|
+
include Tests::Backend::Simple::Setup::Base
|
|
48
|
+
include FallbacksSetup
|
|
49
|
+
include Tests::Backend::Api::Pluralization
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class I18nFallbacksBackendApiLocalizeDateTest < Test::Unit::TestCase
|
|
53
|
+
include Tests::Backend::Simple::Setup::Base
|
|
54
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
55
|
+
include FallbacksSetup
|
|
56
|
+
include Tests::Backend::Api::Localization::Date
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class I18nFallbacksBackendApiLocalizeDateTimeTest < Test::Unit::TestCase
|
|
60
|
+
include Tests::Backend::Simple::Setup::Base
|
|
61
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
62
|
+
include FallbacksSetup
|
|
63
|
+
include Tests::Backend::Api::Localization::DateTime
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class I18nFallbacksBackendApiLocalizeTimeTest < Test::Unit::TestCase
|
|
67
|
+
include Tests::Backend::Simple::Setup::Base
|
|
68
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
69
|
+
include FallbacksSetup
|
|
70
|
+
include Tests::Backend::Api::Localization::Time
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class I18nFallbacksBackendApiLocalizeLambdaTest < Test::Unit::TestCase
|
|
74
|
+
include Tests::Backend::Simple::Setup::Base
|
|
75
|
+
include Tests::Backend::Simple::Setup::Localization
|
|
76
|
+
include FallbacksSetup
|
|
77
|
+
include Tests::Backend::Api::Localization::Lambda
|
|
78
|
+
end
|
|
79
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
4
|
+
require 'i18n/backend/fallbacks'
|
|
5
|
+
|
|
6
|
+
class I18nFallbacksBackendTest < Test::Unit::TestCase
|
|
7
|
+
def setup
|
|
8
|
+
I18n.backend = I18n::Backend::Simple.new
|
|
9
|
+
I18n.backend.meta_class.send(:include, I18n::Backend::Fallbacks)
|
|
10
|
+
backend_store_translations(:en, :foo => 'Foo')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
define_method "test: fallbacks for :de are [:de, :en]" do
|
|
14
|
+
assert_equal [:de, :en], I18n.fallbacks[:de]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
define_method "test: still returns the English translation as usual" do
|
|
18
|
+
assert_equal 'Foo', I18n.t(:foo, :locale => :en)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
define_method "test: returns the English translation for a missing German translation" do
|
|
22
|
+
assert_equal 'Foo', I18n.t(:foo, :locale => :de)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
define_method "test: raises I18n::MissingTranslationData exception when no translation was found" do
|
|
26
|
+
assert_raises(I18n::MissingTranslationData) { I18n.t(:bar, :locale => :en, :raise => true) }
|
|
27
|
+
assert_raises(I18n::MissingTranslationData) { I18n.t(:bar, :locale => :de, :raise => true) }
|
|
28
|
+
end
|
|
29
|
+
end
|