twitter_cldr 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/NOTICE +29 -1
- data/README.md +4 -11
- data/lib/twitter_cldr/formatters/calendars/date_formatter.rb +6 -1
- data/lib/twitter_cldr/formatters/calendars/datetime_formatter.rb +10 -1
- data/lib/twitter_cldr/formatters/calendars/time_formatter.rb +6 -1
- data/lib/twitter_cldr/formatters/calendars/timespan_formatter.rb +12 -2
- data/lib/twitter_cldr/formatters/numbers/currency_formatter.rb +12 -3
- data/lib/twitter_cldr/formatters/numbers/number_formatter.rb +9 -1
- data/lib/twitter_cldr/formatters/plurals/rules.rb +8 -3
- data/lib/twitter_cldr/localized/localized_date.rb +13 -0
- data/lib/twitter_cldr/localized/localized_datetime.rb +20 -7
- data/lib/twitter_cldr/localized/localized_object.rb +1 -1
- data/lib/twitter_cldr/localized/localized_string.rb +14 -0
- data/lib/twitter_cldr/localized/localized_time.rb +12 -0
- data/lib/twitter_cldr/localized/localized_timespan.rb +1 -1
- data/lib/twitter_cldr/parsers/number_parser.rb +113 -0
- data/lib/twitter_cldr/parsers.rb +10 -0
- data/lib/twitter_cldr/resources/loader.rb +49 -2
- data/lib/twitter_cldr/resources/locales_resources_importer.rb +22 -2
- data/lib/twitter_cldr/shared/calendar.rb +95 -12
- data/lib/twitter_cldr/shared/currencies.rb +18 -15
- data/lib/twitter_cldr/shared/languages.rb +4 -4
- data/lib/twitter_cldr/shared/numbers.rb +1 -1
- data/lib/twitter_cldr/shared/territories.rb +63 -0
- data/lib/twitter_cldr/shared.rb +2 -1
- data/lib/twitter_cldr/tokenizers/base.rb +10 -15
- data/lib/twitter_cldr/tokenizers/calendars/additional_date_format_selector.rb +6 -1
- data/lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb +11 -2
- data/lib/twitter_cldr/tokenizers/calendars/timespan_tokenizer.rb +12 -9
- data/lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb +2 -2
- data/lib/twitter_cldr/utils/territories.rb +56 -0
- data/lib/twitter_cldr/utils.rb +4 -3
- data/lib/twitter_cldr/version.rb +1 -1
- data/lib/twitter_cldr.rb +60 -8
- data/resources/collation/tailoring/hr.yml +32 -0
- data/resources/collation/tailoring/is.yml +30 -0
- data/resources/collation/tries/hr.dump +0 -0
- data/resources/collation/tries/is.dump +0 -0
- data/resources/custom/locales/he/units.yml +150 -13
- data/resources/custom/locales/hr/units.yml +9 -0
- data/resources/locales/af/territories.yml +262 -0
- data/resources/locales/ar/territories.yml +262 -0
- data/resources/locales/be/territories.yml +239 -0
- data/resources/locales/bg/territories.yml +262 -0
- data/resources/locales/bn/territories.yml +262 -0
- data/resources/locales/ca/territories.yml +262 -0
- data/resources/locales/cs/territories.yml +262 -0
- data/resources/locales/cy/territories.yml +5 -0
- data/resources/locales/da/territories.yml +262 -0
- data/resources/locales/de/territories.yml +262 -0
- data/resources/locales/el/territories.yml +262 -0
- data/resources/locales/en/territories.yml +262 -0
- data/resources/locales/es/territories.yml +262 -0
- data/resources/locales/eu/territories.yml +262 -0
- data/resources/locales/fa/territories.yml +262 -0
- data/resources/locales/fi/territories.yml +262 -0
- data/resources/locales/fil/territories.yml +262 -0
- data/resources/locales/fr/territories.yml +262 -0
- data/resources/locales/ga/territories.yml +251 -0
- data/resources/locales/gl/territories.yml +262 -0
- data/resources/locales/he/territories.yml +262 -0
- data/resources/locales/hi/territories.yml +262 -0
- data/resources/locales/hr/calendars.yml +299 -0
- data/resources/locales/hr/currencies.yml +1490 -0
- data/resources/locales/hr/languages.yml +576 -0
- data/resources/locales/hr/layout.yml +4 -0
- data/resources/locales/hr/lists.yml +7 -0
- data/resources/locales/hr/numbers.yml +59 -0
- data/resources/locales/hr/plurals.yml +5 -0
- data/resources/locales/hr/territories.yml +262 -0
- data/resources/locales/hr/units.yml +164 -0
- data/resources/locales/hu/territories.yml +262 -0
- data/resources/locales/id/territories.yml +262 -0
- data/resources/locales/is/calendars.yml +243 -0
- data/resources/locales/is/currencies.yml +478 -0
- data/resources/locales/is/languages.yml +495 -0
- data/resources/locales/is/layout.yml +4 -0
- data/resources/locales/is/lists.yml +7 -0
- data/resources/locales/is/numbers.yml +57 -0
- data/resources/locales/is/plurals.yml +3 -0
- data/resources/locales/is/territories.yml +262 -0
- data/resources/locales/is/units.yml +108 -0
- data/resources/locales/it/territories.yml +262 -0
- data/resources/locales/ja/territories.yml +262 -0
- data/resources/locales/ko/territories.yml +262 -0
- data/resources/locales/lv/territories.yml +262 -0
- data/resources/locales/ms/territories.yml +262 -0
- data/resources/locales/nb/territories.yml +262 -0
- data/resources/locales/nl/territories.yml +262 -0
- data/resources/locales/pl/territories.yml +262 -0
- data/resources/locales/pt/territories.yml +262 -0
- data/resources/locales/ro/territories.yml +262 -0
- data/resources/locales/ru/territories.yml +262 -0
- data/resources/locales/sk/territories.yml +262 -0
- data/resources/locales/sq/territories.yml +159 -0
- data/resources/locales/sr/territories.yml +262 -0
- data/resources/locales/sv/territories.yml +262 -0
- data/resources/locales/ta/territories.yml +262 -0
- data/resources/locales/th/territories.yml +262 -0
- data/resources/locales/tr/territories.yml +262 -0
- data/resources/locales/uk/territories.yml +262 -0
- data/resources/locales/ur/territories.yml +262 -0
- data/resources/locales/vi/territories.yml +262 -0
- data/resources/locales/zh/territories.yml +262 -0
- data/resources/locales/zh-Hant/territories.yml +262 -0
- data/resources/shared/iso_currency_symbols.yml +475 -0
- data/spec/formatters/numbers/currency_formatter_spec.rb +11 -2
- data/spec/formatters/plurals/rules_spec.rb +1 -1
- data/spec/localized/localized_date_spec.rb +22 -24
- data/spec/localized/localized_object_spec.rb +1 -1
- data/spec/localized/localized_string_spec.rb +33 -0
- data/spec/localized/localized_symbol_spec.rb +1 -1
- data/spec/normalization/base_spec.rb +1 -0
- data/spec/parsers/number_parser_spec.rb +189 -0
- data/spec/readme_spec.rb +10 -11
- data/spec/resources/loader_spec.rb +75 -1
- data/spec/shared/calendar_spec.rb +123 -1
- data/spec/shared/currencies_spec.rb +20 -24
- data/spec/shared/languages_spec.rb +27 -27
- data/spec/shared/numbers_spec.rb +1 -1
- data/spec/shared/territories_spec.rb +120 -0
- data/spec/spec_helper.rb +19 -2
- data/spec/twitter_cldr_spec.rb +234 -9
- data/spec/utils/territories_spec.rb +16 -0
- data/spec/utils_spec.rb +1 -1
- metadata +131 -37
- data/resources/shared/currencies.yml +0 -448
@@ -11,15 +11,6 @@ TEST_COUNTRIES = ["Australia", "Thailand", "Russia", "China", "Japan", "Peru", "
|
|
11
11
|
TEST_CODES = %w[AUD THB RUB CNY JPY PEN ZAR INR KRW GBP]
|
12
12
|
|
13
13
|
describe Currencies do
|
14
|
-
describe "#countries" do
|
15
|
-
it "should list all supported countries" do
|
16
|
-
countries = Currencies.countries
|
17
|
-
|
18
|
-
countries.size.should == 112
|
19
|
-
countries.should include(*TEST_COUNTRIES)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
14
|
describe "#currency_codes" do
|
24
15
|
it "should list all supported country codes" do
|
25
16
|
codes = Currencies.currency_codes
|
@@ -29,29 +20,34 @@ describe Currencies do
|
|
29
20
|
end
|
30
21
|
end
|
31
22
|
|
32
|
-
describe "#
|
33
|
-
it "should return all information for
|
34
|
-
data = Currencies.
|
35
|
-
|
23
|
+
describe "#for_code" do
|
24
|
+
it "should return all information for PEN" do
|
25
|
+
data = Currencies.for_code("PEN")
|
36
26
|
data.should be_a(Hash)
|
37
27
|
data.should include(
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:symbol
|
28
|
+
:name => "Peruvian nuevo sol",
|
29
|
+
:currency => :PEN,
|
30
|
+
:symbol => "S/.",
|
31
|
+
:cldr_symbol => "PEN"
|
41
32
|
)
|
42
33
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#for_code" do
|
46
|
-
it "should return all information for the given currency code" do
|
47
|
-
data = Currencies.for_code("PEN")
|
48
34
|
|
35
|
+
it "should return all information for CAD, a currency code with multiple possible symbols" do
|
36
|
+
data = Currencies.for_code("CAD")
|
49
37
|
data.should be_a(Hash)
|
50
38
|
data.should include(
|
51
|
-
:name
|
52
|
-
:currency
|
53
|
-
:symbol
|
39
|
+
:name => "Canadian dollar",
|
40
|
+
:currency => :CAD,
|
41
|
+
:symbol => "$",
|
42
|
+
:cldr_symbol => "CA$"
|
54
43
|
)
|
55
44
|
end
|
45
|
+
|
46
|
+
it "verifies that all code_points values are equivalent to their corresponding symbols" do
|
47
|
+
Currencies.currency_codes.select do |code|
|
48
|
+
data = Currencies.for_code(code)
|
49
|
+
data[:code_points].pack("U*").should == data[:symbol]
|
50
|
+
end
|
51
|
+
end
|
56
52
|
end
|
57
53
|
end
|
@@ -10,31 +10,31 @@ include TwitterCldr::Shared
|
|
10
10
|
describe Languages do
|
11
11
|
describe "#translate_language" do
|
12
12
|
it "should translate a language from one locale to another" do
|
13
|
-
Languages.translate_language("Russian", :en, :es).should
|
14
|
-
Languages.translate_language("ruso", :es, :en).should
|
15
|
-
Languages.translate_language("Spanish", :en, :es).should
|
16
|
-
Languages.translate_language("ruso", :es, :ru).should
|
13
|
+
Languages.translate_language("Russian", :en, :es).should match_normalized("ruso")
|
14
|
+
Languages.translate_language("ruso", :es, :en).should match_normalized("Russian")
|
15
|
+
Languages.translate_language("Spanish", :en, :es).should match_normalized("español")
|
16
|
+
Languages.translate_language("ruso", :es, :ru).should match_normalized("русский")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should be capitalization agnostic" do
|
20
|
-
Languages.translate_language("russian", :en, :es).should
|
21
|
-
Languages.translate_language("RUSSIAN", :en, :es).should
|
20
|
+
Languages.translate_language("russian", :en, :es).should match_normalized("ruso")
|
21
|
+
Languages.translate_language("RUSSIAN", :en, :es).should match_normalized("ruso")
|
22
22
|
end
|
23
23
|
|
24
|
-
it "defaults the destination language to English (or whatever
|
25
|
-
Languages.translate_language("Ruso", :es).should
|
26
|
-
Languages.translate_language("русский", :ru).should
|
24
|
+
it "defaults the destination language to English (or whatever the global locale is)" do
|
25
|
+
Languages.translate_language("Ruso", :es).should match_normalized("Russian")
|
26
|
+
Languages.translate_language("русский", :ru).should match_normalized("Russian")
|
27
27
|
end
|
28
28
|
|
29
29
|
it "defaults source and destination language to English if not given" do
|
30
|
-
Languages.translate_language("Russian").should
|
31
|
-
|
32
|
-
Languages.translate_language("Russian").should
|
30
|
+
Languages.translate_language("Russian").should match_normalized("Russian")
|
31
|
+
TwitterCldr.locale = :es
|
32
|
+
Languages.translate_language("Russian").should match_normalized("ruso")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "successfully translates locale codes that are and are not in the CLDR using the locale map" do
|
36
|
-
Languages.translate_language("Russian", :en, :'zh-cn').should
|
37
|
-
Languages.translate_language("Russian", :en, :'zh').should
|
36
|
+
Languages.translate_language("Russian", :en, :'zh-cn').should match_normalized("俄文")
|
37
|
+
Languages.translate_language("Russian", :en, :'zh').should match_normalized("俄文")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should return nil if no translation was found" do
|
@@ -44,17 +44,17 @@ describe Languages do
|
|
44
44
|
|
45
45
|
describe "#from_code_for_locale" do
|
46
46
|
it "should return the language in the correct locale for the given locale code (i.e. es in English should be Spanish)" do
|
47
|
-
Languages.from_code_for_locale(:es, :en).should
|
48
|
-
Languages.from_code_for_locale(:en, :es).should
|
47
|
+
Languages.from_code_for_locale(:es, :en).should match_normalized("Spanish")
|
48
|
+
Languages.from_code_for_locale(:en, :es).should match_normalized("inglés")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#from_code" do
|
53
53
|
it "should return the language in the default locale for the given locale code" do
|
54
|
-
Languages.from_code(:es).should
|
55
|
-
Languages.from_code(:ru).should
|
56
|
-
|
57
|
-
Languages.from_code(:es).should
|
54
|
+
Languages.from_code(:es).should match_normalized("Spanish")
|
55
|
+
Languages.from_code(:ru).should match_normalized("Russian")
|
56
|
+
TwitterCldr.locale = :es
|
57
|
+
Languages.from_code(:es).should match_normalized("español")
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,7 +62,7 @@ describe Languages do
|
|
62
62
|
it "should return a hash of all languages for the given language code" do
|
63
63
|
langs = Languages.all_for(:es)
|
64
64
|
langs.should be_a(Hash)
|
65
|
-
langs[:ru].should
|
65
|
+
langs[:ru].should match_normalized("ruso")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should return an empty hash for an invalid language" do
|
@@ -75,14 +75,14 @@ describe Languages do
|
|
75
75
|
it "should use the default language to get the language hash" do
|
76
76
|
langs = Languages.all
|
77
77
|
langs.should be_a(Hash)
|
78
|
-
langs[:ru].should
|
79
|
-
langs[:de].should
|
78
|
+
langs[:ru].should match_normalized("Russian")
|
79
|
+
langs[:de].should match_normalized("German")
|
80
80
|
|
81
|
-
|
81
|
+
TwitterCldr.locale = :es
|
82
82
|
langs = Languages.all
|
83
83
|
langs.should be_a(Hash)
|
84
|
-
langs[:ru].should
|
85
|
-
langs[:de].should
|
84
|
+
langs[:ru].should match_normalized("ruso")
|
85
|
+
langs[:de].should match_normalized("alemán")
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -106,4 +106,4 @@ describe Languages do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
end
|
109
|
+
end
|
data/spec/shared/numbers_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Numbers do
|
|
12
12
|
let(:symbols) { { :nan => 'NaN', :minus_sign => '-' } }
|
13
13
|
|
14
14
|
it 'returns numerical symbols for default locale' do
|
15
|
-
stub(TwitterCldr).
|
15
|
+
stub(TwitterCldr).locale { :jp }
|
16
16
|
stub(TwitterCldr).get_locale_resource(:jp, :numbers) { { :jp => { :numbers => { :symbols => symbols } } } }
|
17
17
|
TwitterCldr::Shared::Numbers.symbols.should == symbols
|
18
18
|
end
|
@@ -0,0 +1,120 @@
|
|
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 Territories do
|
11
|
+
describe "#translate_territory" do
|
12
|
+
it "should translate country names from one locale to another" do
|
13
|
+
Territories.translate_territory("Russia", :en, :es).should match_normalized("Rusia")
|
14
|
+
Territories.translate_territory("Rusia", :es, :en).should match_normalized("Russia")
|
15
|
+
Territories.translate_territory("Spain", :en, :es).should match_normalized("España")
|
16
|
+
Territories.translate_territory("España", :es, :ru).should match_normalized("Испания")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should use alternate/short names" do
|
20
|
+
Territories.translate_territory("Congo [DRC]", :en, :es).should match_normalized("Congo [República Democrática del Congo]")
|
21
|
+
Territories.translate_territory("Congo [Republic]", :en, :es).should match_normalized("Congo [República]")
|
22
|
+
Territories.translate_territory("East Timor", :en, :es).should match_normalized("Timor Oriental")
|
23
|
+
Territories.translate_territory("Falkland Islands [Islas Malvinas]", :en, :es).should match_normalized("Islas Malvinas [Islas Falkland]")
|
24
|
+
Territories.translate_territory("Hong Kong", :en, :es).should match_normalized("Hong Kong")
|
25
|
+
Territories.translate_territory("Ivory Coast", :en, :es).should match_normalized("Costa de Marfil")
|
26
|
+
Territories.translate_territory("Macau", :en, :es).should match_normalized("Macao")
|
27
|
+
Territories.translate_territory("Macedonia [FYROM]", :en, :es).should match_normalized("Macedonia [ERYM]")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be capitalization agnostic" do
|
31
|
+
Territories.translate_territory("russia", :en, :es).should match_normalized("Rusia")
|
32
|
+
Territories.translate_territory("RUSSIA", :en, :es).should match_normalized("Rusia")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "defaults the destination language to English (or whatever the global locale is)" do
|
36
|
+
Territories.translate_territory("Rusia", :es).should match_normalized("Russia")
|
37
|
+
Territories.translate_territory("Россия", :ru).should match_normalized("Russia")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "defaults source and destination language to English if not given" do
|
41
|
+
Territories.translate_territory("Russia").should match_normalized("Russia")
|
42
|
+
TwitterCldr.locale = :es
|
43
|
+
Territories.translate_territory("Russia").should match_normalized("Rusia")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "successfully translates locale codes that are and are not in the CLDR using the locale map" do
|
47
|
+
Territories.translate_territory("Russia", :en, :'zh-cn').should match_normalized("俄罗斯")
|
48
|
+
Territories.translate_territory("Russia", :en, :'zh').should match_normalized("俄罗斯")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return nil if no translation was found" do
|
52
|
+
Territories.translate_territory("Russia", :en, :blarg).should == nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#from_territory_code_for_locale" do
|
57
|
+
it "should return the territory in the correct locale for the given locale code (i.e. RU in English should be Russia)" do
|
58
|
+
Territories.from_territory_code_for_locale(:ES, :en).should match_normalized("Spain")
|
59
|
+
Territories.from_territory_code_for_locale(:GB, :es).should match_normalized("Reino Unido")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should work with lower-case country codes as well" do
|
63
|
+
Territories.from_territory_code_for_locale(:es, :en).should match_normalized("Spain")
|
64
|
+
Territories.from_territory_code_for_locale(:gb, :es).should match_normalized("Reino Unido")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should work with Traditional Chinese" do
|
68
|
+
Territories.from_territory_code_for_locale(:US, :"zh-Hant").should match_normalized("美國")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#from_territory_code" do
|
73
|
+
it "should return the language in the default locale for the given locale code" do
|
74
|
+
Territories.from_territory_code(:ES).should match_normalized("Spain")
|
75
|
+
Territories.from_territory_code(:RU).should match_normalized("Russia")
|
76
|
+
TwitterCldr.locale = :es
|
77
|
+
Territories.from_territory_code(:ES).should match_normalized("España")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#all_for" do
|
82
|
+
it "should return a hash of all languages for the given language code" do
|
83
|
+
territories = Territories.all_for(:es)
|
84
|
+
territories.should be_a(Hash)
|
85
|
+
territories[:ru].should match_normalized("Rusia")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return an empty hash for an invalid language" do
|
89
|
+
territories = Territories.all_for(:blarg)
|
90
|
+
territories.should == {}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#all" do
|
95
|
+
it "should use the default language to get the language hash" do
|
96
|
+
territories = Territories.all
|
97
|
+
territories.should be_a(Hash)
|
98
|
+
territories[:ru].should match_normalized("Russia")
|
99
|
+
territories[:de].should match_normalized("Germany")
|
100
|
+
|
101
|
+
TwitterCldr.locale = :es
|
102
|
+
territories = Territories.all
|
103
|
+
territories.should be_a(Hash)
|
104
|
+
territories[:ru].should match_normalized("Rusia")
|
105
|
+
territories[:de].should match_normalized("Alemania")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "the lack of knowledge about three-digit UN area codes" do
|
110
|
+
it "should not be able to translate three-digit UN area codes" do
|
111
|
+
Territories.translate_territory("Southern Africa", :en, :es).should == nil
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not be able to name three-digit UN area codes" do
|
115
|
+
Territories.from_territory_code_for_locale(:"18", :es).should == nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -21,8 +21,22 @@ class FastGettext
|
|
21
21
|
@@locale
|
22
22
|
end
|
23
23
|
|
24
|
-
def locale=(
|
25
|
-
@@locale =
|
24
|
+
def locale=(new_locale)
|
25
|
+
@@locale = new_locale
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class I18n
|
31
|
+
class << self
|
32
|
+
@@locale = :en
|
33
|
+
|
34
|
+
def locale
|
35
|
+
@@locale
|
36
|
+
end
|
37
|
+
|
38
|
+
def locale=(new_locale)
|
39
|
+
@@locale = new_locale
|
26
40
|
end
|
27
41
|
end
|
28
42
|
end
|
@@ -35,7 +49,10 @@ RSpec.configure do |config|
|
|
35
49
|
config.filter_run_excluding(:slow => true) unless ENV['FULL_SPEC']
|
36
50
|
|
37
51
|
config.before(:each) do
|
52
|
+
TwitterCldr.reset_locale_fallbacks
|
53
|
+
TwitterCldr.locale = :en
|
38
54
|
FastGettext.locale = :en
|
55
|
+
I18n.locale = :en
|
39
56
|
end
|
40
57
|
end
|
41
58
|
|
data/spec/twitter_cldr_spec.rb
CHANGED
@@ -62,17 +62,242 @@ describe TwitterCldr do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe "#
|
66
|
-
context "with
|
67
|
-
it "should return the
|
68
|
-
|
69
|
-
TwitterCldr.
|
65
|
+
describe "#locale" do
|
66
|
+
context "with explicit locale" do
|
67
|
+
it "should return the same locale the user sets (if it's supported)" do
|
68
|
+
TwitterCldr.locale = :es
|
69
|
+
TwitterCldr.locale.should == :es
|
70
70
|
end
|
71
71
|
|
72
|
-
it "should
|
73
|
-
|
74
|
-
TwitterCldr.
|
72
|
+
it "should convert strings to symbols" do
|
73
|
+
TwitterCldr.locale = "es"
|
74
|
+
TwitterCldr.locale.should == :es
|
75
75
|
end
|
76
|
+
|
77
|
+
it "should fall back if the user sets an unsupported locale" do
|
78
|
+
FastGettext.locale = :ko
|
79
|
+
TwitterCldr.locale = "blarg"
|
80
|
+
TwitterCldr.locale.should == :ko
|
81
|
+
|
82
|
+
FastGettext.locale = nil
|
83
|
+
I18n.locale = :hu
|
84
|
+
TwitterCldr.locale.should == :hu
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with implicit locale (fallbacks)" do
|
89
|
+
before(:each) do
|
90
|
+
TwitterCldr.locale = nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return FastGettext locale before I18n locale and fall back gracefully" do
|
94
|
+
FastGettext.locale = :pt
|
95
|
+
I18n.locale = :ar
|
96
|
+
TwitterCldr.locale.should == :pt
|
97
|
+
|
98
|
+
FastGettext.locale = nil
|
99
|
+
TwitterCldr.locale.should == :ar
|
100
|
+
|
101
|
+
I18n.locale = nil
|
102
|
+
TwitterCldr.locale.should == :en
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with only FastGettext locale" do
|
106
|
+
before(:each) do
|
107
|
+
I18n.locale = nil # disable I18n fallback
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return the FastGettext locale if it's supported" do
|
111
|
+
FastGettext.locale = "vi"
|
112
|
+
TwitterCldr.locale.should == :vi
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should return the default locale if the FastGettext locale is unsupported" do
|
116
|
+
FastGettext.locale = "bogus"
|
117
|
+
TwitterCldr.locale.should == TwitterCldr::DEFAULT_LOCALE
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "with only I18n locale" do
|
122
|
+
before(:each) do
|
123
|
+
FastGettext.locale = nil # disable FastGettext fallback
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return the I18n locale if it's supported" do
|
127
|
+
I18n.locale = "ru"
|
128
|
+
TwitterCldr.locale.should == :ru
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should return the default locale if the I18n locale is unsupported" do
|
132
|
+
I18n.locale = "bogus"
|
133
|
+
TwitterCldr.locale.should == TwitterCldr::DEFAULT_LOCALE
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "with a custom fallback" do
|
138
|
+
before(:each) do
|
139
|
+
@allow = false
|
140
|
+
TwitterCldr.register_locale_fallback(lambda { @allow ? :uk : nil })
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should fall back to the custom locale" do
|
144
|
+
TwitterCldr.locale.should == :en
|
145
|
+
@allow = true
|
146
|
+
TwitterCldr.locale.should == :uk
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should fall back to the next fallback option if the custom one returns nil" do
|
150
|
+
FastGettext.locale = :lv
|
151
|
+
TwitterCldr.locale.should == :lv
|
152
|
+
@allow = true
|
153
|
+
TwitterCldr.locale.should == :uk
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should not return the fallback locale if it's unsupported" do
|
157
|
+
TwitterCldr.reset_locale_fallbacks
|
158
|
+
TwitterCldr.register_locale_fallback(lambda { :zzz })
|
159
|
+
TwitterCldr.locale.should == :en
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should fall back if the user sets an unsupported locale" do
|
164
|
+
FastGettext.locale = :ko
|
165
|
+
TwitterCldr.locale = "blarg"
|
166
|
+
TwitterCldr.locale.should == :ko
|
167
|
+
|
168
|
+
FastGettext.locale = nil
|
169
|
+
I18n.locale = :hu
|
170
|
+
TwitterCldr.locale.should == :hu
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "with implicit locale (fallbacks)" do
|
175
|
+
before(:each) do
|
176
|
+
TwitterCldr.locale = nil
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should return FastGettext locale before I18n locale and fall back gracefully" do
|
180
|
+
FastGettext.locale = :pt
|
181
|
+
I18n.locale = :ar
|
182
|
+
TwitterCldr.locale.should == :pt
|
183
|
+
|
184
|
+
FastGettext.locale = nil
|
185
|
+
TwitterCldr.locale.should == :ar
|
186
|
+
|
187
|
+
I18n.locale = nil
|
188
|
+
TwitterCldr.locale.should == :en
|
189
|
+
end
|
190
|
+
|
191
|
+
context "with only FastGettext locale" do
|
192
|
+
before(:each) do
|
193
|
+
I18n.locale = nil # disable I18n fallback
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should return the FastGettext locale if it's supported" do
|
197
|
+
FastGettext.locale = "vi"
|
198
|
+
TwitterCldr.locale.should == :vi
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should return the default locale if the FastGettext locale is unsupported" do
|
202
|
+
FastGettext.locale = "bogus"
|
203
|
+
TwitterCldr.locale.should == TwitterCldr::DEFAULT_LOCALE
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "with only I18n locale" do
|
208
|
+
before(:each) do
|
209
|
+
FastGettext.locale = nil # disable FastGettext fallback
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should return the I18n locale if it's supported" do
|
213
|
+
I18n.locale = "ru"
|
214
|
+
TwitterCldr.locale.should == :ru
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should return the default locale if the I18n locale is unsupported" do
|
218
|
+
I18n.locale = "bogus"
|
219
|
+
TwitterCldr.locale.should == TwitterCldr::DEFAULT_LOCALE
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "with a custom fallback" do
|
224
|
+
before(:each) do
|
225
|
+
@allow = false
|
226
|
+
TwitterCldr.register_locale_fallback(lambda { @allow ? :uk : nil })
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should fall back to the custom locale" do
|
230
|
+
TwitterCldr.locale.should == :en
|
231
|
+
@allow = true
|
232
|
+
TwitterCldr.locale.should == :uk
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should fall back to the next fallback option if the custom one returns nil" do
|
236
|
+
FastGettext.locale = :lv
|
237
|
+
TwitterCldr.locale.should == :lv
|
238
|
+
@allow = true
|
239
|
+
TwitterCldr.locale.should == :uk
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should not return the fallback locale if it's unsupported" do
|
243
|
+
TwitterCldr.reset_locale_fallbacks
|
244
|
+
TwitterCldr.register_locale_fallback(lambda { :zzz })
|
245
|
+
TwitterCldr.locale.should == :en
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "#with_locale" do
|
252
|
+
it "should only change the locale in the context of the block" do
|
253
|
+
TwitterCldr::Shared::Languages.from_code(:es).should == "Spanish"
|
254
|
+
TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }.should match_normalized("español")
|
255
|
+
TwitterCldr::Shared::Languages.from_code(:es).should == "Spanish"
|
256
|
+
end
|
257
|
+
|
258
|
+
it "switches the locale back to the original if the block raises an error" do
|
259
|
+
TwitterCldr.locale.should == :en
|
260
|
+
locale_inside_block = nil
|
261
|
+
|
262
|
+
lambda do
|
263
|
+
TwitterCldr.with_locale(:es) do
|
264
|
+
locale_inside_block = TwitterCldr.locale
|
265
|
+
raise "Error!"
|
266
|
+
end
|
267
|
+
end.should raise_error
|
268
|
+
|
269
|
+
locale_inside_block.should == :es
|
270
|
+
TwitterCldr.locale.should == :en
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "#with_locale" do
|
275
|
+
it "should only change the locale in the context of the block" do
|
276
|
+
TwitterCldr::Shared::Languages.from_code(:es).should == "Spanish"
|
277
|
+
TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }.should match_normalized("español")
|
278
|
+
TwitterCldr::Shared::Languages.from_code(:es).should == "Spanish"
|
279
|
+
end
|
280
|
+
|
281
|
+
it "doesn't mess up if the given locale isn't supported" do
|
282
|
+
TwitterCldr.locale = :pt
|
283
|
+
TwitterCldr.locale.should == :pt
|
284
|
+
lambda { TwitterCldr.with_locale(:xx) {} }.should raise_error
|
285
|
+
TwitterCldr.locale.should == :pt
|
286
|
+
end
|
287
|
+
|
288
|
+
it "switches the locale back to the original if the block raises an error" do
|
289
|
+
TwitterCldr.locale.should == :en
|
290
|
+
locale_inside_block = nil
|
291
|
+
|
292
|
+
lambda do
|
293
|
+
TwitterCldr.with_locale(:es) do
|
294
|
+
locale_inside_block = TwitterCldr.locale
|
295
|
+
raise "Error!"
|
296
|
+
end
|
297
|
+
end.should raise_error
|
298
|
+
|
299
|
+
locale_inside_block.should == :es
|
300
|
+
TwitterCldr.locale.should == :en
|
76
301
|
end
|
77
302
|
end
|
78
303
|
|
@@ -104,4 +329,4 @@ describe TwitterCldr do
|
|
104
329
|
TwitterCldr.get_locale_resource(:de, :numbers).should == 'result'
|
105
330
|
end
|
106
331
|
end
|
107
|
-
end
|
332
|
+
end
|
@@ -0,0 +1,16 @@
|
|
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
|
+
describe TwitterCldr::Utils::Territories do
|
9
|
+
describe "#deep_normalize_territory_code_keys" do
|
10
|
+
TwitterCldr::Utils::Territories.deep_normalize_territory_code_keys(
|
11
|
+
{ "is" => [ { "US" => "United States",
|
12
|
+
5 => "Suður-Ameríka" },
|
13
|
+
{ "009" => "Eyjaálfa" } ] }
|
14
|
+
).should == { :is => [ { :us => "United States" }, { } ] }
|
15
|
+
end
|
16
|
+
end
|
data/spec/utils_spec.rb
CHANGED