twitter_cldr 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NOTICE +95 -1
- data/README.md +4 -4
- data/Rakefile +18 -28
- data/lib/ext/calendars/date.rb +3 -0
- data/lib/ext/calendars/datetime.rb +3 -0
- data/lib/ext/calendars/time.rb +3 -0
- data/lib/ext/localized_object.rb +3 -0
- data/lib/ext/numbers/bignum.rb +3 -0
- data/lib/ext/numbers/fixnum.rb +3 -0
- data/lib/ext/numbers/float.rb +3 -0
- data/lib/ext/numbers/localized_number.rb +3 -0
- data/lib/ext/strings/string.rb +31 -0
- data/lib/ext/strings/symbol.rb +3 -0
- data/lib/formatters/base.rb +3 -0
- data/lib/formatters/calendars/date_formatter.rb +3 -0
- data/lib/formatters/calendars/datetime_formatter.rb +3 -0
- data/lib/formatters/calendars/time_formatter.rb +3 -0
- data/lib/formatters/numbers/currency_formatter.rb +3 -0
- data/lib/formatters/numbers/decimal_formatter.rb +3 -0
- data/lib/formatters/numbers/helpers/base.rb +3 -0
- data/lib/formatters/numbers/helpers/fraction.rb +3 -0
- data/lib/formatters/numbers/helpers/integer.rb +3 -0
- data/lib/formatters/numbers/number_formatter.rb +3 -0
- data/lib/formatters/numbers/percent_formatter.rb +3 -0
- data/lib/formatters/plurals/plural_formatter.rb +141 -0
- data/lib/formatters/plurals/rules.rb +4 -1
- data/lib/normalizers/base.rb +17 -0
- data/lib/normalizers/canonical/nfd.rb +81 -0
- data/lib/shared/currencies.rb +4 -1
- data/lib/shared/languages.rb +4 -1
- data/lib/shared/resources.rb +8 -28
- data/lib/shared/timezones.rb +3 -0
- data/lib/shared/unicode_data.rb +44 -0
- data/lib/tokenizers/base.rb +3 -0
- data/lib/tokenizers/calendars/date_tokenizer.rb +3 -0
- data/lib/tokenizers/calendars/datetime_tokenizer.rb +4 -1
- data/lib/tokenizers/calendars/time_tokenizer.rb +3 -0
- data/lib/tokenizers/key_path.rb +3 -0
- data/lib/tokenizers/numbers/number_tokenizer.rb +4 -1
- data/lib/tokenizers/token.rb +3 -0
- data/lib/twitter_cldr.rb +52 -29
- data/lib/utils/interpolation.rb +105 -0
- data/lib/utils.rb +28 -0
- data/lib/version.rb +6 -1
- data/resources/unicode_data/aegean_numbers.yml +913 -0
- data/resources/unicode_data/alchemical_symbols.yml +1857 -0
- data/resources/unicode_data/alphabetic_presentation_forms.yml +929 -0
- data/resources/unicode_data/ancient_greek_musical_notation.yml +1121 -0
- data/resources/unicode_data/ancient_greek_numbers.yml +1201 -0
- data/resources/unicode_data/ancient_symbols.yml +193 -0
- data/resources/unicode_data/arabic.yml +4049 -0
- data/resources/unicode_data/arabic_extended_a.yml +625 -0
- data/resources/unicode_data/arabic_mathematical_alphabetic_symbols.yml +2289 -0
- data/resources/unicode_data/arabic_presentation_forms_a.yml +9777 -0
- data/resources/unicode_data/arabic_presentation_forms_b.yml +2257 -0
- data/resources/unicode_data/arabic_supplement.yml +769 -0
- data/resources/unicode_data/armenian.yml +1393 -0
- data/resources/unicode_data/arrows.yml +1793 -0
- data/resources/unicode_data/avestan.yml +977 -0
- data/resources/unicode_data/balinese.yml +1937 -0
- data/resources/unicode_data/bamum.yml +1409 -0
- data/resources/unicode_data/bamum_supplement.yml +9105 -0
- data/resources/unicode_data/basic_latin.yml +2049 -0
- data/resources/unicode_data/batak.yml +897 -0
- data/resources/unicode_data/bengali.yml +1473 -0
- data/resources/unicode_data/block_elements.yml +513 -0
- data/resources/unicode_data/blocks.yml +881 -0
- data/resources/unicode_data/bopomofo.yml +657 -0
- data/resources/unicode_data/bopomofo_extended.yml +433 -0
- data/resources/unicode_data/box_drawing.yml +2049 -0
- data/resources/unicode_data/brahmi.yml +1729 -0
- data/resources/unicode_data/braille_patterns.yml +4097 -0
- data/resources/unicode_data/buginese.yml +481 -0
- data/resources/unicode_data/buhid.yml +321 -0
- data/resources/unicode_data/byzantine_musical_symbols.yml +3937 -0
- data/resources/unicode_data/carian.yml +785 -0
- data/resources/unicode_data/chakma.yml +1073 -0
- data/resources/unicode_data/cham.yml +1329 -0
- data/resources/unicode_data/cherokee.yml +1361 -0
- data/resources/unicode_data/cjk_compatibility.yml +4097 -0
- data/resources/unicode_data/cjk_compatibility_forms.yml +513 -0
- data/resources/unicode_data/cjk_compatibility_ideographs.yml +7553 -0
- data/resources/unicode_data/cjk_compatibility_ideographs_supplement.yml +8673 -0
- data/resources/unicode_data/cjk_radicals_supplement.yml +1841 -0
- data/resources/unicode_data/cjk_strokes.yml +577 -0
- data/resources/unicode_data/cjk_symbols_and_punctuation.yml +1025 -0
- data/resources/unicode_data/cjk_unified_ideographs.yml +33 -0
- data/resources/unicode_data/cjk_unified_ideographs_extension_a.yml +33 -0
- data/resources/unicode_data/cjk_unified_ideographs_extension_b.yml +33 -0
- data/resources/unicode_data/cjk_unified_ideographs_extension_c.yml +33 -0
- data/resources/unicode_data/cjk_unified_ideographs_extension_d.yml +33 -0
- data/resources/unicode_data/combining_diacritical_marks.yml +1793 -0
- data/resources/unicode_data/combining_diacritical_marks_for_symbols.yml +529 -0
- data/resources/unicode_data/combining_diacritical_marks_supplement.yml +689 -0
- data/resources/unicode_data/combining_half_marks.yml +113 -0
- data/resources/unicode_data/common_indic_number_forms.yml +161 -0
- data/resources/unicode_data/control_pictures.yml +625 -0
- data/resources/unicode_data/coptic.yml +1969 -0
- data/resources/unicode_data/counting_rod_numerals.yml +289 -0
- data/resources/unicode_data/cuneiform.yml +14065 -0
- data/resources/unicode_data/cuneiform_numbers_and_punctuation.yml +1649 -0
- data/resources/unicode_data/currency_symbols.yml +417 -0
- data/resources/unicode_data/cypriot_syllabary.yml +881 -0
- data/resources/unicode_data/cyrillic.yml +4097 -0
- data/resources/unicode_data/cyrillic_extended_a.yml +513 -0
- data/resources/unicode_data/cyrillic_extended_b.yml +1425 -0
- data/resources/unicode_data/cyrillic_supplement.yml +641 -0
- data/resources/unicode_data/deseret.yml +1281 -0
- data/resources/unicode_data/devanagari.yml +2033 -0
- data/resources/unicode_data/devanagari_extended.yml +449 -0
- data/resources/unicode_data/dingbats.yml +3057 -0
- data/resources/unicode_data/domino_tiles.yml +1601 -0
- data/resources/unicode_data/egyptian_hieroglyphs.yml +17137 -0
- data/resources/unicode_data/emoticons.yml +1217 -0
- data/resources/unicode_data/enclosed_alphanumeric_supplement.yml +2737 -0
- data/resources/unicode_data/enclosed_alphanumerics.yml +2561 -0
- data/resources/unicode_data/enclosed_cjk_letters_and_months.yml +4065 -0
- data/resources/unicode_data/enclosed_ideographic_supplement.yml +913 -0
- data/resources/unicode_data/ethiopic.yml +5729 -0
- data/resources/unicode_data/ethiopic_extended.yml +1265 -0
- data/resources/unicode_data/ethiopic_extended_a.yml +513 -0
- data/resources/unicode_data/ethiopic_supplement.yml +417 -0
- data/resources/unicode_data/general_punctuation.yml +1713 -0
- data/resources/unicode_data/geometric_shapes.yml +1537 -0
- data/resources/unicode_data/georgian.yml +1409 -0
- data/resources/unicode_data/georgian_supplement.yml +641 -0
- data/resources/unicode_data/glagolitic.yml +1505 -0
- data/resources/unicode_data/gothic.yml +433 -0
- data/resources/unicode_data/greek_and_coptic.yml +2145 -0
- data/resources/unicode_data/greek_extended.yml +3729 -0
- data/resources/unicode_data/gujarati.yml +1345 -0
- data/resources/unicode_data/gurmukhi.yml +1265 -0
- data/resources/unicode_data/halfwidth_and_fullwidth_forms.yml +3601 -0
- data/resources/unicode_data/hangul_compatibility_jamo.yml +1505 -0
- data/resources/unicode_data/hangul_jamo.yml +4097 -0
- data/resources/unicode_data/hangul_jamo_extended_a.yml +465 -0
- data/resources/unicode_data/hangul_jamo_extended_b.yml +1153 -0
- data/resources/unicode_data/hangul_syllables.yml +33 -0
- data/resources/unicode_data/hanunoo.yml +369 -0
- data/resources/unicode_data/hebrew.yml +1393 -0
- data/resources/unicode_data/high_private_use_surrogates.yml +33 -0
- data/resources/unicode_data/high_surrogates.yml +33 -0
- data/resources/unicode_data/hiragana.yml +1489 -0
- data/resources/unicode_data/ideographic_description_characters.yml +193 -0
- data/resources/unicode_data/imperial_aramaic.yml +497 -0
- data/resources/unicode_data/inscriptional_pahlavi.yml +433 -0
- data/resources/unicode_data/inscriptional_parthian.yml +481 -0
- data/resources/unicode_data/ipa_extensions.yml +1537 -0
- data/resources/unicode_data/javanese.yml +1457 -0
- data/resources/unicode_data/kaithi.yml +1057 -0
- data/resources/unicode_data/kana_supplement.yml +33 -0
- data/resources/unicode_data/kanbun.yml +257 -0
- data/resources/unicode_data/kangxi_radicals.yml +3425 -0
- data/resources/unicode_data/kannada.yml +1377 -0
- data/resources/unicode_data/katakana.yml +1537 -0
- data/resources/unicode_data/katakana_phonetic_extensions.yml +257 -0
- data/resources/unicode_data/kayah_li.yml +769 -0
- data/resources/unicode_data/kharoshthi.yml +1041 -0
- data/resources/unicode_data/khmer.yml +1825 -0
- data/resources/unicode_data/khmer_symbols.yml +513 -0
- data/resources/unicode_data/lao.yml +1073 -0
- data/resources/unicode_data/latin_1_supplement.yml +2049 -0
- data/resources/unicode_data/latin_extended_a.yml +2049 -0
- data/resources/unicode_data/latin_extended_additional.yml +4097 -0
- data/resources/unicode_data/latin_extended_b.yml +3329 -0
- data/resources/unicode_data/latin_extended_c.yml +513 -0
- data/resources/unicode_data/latin_extended_d.yml +2145 -0
- data/resources/unicode_data/lepcha.yml +1185 -0
- data/resources/unicode_data/letterlike_symbols.yml +1281 -0
- data/resources/unicode_data/limbu.yml +1057 -0
- data/resources/unicode_data/linear_b_ideograms.yml +1969 -0
- data/resources/unicode_data/linear_b_syllabary.yml +1409 -0
- data/resources/unicode_data/lisu.yml +769 -0
- data/resources/unicode_data/low_surrogates.yml +33 -0
- data/resources/unicode_data/lycian.yml +465 -0
- data/resources/unicode_data/lydian.yml +433 -0
- data/resources/unicode_data/mahjong_tiles.yml +705 -0
- data/resources/unicode_data/malayalam.yml +1569 -0
- data/resources/unicode_data/mandaic.yml +465 -0
- data/resources/unicode_data/mathematical_alphanumeric_symbols.yml +15937 -0
- data/resources/unicode_data/mathematical_operators.yml +4097 -0
- data/resources/unicode_data/meetei_mayek.yml +897 -0
- data/resources/unicode_data/meetei_mayek_extensions.yml +369 -0
- data/resources/unicode_data/meroitic_cursive.yml +417 -0
- data/resources/unicode_data/meroitic_hieroglyphs.yml +513 -0
- data/resources/unicode_data/miao.yml +2129 -0
- data/resources/unicode_data/miscellaneous_mathematical_symbols_a.yml +769 -0
- data/resources/unicode_data/miscellaneous_mathematical_symbols_b.yml +2049 -0
- data/resources/unicode_data/miscellaneous_symbols.yml +4097 -0
- data/resources/unicode_data/miscellaneous_symbols_and_arrows.yml +1393 -0
- data/resources/unicode_data/miscellaneous_symbols_and_pictographs.yml +8529 -0
- data/resources/unicode_data/miscellaneous_technical.yml +3905 -0
- data/resources/unicode_data/modifier_tone_letters.yml +513 -0
- data/resources/unicode_data/mongolian.yml +2497 -0
- data/resources/unicode_data/musical_symbols.yml +3521 -0
- data/resources/unicode_data/myanmar.yml +2561 -0
- data/resources/unicode_data/myanmar_extended_a.yml +449 -0
- data/resources/unicode_data/new_tai_lue.yml +1329 -0
- data/resources/unicode_data/nko.yml +945 -0
- data/resources/unicode_data/number_forms.yml +929 -0
- data/resources/unicode_data/ogham.yml +465 -0
- data/resources/unicode_data/ol_chiki.yml +769 -0
- data/resources/unicode_data/old_italic.yml +561 -0
- data/resources/unicode_data/old_persian.yml +801 -0
- data/resources/unicode_data/old_south_arabian.yml +513 -0
- data/resources/unicode_data/old_turkic.yml +1169 -0
- data/resources/unicode_data/optical_character_recognition.yml +177 -0
- data/resources/unicode_data/oriya.yml +1441 -0
- data/resources/unicode_data/osmanya.yml +641 -0
- data/resources/unicode_data/phags_pa.yml +897 -0
- data/resources/unicode_data/phaistos_disc.yml +737 -0
- data/resources/unicode_data/phoenician.yml +465 -0
- data/resources/unicode_data/phonetic_extensions.yml +2049 -0
- data/resources/unicode_data/phonetic_extensions_supplement.yml +1025 -0
- data/resources/unicode_data/playing_cards.yml +945 -0
- data/resources/unicode_data/private_use_area.yml +33 -0
- data/resources/unicode_data/rejang.yml +593 -0
- data/resources/unicode_data/rumi_numeral_symbols.yml +497 -0
- data/resources/unicode_data/runic.yml +1297 -0
- data/resources/unicode_data/samaritan.yml +977 -0
- data/resources/unicode_data/saurashtra.yml +1297 -0
- data/resources/unicode_data/sharada.yml +1329 -0
- data/resources/unicode_data/shavian.yml +769 -0
- data/resources/unicode_data/sinhala.yml +1281 -0
- data/resources/unicode_data/small_form_variants.yml +417 -0
- data/resources/unicode_data/sora_sompeng.yml +561 -0
- data/resources/unicode_data/spacing_modifier_letters.yml +1281 -0
- data/resources/unicode_data/specials.yml +81 -0
- data/resources/unicode_data/sundanese.yml +1025 -0
- data/resources/unicode_data/sundanese_supplement.yml +129 -0
- data/resources/unicode_data/superscripts_and_subscripts.yml +673 -0
- data/resources/unicode_data/supplemental_arrows_a.yml +257 -0
- data/resources/unicode_data/supplemental_arrows_b.yml +2049 -0
- data/resources/unicode_data/supplemental_mathematical_operators.yml +4097 -0
- data/resources/unicode_data/supplemental_punctuation.yml +961 -0
- data/resources/unicode_data/supplementary_private_use_area_a.yml +33 -0
- data/resources/unicode_data/supplementary_private_use_area_b.yml +33 -0
- data/resources/unicode_data/syloti_nagri.yml +705 -0
- data/resources/unicode_data/syriac.yml +1233 -0
- data/resources/unicode_data/tagalog.yml +321 -0
- data/resources/unicode_data/tagbanwa.yml +289 -0
- data/resources/unicode_data/tags.yml +1553 -0
- data/resources/unicode_data/tai_le.yml +561 -0
- data/resources/unicode_data/tai_tham.yml +2033 -0
- data/resources/unicode_data/tai_viet.yml +1153 -0
- data/resources/unicode_data/tai_xuan_jing_symbols.yml +1393 -0
- data/resources/unicode_data/takri.yml +1057 -0
- data/resources/unicode_data/tamil.yml +1153 -0
- data/resources/unicode_data/telugu.yml +1489 -0
- data/resources/unicode_data/thaana.yml +801 -0
- data/resources/unicode_data/thai.yml +1393 -0
- data/resources/unicode_data/tibetan.yml +3377 -0
- data/resources/unicode_data/tifinagh.yml +945 -0
- data/resources/unicode_data/transport_and_map_symbols.yml +1121 -0
- data/resources/unicode_data/ugaritic.yml +497 -0
- data/resources/unicode_data/unified_canadian_aboriginal_syllabics.yml +10241 -0
- data/resources/unicode_data/unified_canadian_aboriginal_syllabics_extended.yml +1121 -0
- data/resources/unicode_data/vai.yml +4801 -0
- data/resources/unicode_data/variation_selectors.yml +257 -0
- data/resources/unicode_data/variation_selectors_supplement.yml +3841 -0
- data/resources/unicode_data/vedic_extensions.yml +625 -0
- data/resources/unicode_data/vertical_forms.yml +161 -0
- data/resources/unicode_data/yi_radicals.yml +881 -0
- data/resources/unicode_data/yi_syllables.yml +18641 -0
- data/resources/unicode_data/yijing_hexagram_symbols.yml +1025 -0
- data/spec/ext/calendars/date_spec.rb +5 -1
- data/spec/ext/calendars/datetime_spec.rb +5 -1
- data/spec/ext/calendars/time_spec.rb +5 -1
- data/spec/ext/numbers/bignum_spec.rb +5 -1
- data/spec/ext/numbers/fixnum_spec.rb +5 -1
- data/spec/ext/numbers/float_spec.rb +5 -1
- data/spec/ext/numbers/localized_number_spec.rb +5 -1
- data/spec/ext/strings/string_spec.rb +102 -0
- data/spec/ext/strings/symbol_spec.rb +5 -1
- data/spec/formatters/base_spec.rb +5 -1
- data/spec/formatters/calendars/datetime_formatter_spec.rb +5 -1
- data/spec/formatters/numbers/currency_formatter_spec.rb +5 -1
- data/spec/formatters/numbers/decimal_formatter_spec.rb +5 -1
- data/spec/formatters/numbers/helpers/fraction_spec.rb +5 -1
- data/spec/formatters/numbers/helpers/integer_spec.rb +5 -1
- data/spec/formatters/numbers/number_formatter_spec.rb +6 -2
- data/spec/formatters/numbers/percent_formatter_spec.rb +5 -1
- data/spec/formatters/plurals/plural_formatter_spec.rb +205 -0
- data/spec/formatters/plurals/rules_spec.rb +28 -28
- data/spec/normalizers/NormalizationTest.txt +602 -0
- data/spec/normalizers/base_spec.rb +16 -0
- data/spec/normalizers/canonical/nfd_spec.rb +50 -0
- data/spec/shared/currencies_spec.rb +5 -1
- data/spec/shared/languages_spec.rb +5 -1
- data/spec/shared/resources_spec.rb +5 -18
- data/spec/shared/unicode_data_spec.rb +51 -0
- data/spec/spec_helper.rb +6 -3
- data/spec/tokenizers/base_spec.rb +3 -0
- data/spec/tokenizers/calendars/date_tokenizer_spec.rb +5 -1
- data/spec/tokenizers/calendars/datetime_tokenizer_spec.rb +5 -1
- data/spec/tokenizers/calendars/time_tokenizer_spec.rb +5 -1
- data/spec/tokenizers/key_path_spec.rb +3 -0
- data/spec/tokenizers/numbers/number_tokenizer_spec.rb +5 -1
- data/spec/tokenizers/token_spec.rb +5 -1
- data/spec/twitter_cldr_spec.rb +23 -1
- data/spec/utils/interpolation_spec.rb +124 -0
- data/spec/utils_spec.rb +32 -0
- metadata +285 -21
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr
|
5
9
|
|
6
10
|
describe DateTime do
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr
|
5
9
|
|
6
10
|
describe Bignum do
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr
|
5
9
|
|
6
10
|
describe Fixnum do
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr
|
5
9
|
|
6
10
|
describe LocalizedNumber do
|
@@ -0,0 +1,102 @@
|
|
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
|
9
|
+
|
10
|
+
describe String do
|
11
|
+
|
12
|
+
describe '#localize' do
|
13
|
+
it 'returns localized string object' do
|
14
|
+
'foo'.localize.should be_a(LocalizedString)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "uses default locale if it's not explicitly specified" do
|
18
|
+
mock(TwitterCldr).get_locale { :jp }
|
19
|
+
'foo'.localize.locale.should == :jp
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'uses provided locale if there is one' do
|
23
|
+
'foo'.localize(:ru).locale.should == :ru
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe LocalizedString do
|
30
|
+
describe '#%' do
|
31
|
+
context 'when argument is not a Hash' do
|
32
|
+
it 'performs regular formatting of values' do
|
33
|
+
('%d is an integer'.localize % 3.14).should == '3 is an integer'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'performs regular formatting of arrays' do
|
37
|
+
('"% 04d" is a %s'.localize % [12, 'number']).should == '" 012" is a number'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'ignores pluralization placeholders' do
|
41
|
+
('%s: %{horses_count:horses}'.localize % 'total').should == 'total: %{horses_count:horses}'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'raises ArgumentError when the string contains named placeholder' do
|
45
|
+
lambda { '%{msg}: %{horses_count:horses}'.localize % 'total' }.should raise_error(ArgumentError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when argument is a Hash' do
|
50
|
+
let(:horses) { { :one => '1 horse', :other => '%{horses_count} horses' } }
|
51
|
+
|
52
|
+
before(:each) do
|
53
|
+
stub(Formatters::Plurals::Rules).rule_for { |n, _| n == 1 ? :one : :other }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'interpolates named placeholders' do
|
57
|
+
('%<num>.2f is a %{noun}'.localize % { :num => 3.1415, :noun => 'number' }).should == '3.14 is a number'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'performs regular pluralization' do
|
61
|
+
('%{horses_count:horses}'.localize % { :horses_count => 2, :horses => horses }).should == '2 horses'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'performs inline pluralization' do
|
65
|
+
string = '%<{ "horses_count": { "other": "%{horses_count} horses" } }>'.localize
|
66
|
+
(string % { :horses_count => 2 }).should == '2 horses'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'performs both formatting and regular pluralization simultaneously' do
|
70
|
+
string = '%{msg}: %{horses_count:horses}'.localize
|
71
|
+
(string % { :horses_count => 2, :horses => horses, :msg => 'result' }).should == 'result: 2 horses'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'performs both formatting and inline pluralization simultaneously' do
|
75
|
+
string = '%{msg}: %<{"horses_count": {"other": "%{horses_count} horses"}}>'.localize
|
76
|
+
(string % { :horses_count => 2, :msg => 'result' }).should == 'result: 2 horses'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'performs both formatted interpolation and inline pluralization simultaneously' do
|
80
|
+
string = '%<number>d, %<{"horses_count": {"other": "%{horses_count} horses" }}>'.localize
|
81
|
+
(string % { :number => 3.14, :horses_count => 2 }).should == '3, 2 horses'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'leaves regular pluralization placeholders unchanged if not enough information given' do
|
85
|
+
string = '%{msg}: %{horses_count:horses}'.localize
|
86
|
+
(string % { :msg => 'no pluralization' } ).should == 'no pluralization: %{horses_count:horses}'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'leaves inline pluralization placeholders unchanged if not enough information given' do
|
90
|
+
string = '%<number>d, %<{"horses_count": {"one": "one horse"}}>'.localize
|
91
|
+
(string % { :number => 3.14, :horses_count => 2 }).should == '3, %<{"horses_count": {"one": "one horse"}}>'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'raises KeyError when value for a named placeholder is missing' do
|
95
|
+
lambda do
|
96
|
+
'%{msg}: %{horses_count:horses}'.localize % { :horses_count => 2, :horses => horses }
|
97
|
+
end.should raise_error(KeyError)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr
|
5
9
|
|
6
10
|
describe LocalizedSymbol do
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters
|
5
9
|
|
6
10
|
describe DateTimeFormatter do
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters
|
5
9
|
|
6
10
|
describe CurrencyFormatter do
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters
|
5
9
|
|
6
10
|
describe DecimalFormatter do
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters::Numbers
|
5
9
|
include TwitterCldr::Tokenizers
|
6
10
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters::Numbers
|
5
9
|
include TwitterCldr::Tokenizers
|
6
10
|
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters
|
5
9
|
|
6
10
|
describe NumberFormatter do
|
@@ -78,4 +82,4 @@ describe NumberFormatter do
|
|
78
82
|
@formatter.format(1337.37).should == "1 337,37"
|
79
83
|
end
|
80
84
|
end
|
81
|
-
end
|
85
|
+
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters
|
5
9
|
|
6
10
|
describe PercentFormatter do
|
@@ -0,0 +1,205 @@
|
|
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::Formatters
|
9
|
+
|
10
|
+
describe PluralFormatter do
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
it 'fetches locale from options hash' do
|
14
|
+
PluralFormatter.new(:locale => :ru).locale.should == :ru
|
15
|
+
end
|
16
|
+
|
17
|
+
it "uses default locale if it's not passed in options hash" do
|
18
|
+
PluralFormatter.new.locale.should == TwitterCldr::DEFAULT_LOCALE
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#format' do
|
23
|
+
subject { PluralFormatter.new }
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
stub(subject).pluralization_rule { |n| n == 1 ? :one : :other }
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:horses) { { :one => 'is 1 horse', :other => 'are %{horses_count} horses' } }
|
30
|
+
let(:horses_string) { '%<{ "horses_count": {"one": "is 1 horse", "other": "are %{horses_count} horses"} }>' }
|
31
|
+
|
32
|
+
let(:simple_horses) { { :one => '1 horse', :other => '%{horses_count} horses' } }
|
33
|
+
let(:simple_horses_string) { '%<{ "horses_count": {"one": "1 horse", "other": "%{horses_count} horses"} }>' }
|
34
|
+
|
35
|
+
let(:to_be) { { :one => 'is', :other => 'are' } }
|
36
|
+
let(:yaks) { { :one => 'is 1 yak', :other => 'are %{yaks_count} yaks' } }
|
37
|
+
|
38
|
+
context 'when there is nothing to pluralize' do
|
39
|
+
it "doesn't change the string if no interpolation found" do
|
40
|
+
string = 'no interpolation here'
|
41
|
+
subject.format(string, {}).should == string
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with regular pluralization' do
|
45
|
+
it "doesn't change the string if a number is not provided" do
|
46
|
+
string = 'there %{horses_count:horses}'
|
47
|
+
subject.format(string, :horses => horses).should == string
|
48
|
+
end
|
49
|
+
|
50
|
+
it "doesn't change the string if a patterns hash is not provided" do
|
51
|
+
string = 'there %{horses_count:horses}'
|
52
|
+
subject.format(string, :horses_count => 1).should == string
|
53
|
+
end
|
54
|
+
|
55
|
+
it "doesn't change the string if required pattern is not provided" do
|
56
|
+
string = 'there %{horses_count:horses}'
|
57
|
+
subject.format(string, :horses_count => 2, :horses => { :one => 'is 1 horse' }).should == string
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with inline pluralization' do
|
62
|
+
it "doesn't change the string if a number is not provided" do
|
63
|
+
string = "there #{horses_string}"
|
64
|
+
subject.format(string, {}).should == string
|
65
|
+
end
|
66
|
+
|
67
|
+
it "doesn't change the string if required pattern is not provided" do
|
68
|
+
string = 'there %<{ "horses_count": {"one": "is 1 horse"} }>'
|
69
|
+
subject.format(string, :horses_count => 2).should == string
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with mixed pluralization' do
|
74
|
+
it "doesn't change the string if a number is not provided" do
|
75
|
+
string = "there #{horses_string} %{horses_count:horses}"
|
76
|
+
subject.format(string, :horses => horses).should == string
|
77
|
+
end
|
78
|
+
|
79
|
+
it "doesn't change the string if required pattern is not provided" do
|
80
|
+
string = 'there %<{ "horses_count": {"one": "is 1 horse"} }> %{horses_count:horses}'
|
81
|
+
subject.format(string, :horses_count => 2, :horses => { :one => 'is 1 horse' }).should == string
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when something should be pluralized' do
|
87
|
+
context 'with regular pluralization' do
|
88
|
+
it 'pluralizes with a simple replacement' do
|
89
|
+
subject.format(
|
90
|
+
'there %{horses_count:horses}',
|
91
|
+
:horses_count => 1, :horses => horses
|
92
|
+
).should == 'there is 1 horse'
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'pluralizes when there are named interpolation patterns in the string' do
|
96
|
+
subject.format(
|
97
|
+
'%{there} %{horses_count:horses}',
|
98
|
+
:horses_count => 1, :horses => horses
|
99
|
+
).should == '%{there} is 1 horse'
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'supports multiple patterns sets for the same number' do
|
103
|
+
subject.format(
|
104
|
+
'there %{horses_count:to_be} %{horses_count:horses}',
|
105
|
+
:horses_count => 1, :horses => simple_horses, :to_be => to_be
|
106
|
+
).should == 'there is 1 horse'
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'pluralizes multiple entries' do
|
110
|
+
subject.format(
|
111
|
+
'there %{yaks_count:yaks} and %{horses_count:horses}',
|
112
|
+
:yaks_count => 1, :yaks => yaks, :horses_count => 2, :horses => simple_horses
|
113
|
+
).should == 'there is 1 yak and 2 horses'
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'substitutes the number for a placeholder in the pattern' do
|
117
|
+
subject.format(
|
118
|
+
'there %{horses_count:horses}',
|
119
|
+
:horses_count => 3, :horses => horses
|
120
|
+
).should == 'there are 3 horses'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'substitutes the number for multiple placeholders in the pattern' do
|
124
|
+
subject.format(
|
125
|
+
'there are %{horses_count:horses}',
|
126
|
+
:horses_count => 3, :horses => { :other => '%{horses_count}, seriously %{horses_count}, horses' }
|
127
|
+
).should == 'there are 3, seriously 3, horses'
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'throws an exception if pluralization patterns is not a hash' do
|
131
|
+
lambda do
|
132
|
+
subject.format('there %{horses_count:horses}', :horses_count => 1, :horses => [])
|
133
|
+
end.should raise_error(ArgumentError, 'expected patterns to be a Hash')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'with inline pluralization' do
|
138
|
+
it 'pluralizes with a simple replacement' do
|
139
|
+
subject.format("there #{horses_string}", :horses_count => 1).should == 'there is 1 horse'
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'pluralizes when there are named interpolation patterns in the string' do
|
143
|
+
subject.format("%{there} #{horses_string}", :horses_count => 1).should == '%{there} is 1 horse'
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'supports multiple patterns sets for the same number' do
|
147
|
+
subject.format(
|
148
|
+
%Q(there %<{ "horses_count": {"one": "is", "other": "are"} }> #{simple_horses_string}), :horses_count => 1
|
149
|
+
).should == 'there is 1 horse'
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'pluralizes multiple entries' do
|
153
|
+
subject.format(
|
154
|
+
%Q(there %<{ "yaks_count": {"one": "is 1 yak", "other": "are %{yaks_count} yaks"} }> and #{simple_horses_string}),
|
155
|
+
:yaks_count => 1, :horses_count => 2
|
156
|
+
).should == 'there is 1 yak and 2 horses'
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'substitutes the number for a placeholder in the pattern' do
|
160
|
+
subject.format(
|
161
|
+
"there #{horses_string}", :horses_count => 3, :horses => horses
|
162
|
+
).should == 'there are 3 horses'
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'substitutes the number for multiple placeholders in the pattern' do
|
166
|
+
subject.format(
|
167
|
+
'there are %<{ "horses_count": {"other": "%{horses_count}, seriously %{horses_count}, horses"} }>',
|
168
|
+
:horses_count => 3
|
169
|
+
).should == 'there are 3, seriously 3, horses'
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'throws an exception if pluralization hash has more than one key' do
|
173
|
+
lambda do
|
174
|
+
subject.format('there are %<{ "horses_count": {}, "foo": {} }>', {})
|
175
|
+
end.should raise_error(ArgumentError, 'expected a Hash with a single key')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'with mixed pluralization' do
|
180
|
+
it 'pluralizes separate groups' do
|
181
|
+
subject.format(
|
182
|
+
"there %{yaks_count:yaks} and #{simple_horses_string}",
|
183
|
+
:yaks => yaks, :yaks_count => 3, :horses_count => 2
|
184
|
+
).should == 'there are 3 yaks and 2 horses'
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'pluralizes similar groups' do
|
188
|
+
subject.format(
|
189
|
+
"there %{horses_count:horses} + #{simple_horses_string}",
|
190
|
+
:horses => horses, :horses_count => 2
|
191
|
+
).should == 'there are 2 horses + 2 horses'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
describe '#pluralization_rule' do
|
199
|
+
it 'delegates pluralization rule fetching to Rules.rule_for method' do
|
200
|
+
mock(Plurals::Rules).rule_for(42, :jp) { 'result' }
|
201
|
+
PluralFormatter.new(:locale => :jp).send(:pluralization_rule, 42).should == 'result'
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
@@ -1,20 +1,28 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
4
8
|
include TwitterCldr::Formatters::Plurals
|
5
9
|
|
6
10
|
describe Rules do
|
7
11
|
describe "#get_resource" do
|
8
12
|
it "calls eval on the hash that gets returned, lambdas and all" do
|
9
13
|
result = Rules.send(:get_resource, :ru)
|
10
|
-
result.should include(:ru)
|
11
|
-
result[:ru].should include(:i18n)
|
12
|
-
result[:ru][:i18n].should include(:plural)
|
13
|
-
result[:ru][:i18n][:plural].should include(:keys)
|
14
|
-
result[:ru][:i18n][:plural][:keys].size.should == 4
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
[:ru, :i18n, :plural].inject(result) do |current, key|
|
16
|
+
current.should have_key(key)
|
17
|
+
current[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
plural = result[:ru][:i18n][:plural]
|
21
|
+
|
22
|
+
plural.should include(:keys, :rule)
|
23
|
+
|
24
|
+
plural[:keys].size.should == 4
|
25
|
+
plural[:rule].should be_a(Proc)
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
@@ -27,21 +35,15 @@ describe Rules do
|
|
27
35
|
end
|
28
36
|
|
29
37
|
it "returns the correct values for Russian rules" do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Rules.rule_for(6, :ru).should == :many
|
36
|
-
Rules.rule_for(7, :ru).should == :many
|
37
|
-
Rules.rule_for(8, :ru).should == :many
|
38
|
-
Rules.rule_for(9, :ru).should == :many
|
39
|
-
Rules.rule_for(10, :ru).should == :many
|
40
|
-
Rules.rule_for(11, :ru).should == :many
|
38
|
+
rules = {
|
39
|
+
:one => [1, 101],
|
40
|
+
:few => [2, 3, 4, 102],
|
41
|
+
:many => ((5..11).to_a + [111])
|
42
|
+
}
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
rules.each do |rule, examples|
|
45
|
+
examples.each { |n| Rules.rule_for(n, :ru).should == rule }
|
46
|
+
end
|
45
47
|
end
|
46
48
|
|
47
49
|
it "returns :other if there's an error" do
|
@@ -53,11 +55,11 @@ describe Rules do
|
|
53
55
|
|
54
56
|
describe "#all_for" do
|
55
57
|
it "returns a list of all applicable rules for the given locale" do
|
56
|
-
Rules.all_for(:en).
|
57
|
-
Rules.all_for(:ru).
|
58
|
+
Rules.all_for(:en).should =~ [:one, :other]
|
59
|
+
Rules.all_for(:ru).should =~ [:one, :few, :many, :other]
|
58
60
|
end
|
59
61
|
|
60
|
-
it "
|
62
|
+
it "returns an empty array on error" do
|
61
63
|
stub(Rules).get_resource { lambda { raise "Jelly beans" } }
|
62
64
|
Rules.all_for(:en).should == []
|
63
65
|
Rules.all_for(:ru).should == []
|
@@ -67,9 +69,7 @@ describe Rules do
|
|
67
69
|
describe "#all" do
|
68
70
|
it "gets rules for the default locale (usually supplied by FastGettext)" do
|
69
71
|
mock(TwitterCldr).get_locale { :ru }
|
70
|
-
|
71
|
-
rules.size.should == 4
|
72
|
-
rules.each { |rule| [:one, :few, :many, :other].should include(rule) }
|
72
|
+
Rules.all.should =~ [:one, :few, :many, :other]
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|