twitter_cldr 1.2.0 → 1.3.0
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/README.md +34 -18
- data/lib/twitter_cldr.rb +15 -21
- data/lib/twitter_cldr/core_ext.rb +2 -1
- data/lib/twitter_cldr/core_ext/array.rb +22 -0
- data/lib/twitter_cldr/core_ext/numbers/localized_number.rb +0 -1
- data/lib/twitter_cldr/core_ext/string.rb +10 -2
- data/lib/twitter_cldr/formatters/calendars/datetime_formatter.rb +4 -1
- data/lib/twitter_cldr/formatters/numbers/currency_formatter.rb +7 -2
- data/lib/twitter_cldr/formatters/numbers/decimal_formatter.rb +5 -1
- data/lib/twitter_cldr/formatters/numbers/number_formatter.rb +1 -1
- data/lib/twitter_cldr/formatters/numbers/percent_formatter.rb +5 -3
- data/lib/twitter_cldr/formatters/plurals/rules.rb +9 -5
- data/lib/twitter_cldr/normalizers/nfkd.rb +3 -1
- data/lib/twitter_cldr/shared.rb +2 -0
- data/lib/twitter_cldr/shared/calendar.rb +64 -0
- data/lib/twitter_cldr/shared/currencies.rb +6 -2
- data/lib/twitter_cldr/shared/languages.rb +10 -6
- data/lib/twitter_cldr/shared/numbers.rb +26 -0
- data/lib/twitter_cldr/shared/resources.rb +26 -9
- data/lib/twitter_cldr/shared/unicode_data.rb +26 -6
- data/lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb +5 -3
- data/lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb +1 -1
- data/lib/twitter_cldr/version.rb +1 -1
- data/resources/{ar → locales/ar}/calendars.yml +30 -33
- data/resources/{ar → locales/ar}/languages.yml +120 -118
- data/resources/{ar → locales/ar}/numbers.yml +8 -9
- data/resources/{ar → locales/ar}/plurals.yml +0 -0
- data/resources/{da → locales/da}/calendars.yml +24 -9
- data/resources/{da → locales/da}/languages.yml +14 -8
- data/resources/{da → locales/da}/numbers.yml +1 -2
- data/resources/{da → locales/da}/plurals.yml +0 -0
- data/resources/{de → locales/de}/calendars.yml +42 -8
- data/resources/{de → locales/de}/languages.yml +47 -42
- data/resources/{de → locales/de}/numbers.yml +1 -2
- data/resources/{de → locales/de}/plurals.yml +0 -0
- data/resources/{en → locales/en}/calendars.yml +16 -7
- data/resources/{en → locales/en}/languages.yml +53 -5
- data/resources/{en → locales/en}/numbers.yml +1 -2
- data/resources/{en → locales/en}/plurals.yml +0 -0
- data/resources/{es → locales/es}/calendars.yml +29 -15
- data/resources/{es → locales/es}/languages.yml +7 -5
- data/resources/{es → locales/es}/numbers.yml +3 -3
- data/resources/{es → locales/es}/plurals.yml +0 -0
- data/resources/{fa → locales/fa}/calendars.yml +87 -18
- data/resources/{fa → locales/fa}/languages.yml +13 -9
- data/resources/locales/fa/numbers.yml +29 -0
- data/resources/{fa → locales/fa}/plurals.yml +0 -0
- data/resources/{fi → locales/fi}/calendars.yml +64 -14
- data/resources/{fi → locales/fi}/languages.yml +47 -36
- data/resources/{fi → locales/fi}/numbers.yml +1 -2
- data/resources/{fi → locales/fi}/plurals.yml +0 -0
- data/resources/{fil → locales/fil}/calendars.yml +32 -23
- data/resources/{fil → locales/fil}/languages.yml +75 -22
- data/resources/{fil → locales/fil}/numbers.yml +1 -2
- data/resources/{fil → locales/fil}/plurals.yml +0 -0
- data/resources/{fr → locales/fr}/calendars.yml +54 -12
- data/resources/{fr → locales/fr}/languages.yml +5 -2
- data/resources/{fr → locales/fr}/numbers.yml +1 -2
- data/resources/{fr → locales/fr}/plurals.yml +0 -0
- data/resources/{he → locales/he}/calendars.yml +74 -38
- data/resources/{he → locales/he}/languages.yml +41 -26
- data/resources/{he → locales/he}/numbers.yml +1 -2
- data/resources/{he → locales/he}/plurals.yml +0 -0
- data/resources/{hi → locales/hi}/calendars.yml +36 -42
- data/resources/{hi → locales/hi}/languages.yml +8 -3
- data/resources/{hi → locales/hi}/numbers.yml +1 -2
- data/resources/{hi → locales/hi}/plurals.yml +0 -0
- data/resources/{hu → locales/hu}/calendars.yml +95 -19
- data/resources/{hu → locales/hu}/languages.yml +15 -4
- data/resources/{hu → locales/hu}/numbers.yml +1 -2
- data/resources/{hu → locales/hu}/plurals.yml +0 -0
- data/resources/{id → locales/id}/calendars.yml +56 -39
- data/resources/{id → locales/id}/languages.yml +148 -141
- data/resources/{id → locales/id}/numbers.yml +1 -2
- data/resources/{id → locales/id}/plurals.yml +0 -0
- data/resources/{it → locales/it}/calendars.yml +51 -15
- data/resources/{it → locales/it}/languages.yml +5 -5
- data/resources/{it → locales/it}/numbers.yml +2 -2
- data/resources/{it → locales/it}/plurals.yml +0 -0
- data/resources/{ja → locales/ja}/calendars.yml +26 -36
- data/resources/{ja → locales/ja}/languages.yml +29 -16
- data/resources/{ja → locales/ja}/numbers.yml +2 -3
- data/resources/{ja → locales/ja}/plurals.yml +0 -0
- data/resources/{ko → locales/ko}/calendars.yml +18 -9
- data/resources/{ko → locales/ko}/languages.yml +13 -10
- data/resources/{ko → locales/ko}/numbers.yml +1 -2
- data/resources/{ko → locales/ko}/plurals.yml +0 -0
- data/resources/{ms → locales/ms}/calendars.yml +91 -53
- data/resources/locales/ms/languages.yml +157 -0
- data/resources/{ms → locales/ms}/numbers.yml +1 -2
- data/resources/{ms → locales/ms}/plurals.yml +0 -0
- data/resources/{nl → locales/nl}/calendars.yml +38 -9
- data/resources/{nl → locales/nl}/languages.yml +28 -21
- data/resources/{nl → locales/nl}/numbers.yml +1 -2
- data/resources/{nl → locales/nl}/plurals.yml +0 -0
- data/resources/{no → locales/no}/calendars.yml +11 -6
- data/resources/{no → locales/no}/languages.yml +0 -0
- data/resources/{no → locales/no}/numbers.yml +1 -2
- data/resources/{no → locales/no}/plurals.yml +0 -0
- data/resources/{pl → locales/pl}/calendars.yml +80 -15
- data/resources/{pl → locales/pl}/languages.yml +6 -6
- data/resources/{pl → locales/pl}/numbers.yml +3 -2
- data/resources/{pl → locales/pl}/plurals.yml +0 -0
- data/resources/{pt → locales/pt}/calendars.yml +34 -8
- data/resources/{pt → locales/pt}/languages.yml +12 -4
- data/resources/{pt → locales/pt}/numbers.yml +1 -2
- data/resources/{pt → locales/pt}/plurals.yml +0 -0
- data/resources/{ru → locales/ru}/calendars.yml +69 -30
- data/resources/{ru → locales/ru}/languages.yml +18 -16
- data/resources/{ru → locales/ru}/numbers.yml +2 -3
- data/resources/{ru → locales/ru}/plurals.yml +0 -0
- data/resources/{sv → locales/sv}/calendars.yml +95 -15
- data/resources/{sv → locales/sv}/languages.yml +30 -8
- data/resources/{sv → locales/sv}/numbers.yml +1 -2
- data/resources/{sv → locales/sv}/plurals.yml +0 -0
- data/resources/{th → locales/th}/calendars.yml +89 -64
- data/resources/{th → locales/th}/languages.yml +5 -3
- data/resources/{th → locales/th}/numbers.yml +1 -2
- data/resources/{th → locales/th}/plurals.yml +0 -0
- data/resources/{tr → locales/tr}/calendars.yml +93 -19
- data/resources/{tr → locales/tr}/languages.yml +30 -28
- data/resources/{tr → locales/tr}/numbers.yml +2 -3
- data/resources/{tr → locales/tr}/plurals.yml +0 -0
- data/resources/{ur → locales/ur}/calendars.yml +33 -37
- data/resources/locales/ur/languages.yml +163 -0
- data/resources/{ur → locales/ur}/numbers.yml +1 -2
- data/resources/{ur → locales/ur}/plurals.yml +0 -0
- data/resources/{zh-Hant → locales/zh-Hant}/calendars.yml +76 -44
- data/resources/{zh-Hant → locales/zh-Hant}/languages.yml +122 -22
- data/resources/{zh-Hant → locales/zh-Hant}/numbers.yml +3 -4
- data/resources/{zh → locales/zh}/calendars.yml +81 -24
- data/resources/{zh → locales/zh}/languages.yml +13 -14
- data/resources/{zh → locales/zh}/numbers.yml +1 -2
- data/resources/{zh → locales/zh}/plurals.yml +0 -0
- data/spec/core_ext/array_spec.rb +16 -0
- data/spec/core_ext/calendars/date_spec.rb +6 -1
- data/spec/core_ext/calendars/datetime_spec.rb +6 -1
- data/spec/core_ext/calendars/time_spec.rb +6 -1
- data/spec/core_ext/numbers/localized_number_spec.rb +38 -8
- data/spec/core_ext/string_spec.rb +14 -1
- data/spec/formatters/numbers/number_formatter_spec.rb +3 -3
- data/spec/formatters/plurals/rules_spec.rb +3 -3
- data/spec/readme_spec.rb +190 -0
- data/spec/shared/calendar_spec.rb +133 -0
- data/spec/shared/numbers_spec.rb +35 -0
- data/spec/shared/resources_spec.rb +33 -15
- data/spec/tokenizers/calendars/date_tokenizer_spec.rb +37 -26
- data/spec/tokenizers/calendars/datetime_tokenizer_spec.rb +36 -29
- data/spec/tokenizers/calendars/time_tokenizer_spec.rb +22 -18
- data/spec/twitter_cldr_spec.rb +21 -7
- metadata +166 -114
- data/resources/fa/numbers.yml +0 -30
- data/resources/ms/languages.yml +0 -54
- data/resources/ur/languages.yml +0 -81
@@ -110,12 +110,25 @@ describe LocalizedString do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
describe "#normalize" do
|
113
|
-
it "returns a normalized instance of LocalizedString" do
|
113
|
+
it "returns a normalized instance of LocalizedString, defaults to NFD" do
|
114
|
+
mock.proxy(TwitterCldr::Normalizers::NFD).normalize("español")
|
114
115
|
"español".bytes.to_a.should == [101, 115, 112, 97, 195, 177, 111, 108]
|
115
116
|
result = "español".localize.normalize
|
116
117
|
result.should be_a(LocalizedString)
|
117
118
|
result.to_s.bytes.to_a.should == [101, 115, 112, 97, 110, 204, 131, 111, 108]
|
118
119
|
end
|
120
|
+
|
121
|
+
it "returns a normalized instance of LocalizedString using the specified algorithm" do
|
122
|
+
mock.proxy(TwitterCldr::Normalizers::NFKD).normalize("español")
|
123
|
+
"español".bytes.to_a.should == [101, 115, 112, 97, 195, 177, 111, 108]
|
124
|
+
result = "español".localize.normalize(:using => :NFKD)
|
125
|
+
result.should be_a(LocalizedString)
|
126
|
+
result.to_s.bytes.to_a.should == [101, 115, 112, 97, 110, 204, 131, 111, 108]
|
127
|
+
end
|
128
|
+
|
129
|
+
it "raises an ArgumentError if passed an unsupported normalization form" do
|
130
|
+
lambda { "español".localize.normalize(:using => :blarg) }.should raise_error(ArgumentError)
|
131
|
+
end
|
119
132
|
end
|
120
133
|
|
121
134
|
describe "#code_points" do
|
@@ -11,11 +11,11 @@ describe NumberFormatter do
|
|
11
11
|
before(:each) do
|
12
12
|
@tokenizer = TwitterCldr::Tokenizers::NumberTokenizer.new(:locale => :sv, :type => :decimal)
|
13
13
|
|
14
|
-
any_instance_of(
|
14
|
+
any_instance_of(DecimalFormatter) do |formatter|
|
15
15
|
mock(formatter).tokenizer { @tokenizer }
|
16
16
|
end
|
17
17
|
|
18
|
-
@formatter =
|
18
|
+
@formatter = DecimalFormatter.new(:locale => :sv)
|
19
19
|
@formatter.instance_variable_set("@tokenizer", @tokenizer)
|
20
20
|
end
|
21
21
|
|
@@ -78,7 +78,7 @@ describe NumberFormatter do
|
|
78
78
|
@formatter.format(1337).should == "1 337"
|
79
79
|
end
|
80
80
|
|
81
|
-
it "formats
|
81
|
+
it "formats a decimal larger than 999.9" do
|
82
82
|
@formatter.format(1337.37).should == "1 337,37"
|
83
83
|
end
|
84
84
|
end
|
@@ -59,10 +59,10 @@ describe Rules do
|
|
59
59
|
Rules.all_for(:ru).should =~ [:one, :few, :many, :other]
|
60
60
|
end
|
61
61
|
|
62
|
-
it "returns
|
62
|
+
it "returns nil on error" do
|
63
63
|
stub(Rules).get_resource { lambda { raise "Jelly beans" } }
|
64
|
-
Rules.all_for(:en).should
|
65
|
-
Rules.all_for(:ru).should
|
64
|
+
Rules.all_for(:en).should be_nil
|
65
|
+
Rules.all_for(:ru).should be_nil
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
data/spec/readme_spec.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
def spaces(str)
|
9
|
+
str.gsub("\xC2\xA0", " ")
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "README" do
|
13
|
+
it "verifies supported_locales" do
|
14
|
+
sup = TwitterCldr.supported_locales
|
15
|
+
sup.should be_a(Array)
|
16
|
+
sup.first.should be_a(Symbol)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "verifies supported_locale?" do
|
20
|
+
TwitterCldr.supported_locale?(:es).should be_true
|
21
|
+
TwitterCldr.supported_locale?(:xx).should be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "verifies number formatting" do
|
25
|
+
nbsp = "\xC2\xA0"
|
26
|
+
1337.localize(:es).to_s.should == "1.337"
|
27
|
+
spaces(1337.localize(:es).to_currency.to_s).should == "1.337,00 $"
|
28
|
+
spaces(1337.localize(:es).to_currency.to_s(:currency => "EUR").to_s).should == "1.337,00 €"
|
29
|
+
spaces(1337.localize(:es).to_currency.to_s(:currency => "Peru").to_s).should == "1.337,00 S/."
|
30
|
+
1337.localize(:es).to_percent.to_s.should == "1.337%"
|
31
|
+
1337.localize(:es).to_percent.to_s(:precision => 2).should == "1.337,00%"
|
32
|
+
1337.localize(:es).to_decimal.to_s(:precision => 3).should == "1.337,000"
|
33
|
+
|
34
|
+
num = TwitterCldr::LocalizedNumber.new(1337, :es)
|
35
|
+
spaces(num.to_currency.to_s).should == "1.337,00 $"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "verifies extra currency data" do
|
39
|
+
countries = TwitterCldr::Shared::Currencies.countries
|
40
|
+
countries.should be_a(Array)
|
41
|
+
countries.should include("Lithuania")
|
42
|
+
countries.should include("Philippines")
|
43
|
+
|
44
|
+
currency_codes = TwitterCldr::Shared::Currencies.currency_codes
|
45
|
+
currency_codes.should be_a(Array)
|
46
|
+
currency_codes.should include("LTL")
|
47
|
+
currency_codes.should include("PHP")
|
48
|
+
|
49
|
+
TwitterCldr::Shared::Currencies.for_country("Canada").should == { :currency => "Dollar", :symbol => "$", :code => "CAD" }
|
50
|
+
TwitterCldr::Shared::Currencies.for_code("CAD").should == { :currency => "Dollar", :symbol => "$", :country => "Canada"}
|
51
|
+
end
|
52
|
+
|
53
|
+
it "verifies dates" do
|
54
|
+
date_time = DateTime.new(2011, 12, 12, 21, 44, 57, -8.0 / 24.0)
|
55
|
+
date = date_time.localize.to_date.base_obj
|
56
|
+
time = Time.at(date_time.localize.to_time.base_obj.utc - (8 * 60 * 60))
|
57
|
+
|
58
|
+
date_time.localize(:es).to_full_s.should == "lunes, 12 de diciembre de 2011 21:44:57 UTC -0800"
|
59
|
+
date_time.localize(:es).to_long_s.should == "12 de diciembre de 2011 21:44:57 -08:00"
|
60
|
+
date_time.localize(:es).to_medium_s.should == "12/12/2011 21:44:57"
|
61
|
+
date_time.localize(:es).to_short_s.should == "12/12/11 21:44"
|
62
|
+
|
63
|
+
date.localize(:es).to_full_s.should == "lunes, 12 de diciembre de 2011"
|
64
|
+
date.localize(:es).to_long_s.should == "12 de diciembre de 2011"
|
65
|
+
date.localize(:es).to_medium_s.should == "12/12/2011"
|
66
|
+
date.localize(:es).to_short_s.should == "12/12/11"
|
67
|
+
|
68
|
+
time.localize(:es).to_full_s.should match(/21:44:57 UTC [-+]\d{4}/)
|
69
|
+
time.localize(:es).to_long_s.should == "21:44:57 UTC"
|
70
|
+
time.localize(:es).to_medium_s.should == "21:44:57"
|
71
|
+
time.localize(:es).to_short_s.should == "21:44"
|
72
|
+
|
73
|
+
dt = TwitterCldr::LocalizedDateTime.new(date_time, :es)
|
74
|
+
dt.to_short_s.should == "12/12/11 21:44"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "verifies plural rules" do
|
78
|
+
1.localize(:ru).plural_rule.should == :one
|
79
|
+
2.localize(:ru).plural_rule.should == :few
|
80
|
+
5.localize(:ru).plural_rule.should == :many
|
81
|
+
|
82
|
+
TwitterCldr::Formatters::Plurals::Rules.all.should == [:one, :other]
|
83
|
+
TwitterCldr::Formatters::Plurals::Rules.all_for(:es).should == [:one, :other]
|
84
|
+
TwitterCldr::Formatters::Plurals::Rules.all_for(:ru).should == [:one, :few, :many, :other]
|
85
|
+
|
86
|
+
# get the rule for a number in a specific locale
|
87
|
+
TwitterCldr::Formatters::Plurals::Rules.rule_for(1, :ru).should == :one
|
88
|
+
TwitterCldr::Formatters::Plurals::Rules.rule_for(2, :ru).should == :few
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "plural interpolation" do
|
92
|
+
it "verifies first technique" do
|
93
|
+
replacements = { :horse_count => 3,
|
94
|
+
:horses => { :one => "is 1 horse",
|
95
|
+
:other => "are %{horse_count} horses" } }
|
96
|
+
|
97
|
+
("there %{horse_count:horses} in the barn".localize % replacements).should == "there are 3 horses in the barn"
|
98
|
+
end
|
99
|
+
|
100
|
+
it "verifies second technique" do
|
101
|
+
str = 'there %<{ "horse_count": { "one": "is one horse", "other": "are %{horse_count} horses" } }> in the barn'
|
102
|
+
(str.localize % { :horse_count => 3 }).should == "there are 3 horses in the barn"
|
103
|
+
end
|
104
|
+
|
105
|
+
it "verifies regular Ruby interpolation works" do
|
106
|
+
("five euros plus %.3f in tax" % (13.25 * 0.087)).should == "five euros plus 1.153 in tax"
|
107
|
+
|
108
|
+
if RUBY_VERSION >= '1.9.0'
|
109
|
+
("there are %{count} horses in the barn" % { :count => "5" }).should == "there are 5 horses in the barn"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "verifies named interpolation parameters" do
|
114
|
+
#"five euros plus %<percent>.3f in %{noun}".localize % { :percent => 13.25 * 0.087, :noun => "tax" }.should == "five euros plus 1.15 in tax"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "verifies world languages" do
|
119
|
+
:es.localize(:es).as_language_code.should == "español"
|
120
|
+
:ru.localize(:es).as_language_code.should == "ruso"
|
121
|
+
ls = TwitterCldr::LocalizedSymbol.new(:ru, :es)
|
122
|
+
ls.as_language_code.should == "ruso"
|
123
|
+
end
|
124
|
+
|
125
|
+
it "verifies language data" do
|
126
|
+
# get all languages for the default locale
|
127
|
+
all = TwitterCldr::Shared::Languages.all
|
128
|
+
all.should include(:"zh-Hant")
|
129
|
+
all[:'zh-Hant'].should == "Traditional Chinese"
|
130
|
+
all.should include(:vi)
|
131
|
+
all[:vi].should == "Vietnamese"
|
132
|
+
|
133
|
+
# get all languages for a specific locale
|
134
|
+
all_es = TwitterCldr::Shared::Languages.all_for(:es)
|
135
|
+
all_es.should include(:"zh-Hant")
|
136
|
+
all_es[:'zh-Hant'].should == "chino tradicional"
|
137
|
+
all_es.should include(:vi)
|
138
|
+
all_es[:vi].should == "vietnamita"
|
139
|
+
|
140
|
+
# get a language by its code for the default locale
|
141
|
+
TwitterCldr::Shared::Languages.from_code(:'zh-Hant').should == "Traditional Chinese"
|
142
|
+
|
143
|
+
# get a language from its code for a specific locale
|
144
|
+
TwitterCldr::Shared::Languages.from_code_for_locale(:'zh-Hant', :es).should == "chino tradicional"
|
145
|
+
|
146
|
+
# translate a language from one locale to another
|
147
|
+
TwitterCldr::Shared::Languages.translate_language("chino tradicional", :es, :en).should == "Traditional Chinese"
|
148
|
+
TwitterCldr::Shared::Languages.translate_language("Traditional Chinese", :en, :es).should == "chino tradicional"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "verifies code point conversions" do
|
152
|
+
code_point = TwitterCldr::Shared::UnicodeData.for_code_point("1F3E9")
|
153
|
+
code_point.name.should == "LOVE HOTEL"
|
154
|
+
code_point.bidi_mirrored.should == "N"
|
155
|
+
code_point.category.should == "So"
|
156
|
+
code_point.combining_class.should == "0"
|
157
|
+
|
158
|
+
# Convert characters to code points:
|
159
|
+
TwitterCldr::Utils::CodePoints.from_string("¿").should == ["00BF"]
|
160
|
+
|
161
|
+
# Convert code points to characters:
|
162
|
+
TwitterCldr::Utils::CodePoints.to_string(["00BF"]).should == "¿"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "verifies normalization" do
|
166
|
+
TwitterCldr::Normalizers::NFD.normalize("français").should == TwitterCldr::Utils::CodePoints.to_string(["0066", "0072", "0061", "006E", "0063", "0327", "0061", "0069", "0073"])
|
167
|
+
TwitterCldr::Utils::CodePoints.from_string("español").should == ["0065", "0073", "0070", "0061", "00F1", "006F", "006C"]
|
168
|
+
TwitterCldr::Utils::CodePoints.from_string(TwitterCldr::Normalizers::NFD.normalize("español")).should == ["0065", "0073", "0070", "0061", "006E", "0303", "006F", "006C"]
|
169
|
+
|
170
|
+
"español".localize.code_points.should == ["0065", "0073", "0070", "0061", "00F1", "006F", "006C"]
|
171
|
+
"español".localize.normalize.code_points.should == ["0065", "0073", "0070", "0061", "006E", "0303", "006F", "006C"]
|
172
|
+
"español".localize.normalize(:using => :NFKD).code_points.should == ["0065", "0073", "0070", "0061", "006E", "0303", "006F", "006C"]
|
173
|
+
end
|
174
|
+
|
175
|
+
it "verifies Twitter-specific locale conversion" do
|
176
|
+
TwitterCldr.convert_locale(:'zh-cn').should == :zh
|
177
|
+
TwitterCldr.convert_locale(:zh).should == :zh
|
178
|
+
TwitterCldr.convert_locale(:'zh-tw').should == :'zh-Hant'
|
179
|
+
TwitterCldr.convert_locale(:'zh-Hant').should == :'zh-Hant'
|
180
|
+
|
181
|
+
TwitterCldr.convert_locale(:msa).should == :ms
|
182
|
+
TwitterCldr.convert_locale(:ms).should == :ms
|
183
|
+
end
|
184
|
+
|
185
|
+
it "verifies locale defaults" do
|
186
|
+
TwitterCldr.get_locale.should == :en
|
187
|
+
FastGettext.locale = "ru"
|
188
|
+
TwitterCldr.get_locale.should == :ru
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr::Shared
|
9
|
+
|
10
|
+
describe Calendar do
|
11
|
+
|
12
|
+
let(:calendar) { Calendar.new(:de) }
|
13
|
+
|
14
|
+
describe '#initialize' do
|
15
|
+
it 'returns calendar for default locale and type' do
|
16
|
+
stub(TwitterCldr).get_locale { :fr }
|
17
|
+
cal = Calendar.new
|
18
|
+
|
19
|
+
cal.locale.should == :fr
|
20
|
+
cal.calendar_type.should == TwitterCldr::DEFAULT_CALENDAR_TYPE
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns calendar for a specific locale' do
|
24
|
+
Calendar.new(:jp).locale.should == :jp
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'uses TwitterCldr.convert_locale' do
|
28
|
+
Calendar.new(:'zh-cn').locale.should == :zh
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns calendar of a specific type' do
|
32
|
+
Calendar.new(:th, :buddhist).calendar_type.should == :buddhist
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#months' do
|
38
|
+
context 'when data is available' do
|
39
|
+
it 'returns months list in a wide names form by default' do
|
40
|
+
calendar.months.should == %w[Januar Februar März April Mai Juni Juli August September Oktober November Dezember]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'supports wide names form' do
|
44
|
+
calendar.months(:wide).should == %w[Januar Februar März April Mai Juni Juli August September Oktober November Dezember]
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'supports narrow names form' do
|
48
|
+
calendar.months(:narrow).should == %w[J F M A M J J A S O N D]
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'supports abbreviated names form' do
|
52
|
+
calendar.months(:abbreviated).should == %w[Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez]
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns nil if invalid names form is passed' do
|
56
|
+
calendar.months(:wat).should == nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when some data is missing' do
|
61
|
+
it 'returns nil if some names format is missing' do
|
62
|
+
stub(TwitterCldr).get_locale_resource { { :de => { :calendars => { :gregorian => { :months => { :'stand-alone' => {} } } } } } }
|
63
|
+
calendar.months(:wide).should == nil
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns nil if calendars data is missing' do
|
67
|
+
stub(TwitterCldr).get_locale_resource { { :de => {} } }
|
68
|
+
calendar.months(:wide).should == nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#weekdays' do
|
74
|
+
context 'when data is available' do
|
75
|
+
it 'returns weekdays list in a wide names form by default' do
|
76
|
+
calendar.weekdays.should == {
|
77
|
+
:sun => 'Sonntag',
|
78
|
+
:mon => 'Montag',
|
79
|
+
:tue => 'Dienstag',
|
80
|
+
:wed => 'Mittwoch',
|
81
|
+
:thu => 'Donnerstag',
|
82
|
+
:fri => 'Freitag',
|
83
|
+
:sat => 'Samstag'
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'supports wide names form' do
|
88
|
+
calendar.weekdays(:wide).should == {
|
89
|
+
:sun => 'Sonntag',
|
90
|
+
:mon => 'Montag',
|
91
|
+
:tue => 'Dienstag',
|
92
|
+
:wed => 'Mittwoch',
|
93
|
+
:thu => 'Donnerstag',
|
94
|
+
:fri => 'Freitag',
|
95
|
+
:sat => 'Samstag'
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'supports narrow names form' do
|
100
|
+
calendar.weekdays(:narrow).should == { :sun => 'S', :mon => 'M', :tue => 'D', :wed => 'M', :thu => 'D', :fri => 'F', :sat => 'S' }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'supports abbreviated names form' do
|
104
|
+
calendar.weekdays(:abbreviated).should == {
|
105
|
+
:sun => 'So',
|
106
|
+
:mon => 'Mo',
|
107
|
+
:tue => 'Di',
|
108
|
+
:wed => 'Mi',
|
109
|
+
:thu => 'Do',
|
110
|
+
:fri => 'Fr',
|
111
|
+
:sat => 'Sa'
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'returns nil if invalid names form is passed' do
|
116
|
+
calendar.weekdays(:wat).should == nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when some data is missing' do
|
121
|
+
it 'returns nil if some names format is missing' do
|
122
|
+
stub(TwitterCldr).get_locale_resource { { :de => { :calendars => { :gregorian => { :days => { :'stand-alone' => {} } } } } } }
|
123
|
+
calendar.weekdays(:wide).should == nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'returns nil if calendars data is missing' do
|
127
|
+
stub(TwitterCldr).get_locale_resource { { :de => {} } }
|
128
|
+
calendar.weekdays(:wide).should == nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr::Shared
|
9
|
+
|
10
|
+
describe Numbers do
|
11
|
+
describe "#symbols" do
|
12
|
+
let(:symbols) { { :nan => 'NaN', :minus_sign => '-' } }
|
13
|
+
|
14
|
+
it 'returns numerical symbols for default locale' do
|
15
|
+
stub(TwitterCldr).get_locale { :jp }
|
16
|
+
stub(TwitterCldr).get_locale_resource(:jp, :numbers) { { :jp => { :numbers => { :symbols => symbols } } } }
|
17
|
+
Numbers.symbols.should == symbols
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns numerical symbols for default locale' do
|
21
|
+
stub(TwitterCldr).get_locale_resource(:np, :numbers) { { :np => { :numbers => { :symbols => symbols } } } }
|
22
|
+
Numbers.symbols(:np).should == symbols
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'converts locale' do
|
26
|
+
stub(TwitterCldr).get_locale_resource(:'zh-Hant', :numbers) { { :'zh-Hant' => { :numbers => { :symbols => symbols } } } }
|
27
|
+
Numbers.symbols('zh-tw').should == symbols
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns nil if the resource is missing' do
|
31
|
+
stub(TwitterCldr).get_locale_resource(:nop, :numbers) { nil }
|
32
|
+
Numbers.symbols(:nop).should be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -8,26 +8,44 @@ require 'spec_helper'
|
|
8
8
|
include TwitterCldr::Shared
|
9
9
|
|
10
10
|
describe Resources do
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
let(:resources) { Resources.new }
|
12
|
+
|
13
|
+
describe '#get_resource' do
|
14
|
+
it 'loads the correct YAML file' do
|
15
|
+
stub(File).read(File.join(TwitterCldr::RESOURCES_DIR, 'shared/currencies.yml')) { "---\n- 1\n- 2\n" }
|
16
|
+
resources.get_resource(:shared, :currencies).should == [1, 2]
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
# note that it should convert the string "de" into a symbol
|
18
|
-
mock(@resource).data_for(:de, "racehorse").once { "german racehorse resource" }
|
19
|
+
it 'loads the resource only once' do
|
20
|
+
mock(resources).load_resource('shared/currencies.yml').once { 'foo-bar-baz' }
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
result = resources.get_resource(:shared, :currencies)
|
23
|
+
# second time load_resource is not called but we get the same object as before
|
24
|
+
resources.get_resource(:shared, :currencies).object_id.should == result.object_id
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'accepts a variable length resource path both in symbols and strings' do
|
28
|
+
stub(resources).load_resource('foo/bar/baz.yml') { 'foo-bar-baz' }
|
29
|
+
resources.get_resource('foo', :bar, 'baz').should == 'foo-bar-baz'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'raises an exception if resource file is missing' do
|
33
|
+
lambda { resources.get_resource(:foo, :bar) }.should raise_error(ArgumentError, "Resource 'foo/bar.yml' not found.")
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
26
|
-
describe
|
27
|
-
it
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
describe '#get_locale_resource' do
|
38
|
+
it 'load the correct locale resource file' do
|
39
|
+
stub(resources).get_resource(:locales, :de, :numbers) { 'foo' }
|
40
|
+
resources.get_locale_resource(:de, :numbers).should == 'foo'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'converts locales' do
|
44
|
+
mock(TwitterCldr).convert_locale('zh-tw') { :'zh-Hant' }
|
45
|
+
mock(resources).get_resource(:locales, :'zh-Hant', :numbers) { 'foo' }
|
46
|
+
|
47
|
+
resources.get_locale_resource('zh-tw', :numbers).should == 'foo'
|
31
48
|
end
|
32
49
|
end
|
50
|
+
|
33
51
|
end
|