polish 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,128 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
4
|
+
require 'i18n/locale/fallbacks'
|
5
|
+
require 'i18n/locale/tag'
|
6
|
+
|
7
|
+
include I18n::Locale
|
8
|
+
|
9
|
+
class I18nFallbacksDefaultsTest < Test::Unit::TestCase
|
10
|
+
def teardown
|
11
|
+
I18n.default_locale = :en
|
12
|
+
end
|
13
|
+
|
14
|
+
test "defaults reflect the I18n.default_locale if no default has been set manually" do
|
15
|
+
I18n.default_locale = :'en-US'
|
16
|
+
I18n.fallbacks = Fallbacks.new
|
17
|
+
assert_equal [:'en-US', :en], I18n.fallbacks.defaults
|
18
|
+
end
|
19
|
+
|
20
|
+
test "defaults reflect a manually passed default locale if any" do
|
21
|
+
I18n.fallbacks = Fallbacks.new(:'fi-FI')
|
22
|
+
assert_equal [:'fi-FI', :fi], I18n.fallbacks.defaults
|
23
|
+
I18n.default_locale = :'de-DE'
|
24
|
+
assert_equal [:'fi-FI', :fi], I18n.fallbacks.defaults
|
25
|
+
end
|
26
|
+
|
27
|
+
test "defaults allows to set multiple defaults" do
|
28
|
+
I18n.fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
|
29
|
+
assert_equal [:'fi-FI', :fi, :'se-FI', :se], I18n.fallbacks.defaults
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class I18nFallbacksComputationTest < Test::Unit::TestCase
|
34
|
+
def setup
|
35
|
+
@fallbacks = Fallbacks.new(:'en-US')
|
36
|
+
end
|
37
|
+
|
38
|
+
test "with no mappings defined it returns [:es, :en-US] for :es" do
|
39
|
+
assert_equal [:es, :"en-US", :en], @fallbacks[:es]
|
40
|
+
end
|
41
|
+
|
42
|
+
test "with no mappings defined it returns [:es-ES, :es, :en-US] for :es-ES" do
|
43
|
+
assert_equal [:"es-ES", :es, :"en-US", :en], @fallbacks[:"es-ES"]
|
44
|
+
end
|
45
|
+
|
46
|
+
test "with no mappings defined it returns [:es-MX, :es, :en-US] for :es-MX" do
|
47
|
+
assert_equal [:"es-MX", :es, :"en-US", :en], @fallbacks[:"es-MX"]
|
48
|
+
end
|
49
|
+
|
50
|
+
test "with no mappings defined it returns [:es-Latn-ES, :es-Latn, :es, :en-US] for :es-Latn-ES" do
|
51
|
+
assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en], @fallbacks[:'es-Latn-ES']
|
52
|
+
end
|
53
|
+
|
54
|
+
test "with no mappings defined it returns [:en, :en-US] for :en" do
|
55
|
+
assert_equal [:en, :"en-US"], @fallbacks[:en]
|
56
|
+
end
|
57
|
+
|
58
|
+
test "with no mappings defined it returns [:en-US, :en] for :en-US (special case: locale == default)" do
|
59
|
+
assert_equal [:"en-US", :en], @fallbacks[:"en-US"]
|
60
|
+
end
|
61
|
+
|
62
|
+
# Most people who speak Catalan also live in Spain, so it is safe to assume
|
63
|
+
# that they also speak Spanish as spoken in Spain.
|
64
|
+
test "with a Catalan mapping defined it returns [:ca, :es-ES, :es, :en-US] for :ca" do
|
65
|
+
@fallbacks.map(:ca => :"es-ES")
|
66
|
+
assert_equal [:ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:ca]
|
67
|
+
end
|
68
|
+
|
69
|
+
test "with a Catalan mapping defined it returns [:ca-ES, :ca, :es-ES, :es, :en-US] for :ca-ES" do
|
70
|
+
@fallbacks.map(:ca => :"es-ES")
|
71
|
+
assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:"ca-ES"]
|
72
|
+
end
|
73
|
+
|
74
|
+
# People who speak Arabic as spoken in Palestine often times also speak
|
75
|
+
# Hebrew as spoken in Israel. However it is in no way safe to assume that
|
76
|
+
# everybody who speaks Arabic also speaks Hebrew.
|
77
|
+
|
78
|
+
test "with a Hebrew mapping defined it returns [:ar, :en-US] for :ar" do
|
79
|
+
@fallbacks.map(:"ar-PS" => :"he-IL")
|
80
|
+
assert_equal [:ar, :"en-US", :en], @fallbacks[:ar]
|
81
|
+
end
|
82
|
+
|
83
|
+
test "with a Hebrew mapping defined it returns [:ar-EG, :ar, :en-US] for :ar-EG" do
|
84
|
+
@fallbacks.map(:"ar-PS" => :"he-IL")
|
85
|
+
assert_equal [:"ar-EG", :ar, :"en-US", :en], @fallbacks[:"ar-EG"]
|
86
|
+
end
|
87
|
+
|
88
|
+
test "with a Hebrew mapping defined it returns [:ar-PS, :ar, :he-IL, :he, :en-US] for :ar-PS" do
|
89
|
+
@fallbacks.map(:"ar-PS" => :"he-IL")
|
90
|
+
assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en], @fallbacks[:"ar-PS"]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Sami people live in several scandinavian countries. In Finnland many people
|
94
|
+
# know Swedish and Finnish. Thus, it can be assumed that Sami living in
|
95
|
+
# Finnland also speak Swedish and Finnish.
|
96
|
+
|
97
|
+
test "with a Sami mapping defined it returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US] for :sms-FI" do
|
98
|
+
@fallbacks.map(:sms => [:"se-FI", :"fi-FI"])
|
99
|
+
assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en], @fallbacks[:"sms-FI"]
|
100
|
+
end
|
101
|
+
|
102
|
+
# Austrian people understand German as spoken in Germany
|
103
|
+
|
104
|
+
test "with a German mapping defined it returns [:de, :en-US] for de" do
|
105
|
+
@fallbacks.map(:"de-AT" => :"de-DE")
|
106
|
+
assert_equal [:de, :"en-US", :en], @fallbacks[:"de"]
|
107
|
+
end
|
108
|
+
|
109
|
+
test "with a German mapping defined it returns [:de-DE, :de, :en-US] for de-DE" do
|
110
|
+
@fallbacks.map(:"de-AT" => :"de-DE")
|
111
|
+
assert_equal [:"de-DE", :de, :"en-US", :en], @fallbacks[:"de-DE"]
|
112
|
+
end
|
113
|
+
|
114
|
+
test "with a German mapping defined it returns [:de-AT, :de, :de-DE, :en-US] for de-AT" do
|
115
|
+
@fallbacks.map(:"de-AT" => :"de-DE")
|
116
|
+
assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en], @fallbacks[:"de-AT"]
|
117
|
+
end
|
118
|
+
|
119
|
+
# Mapping :de => :en, :he => :en
|
120
|
+
|
121
|
+
test "with a mapping :de => :en, :he => :en defined it returns [:de, :en] for :de" do
|
122
|
+
assert_equal [:de, :"en-US", :en], @fallbacks[:de]
|
123
|
+
end
|
124
|
+
|
125
|
+
test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
|
126
|
+
assert_equal [:he, :"en-US", :en], @fallbacks[:he]
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
4
|
+
require 'i18n/locale/tag'
|
5
|
+
require 'i18n/locale/tag/rfc4646'
|
6
|
+
|
7
|
+
# Rfc4646::Parser
|
8
|
+
|
9
|
+
class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase
|
10
|
+
include I18n::Locale
|
11
|
+
|
12
|
+
test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
|
13
|
+
assert_equal ['de', nil, nil, nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de')
|
14
|
+
end
|
15
|
+
|
16
|
+
test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
|
17
|
+
assert_equal ['de', nil, 'DE', nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de-DE')
|
18
|
+
end
|
19
|
+
|
20
|
+
test "Rfc4646::Parser given a valid lowercase tag 'de-latn-de-variant-x-phonebk' returns an array of subtags" do
|
21
|
+
assert_equal ['de', 'latn', 'de', 'variant', nil, 'x-phonebk', nil], Tag::Rfc4646::Parser.match('de-latn-de-variant-x-phonebk')
|
22
|
+
end
|
23
|
+
|
24
|
+
test "Rfc4646::Parser given a valid uppercase tag 'DE-LATN-DE-VARIANT-X-PHONEBK' returns an array of subtags" do
|
25
|
+
assert_equal ['DE', 'LATN', 'DE', 'VARIANT', nil, 'X-PHONEBK', nil], Tag::Rfc4646::Parser.match('DE-LATN-DE-VARIANT-X-PHONEBK')
|
26
|
+
end
|
27
|
+
|
28
|
+
test "Rfc4646::Parser given an invalid tag 'a-DE' it returns false" do
|
29
|
+
assert_equal false, Tag::Rfc4646::Parser.match('a-DE')
|
30
|
+
end
|
31
|
+
|
32
|
+
test "Rfc4646::Parser given an invalid tag 'de-419-DE' it returns false" do
|
33
|
+
assert_equal false, Tag::Rfc4646::Parser.match('de-419-DE')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Tag for the locale 'de-Latn-DE-Variant-a-ext-x-phonebk-i-klingon'
|
38
|
+
|
39
|
+
class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
|
40
|
+
include I18n::Locale
|
41
|
+
|
42
|
+
def setup
|
43
|
+
subtags = %w(de Latn DE variant a-ext x-phonebk i-klingon)
|
44
|
+
@tag = Tag::Rfc4646.new *subtags
|
45
|
+
end
|
46
|
+
|
47
|
+
test "returns 'de' as the language subtag in lowercase" do
|
48
|
+
assert_equal 'de', @tag.language
|
49
|
+
end
|
50
|
+
|
51
|
+
test "returns 'Latn' as the script subtag in titlecase" do
|
52
|
+
assert_equal 'Latn', @tag.script
|
53
|
+
end
|
54
|
+
|
55
|
+
test "returns 'DE' as the region subtag in uppercase" do
|
56
|
+
assert_equal 'DE', @tag.region
|
57
|
+
end
|
58
|
+
|
59
|
+
test "returns 'variant' as the variant subtag in lowercase" do
|
60
|
+
assert_equal 'variant', @tag.variant
|
61
|
+
end
|
62
|
+
|
63
|
+
test "returns 'a-ext' as the extension subtag" do
|
64
|
+
assert_equal 'a-ext', @tag.extension
|
65
|
+
end
|
66
|
+
|
67
|
+
test "returns 'x-phonebk' as the privateuse subtag" do
|
68
|
+
assert_equal 'x-phonebk', @tag.privateuse
|
69
|
+
end
|
70
|
+
|
71
|
+
test "returns 'i-klingon' as the grandfathered subtag" do
|
72
|
+
assert_equal 'i-klingon', @tag.grandfathered
|
73
|
+
end
|
74
|
+
|
75
|
+
test "returns a formatted tag string from #to_s" do
|
76
|
+
assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon', @tag.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
test "returns an array containing the formatted subtags from #to_a" do
|
80
|
+
assert_equal %w(de Latn DE variant a-ext x-phonebk i-klingon), @tag.to_a
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Tag inheritance
|
85
|
+
|
86
|
+
class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
|
87
|
+
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
|
88
|
+
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
|
89
|
+
assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk', tag.parent.to_s
|
90
|
+
end
|
91
|
+
|
92
|
+
test "#parent returns 'de-Latn-DE-variant-a-ext' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk'" do
|
93
|
+
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk)
|
94
|
+
assert_equal 'de-Latn-DE-variant-a-ext', tag.parent.to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
test "#parent returns 'de-Latn-DE-variant' as the parent of 'de-Latn-DE-variant-a-ext'" do
|
98
|
+
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext)
|
99
|
+
assert_equal 'de-Latn-DE-variant', tag.parent.to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
test "#parent returns 'de-Latn-DE' as the parent of 'de-Latn-DE-variant'" do
|
103
|
+
tag = Tag::Rfc4646.new *%w(de Latn DE variant)
|
104
|
+
assert_equal 'de-Latn-DE', tag.parent.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
|
108
|
+
tag = Tag::Rfc4646.new *%w(de Latn DE)
|
109
|
+
assert_equal 'de-Latn', tag.parent.to_s
|
110
|
+
end
|
111
|
+
|
112
|
+
test "#parent returns 'de' as the parent of 'de-Latn'" do
|
113
|
+
tag = Tag::Rfc4646.new *%w(de Latn)
|
114
|
+
assert_equal 'de', tag.parent.to_s
|
115
|
+
end
|
116
|
+
|
117
|
+
# TODO RFC4647 says: "If no language tag matches the request, the "default" value is returned."
|
118
|
+
# where should we set the default language?
|
119
|
+
# test "#parent returns '' as the parent of 'de'" do
|
120
|
+
# tag = Tag::Rfc4646.new *%w(de)
|
121
|
+
# assert_equal '', tag.parent.to_s
|
122
|
+
# end
|
123
|
+
|
124
|
+
test "#parent returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
|
125
|
+
parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
|
126
|
+
de-Latn-DE-variant-a-ext-x-phonebk
|
127
|
+
de-Latn-DE-variant-a-ext
|
128
|
+
de-Latn-DE-variant
|
129
|
+
de-Latn-DE
|
130
|
+
de-Latn
|
131
|
+
de)
|
132
|
+
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
|
133
|
+
assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
|
134
|
+
end
|
135
|
+
|
136
|
+
test "returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
|
137
|
+
parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
|
138
|
+
de-Latn-DE-variant-a-ext-x-phonebk
|
139
|
+
de-Latn-DE-variant-a-ext
|
140
|
+
de-Latn-DE-variant
|
141
|
+
de-Latn-DE
|
142
|
+
de-Latn
|
143
|
+
de)
|
144
|
+
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
|
145
|
+
assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../test_helper.rb'
|
4
|
+
require 'i18n/locale/tag'
|
5
|
+
require 'i18n/locale/tag/simple'
|
6
|
+
|
7
|
+
class I18nLocaleTagSimpleTest < Test::Unit::TestCase
|
8
|
+
include I18n::Locale
|
9
|
+
|
10
|
+
test "returns 'de' as the language subtag in lowercase" do
|
11
|
+
assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').subtags
|
12
|
+
end
|
13
|
+
|
14
|
+
test "returns a formatted tag string from #to_s" do
|
15
|
+
assert_equal 'de-Latn-DE', Tag::Simple.new('de-Latn-DE').to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
test "returns an array containing the formatted subtags from #to_a" do
|
19
|
+
assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').to_a
|
20
|
+
end
|
21
|
+
|
22
|
+
# Tag inheritance
|
23
|
+
|
24
|
+
test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
|
25
|
+
assert_equal 'de-Latn', Tag::Simple.new('de-Latn-DE').parent.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
test "#parent returns 'de' as the parent of 'de-Latn'" do
|
29
|
+
assert_equal 'de', Tag::Simple.new('de-Latn').parent.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
test "#self_and_parents returns an array of 3 tags for 'de-Latn-DE'" do
|
33
|
+
assert_equal %w(de-Latn-DE de-Latn de), Tag::Simple.new('de-Latn-DE').self_and_parents.map { |tag| tag.to_s}
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
4
|
+
|
5
|
+
# thanks to Masao's String extensions these should work the same in
|
6
|
+
# Ruby 1.8 (patched) and Ruby 1.9 (native)
|
7
|
+
# some tests taken from Masao's tests
|
8
|
+
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
|
9
|
+
|
10
|
+
class I18nStringTest < Test::Unit::TestCase
|
11
|
+
define_method :"test: String interpolates a single argument" do
|
12
|
+
assert_equal "Masao", "%s" % "Masao"
|
13
|
+
end
|
14
|
+
|
15
|
+
define_method :"test: String interpolates an array argument" do
|
16
|
+
assert_equal "1 message", "%d %s" % [1, 'message']
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method :"test: String interpolates a hash argument w/ named placeholders" do
|
20
|
+
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh' }
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method :"test: String interpolates a hash argument w/ named placeholders (reverse order)" do
|
24
|
+
assert_equal "Mutoh, Masao", "%{last}, %{first}" % { :first => 'Masao', :last => 'Mutoh' }
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method :"test: String interpolates named placeholders with sprintf syntax" do
|
28
|
+
assert_equal "10, 43.4", "%<integer>d, %<float>.1f" % {:integer => 10, :float => 43.4}
|
29
|
+
end
|
30
|
+
|
31
|
+
define_method :"test: String interpolates named placeholders with sprintf syntax, does not recurse" do
|
32
|
+
assert_equal "%<not_translated>s", "%{msg}" % { :msg => '%<not_translated>s', :not_translated => 'should not happen' }
|
33
|
+
end
|
34
|
+
|
35
|
+
define_method :"test: String interpolation does not replace anything when no placeholders are given" do
|
36
|
+
assert_equal("aaa", "aaa" % {:num => 1})
|
37
|
+
assert_equal("bbb", "bbb" % [1])
|
38
|
+
end
|
39
|
+
|
40
|
+
define_method :"test: String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
|
41
|
+
assert_equal("1", "%<num>d" % {:num => 1})
|
42
|
+
assert_equal("0b1", "%<num>#b" % {:num => 1})
|
43
|
+
assert_equal("foo", "%<msg>s" % {:msg => "foo"})
|
44
|
+
assert_equal("1.000000", "%<num>f" % {:num => 1.0})
|
45
|
+
assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
|
46
|
+
assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
|
47
|
+
assert_equal("0x64", "%<num>#x" % {:num => 100.0})
|
48
|
+
assert_raise(ArgumentError) { "%<num>,d" % {:num => 100} }
|
49
|
+
assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
|
50
|
+
end
|
51
|
+
|
52
|
+
define_method :"test: String interpolation old-style sprintf still works" do
|
53
|
+
assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0])
|
54
|
+
end
|
55
|
+
|
56
|
+
define_method :"test: String interpolation raises an ArgumentError when the string has extra placeholders (Array)" do
|
57
|
+
assert_raises(ArgumentError) do # Ruby 1.9 msg: "too few arguments"
|
58
|
+
"%s %s" % %w(Masao)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
define_method :"test: String interpolation raises a KeyError when the string has extra placeholders (Hash)" do
|
63
|
+
assert_raises(KeyError) do # Ruby 1.9 msg: "key not found"
|
64
|
+
"%{first} %{last}" % { :first => 'Masao' }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
define_method :"test: String interpolation does not raise when passed extra values (Array)" do
|
69
|
+
assert_nothing_raised do
|
70
|
+
assert_equal "Masao", "%s" % %w(Masao Mutoh)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
define_method :"test: String interpolation does not raise when passed extra values (Hash)" do
|
75
|
+
assert_nothing_raised do
|
76
|
+
assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
define_method :"test: % acts as escape character in String interpolation" do
|
81
|
+
assert_equal "%{first}", "%%{first}" % { :first => 'Masao' }
|
82
|
+
assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
|
83
|
+
assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_sprintf_mix_unformatted_and_formatted_named_placeholders
|
87
|
+
assert_equal("foo 1.000000", "%{name} %<num>f" % {:name => "foo", :num => 1.0})
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders
|
91
|
+
assert_raises(ArgumentError) { "%{name} %f" % [1.0] }
|
92
|
+
assert_raises(ArgumentError) { "%{name} %f" % [1.0, 2.0] }
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
+
|
15
|
+
Dir[File.dirname(__FILE__) + '/api/**/*.rb'].each do |filename|
|
16
|
+
require filename
|
17
|
+
end
|
18
|
+
|
19
|
+
$KCODE = 'u' unless RUBY_VERSION >= '1.9'
|
20
|
+
|
21
|
+
class Test::Unit::TestCase
|
22
|
+
def self.test(name, &block)
|
23
|
+
define_method("test: " + name, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def euc_jp(string)
|
27
|
+
string.encode!(Encoding::EUC_JP)
|
28
|
+
end
|
29
|
+
|
30
|
+
def locales_dir
|
31
|
+
File.dirname(__FILE__) + '/fixtures/locales'
|
32
|
+
end
|
33
|
+
|
34
|
+
def backend_store_translations(*args)
|
35
|
+
I18n.backend.store_translations(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def backend_get_translations
|
39
|
+
I18n.backend.instance_variable_get :@translations
|
40
|
+
end
|
41
|
+
|
42
|
+
def date
|
43
|
+
Date.new(2008, 3, 1)
|
44
|
+
end
|
45
|
+
|
46
|
+
def morning_datetime
|
47
|
+
DateTime.new(2008, 3, 1, 6)
|
48
|
+
end
|
49
|
+
alias :datetime :morning_datetime
|
50
|
+
|
51
|
+
def evening_datetime
|
52
|
+
DateTime.new(2008, 3, 1, 18)
|
53
|
+
end
|
54
|
+
|
55
|
+
def morning_time
|
56
|
+
Time.parse('2008-03-01 6:00 UTC')
|
57
|
+
end
|
58
|
+
alias :time :morning_time
|
59
|
+
|
60
|
+
def evening_time
|
61
|
+
Time.parse('2008-03-01 18:00 UTC')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Object
|
66
|
+
def meta_class
|
67
|
+
class << self; self; end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|