twitter_cldr 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: accacbf47c61c3008a7cdae91acde6d4bb848bc9
4
- data.tar.gz: 112cdf6e94bc614b5677289ee345b4ea38bd55e0
3
+ metadata.gz: d9c6af08b1eab959bef74d6da6df7187178d6c8a
4
+ data.tar.gz: c1e6a87f70fd295d46f4b9bb57951910568a2223
5
5
  SHA512:
6
- metadata.gz: f923179204c1627ebe184f5fe38d2249e0016b1c20a524c0c0b7e06c3382f19240b054866daf0019edf9215e6034c1bc65d942e4914c8ed4332894883fdd6402
7
- data.tar.gz: 48dd5f10034e32e5900abec0f02a1ff11e0e98bb14dd6921f355b1e171f2fa03bc8c1f68bfb885244abdd9c0b8b1f3fa16cefc62f582c77f661f9db8fbd91050
6
+ metadata.gz: 2d4e1affea9c1f3f93f87d4a9378c8cdcb65beadf7d257693285510e72977fbd5fad2f5601000866f5b7cfb18112eba10973377b368423841b4dfc7a83402ecd
7
+ data.tar.gz: 19dc931849ded8e6b2717be5a0a2bace3f5605e351fd28c03d302128d17a26a54ea3bf2c7612d282d91774dfcb726f105b6bc4aba40338b178a1f637722b62ca
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 3.1.1
2
+ * Fixed an issue with single quotes appearing in dates formatting.
3
+ * Added support for locale codes that have region code in lower case.
4
+ * Fixed time zone formatting for DateTime objects.
5
+
1
6
  == 3.1.0
2
7
 
3
8
  * Updated resources from CLDR v26 (except the collation data).
data/lib/twitter_cldr.rb CHANGED
@@ -64,6 +64,8 @@ module TwitterCldr
64
64
  end
65
65
 
66
66
  def locale
67
+ # doing all this work in locale getter rather than locale setter makes it possible to use locale fallbacks
68
+ # even if they were configured (or became available) after @locale was already assigned an unsupported locale
67
69
  locale = supported_locale?(@locale) ? @locale : find_fallback
68
70
  locale = DEFAULT_LOCALE if locale.to_s.empty?
69
71
  (supported_locale?(locale) ? locale : DEFAULT_LOCALE).to_sym
@@ -104,6 +106,7 @@ module TwitterCldr
104
106
 
105
107
  def convert_locale(locale)
106
108
  locale = locale.to_sym if locale.respond_to?(:to_sym)
109
+ locale = lowercase_locales_map.fetch(locale, locale)
107
110
  TWITTER_LOCALE_MAP.fetch(locale, locale)
108
111
  end
109
112
 
@@ -138,6 +141,14 @@ module TwitterCldr
138
141
  nil
139
142
  end
140
143
 
144
+ def lowercase_locales_map
145
+ @lowercase_locales_map ||= supported_locales.inject({}) do |memo, locale|
146
+ lowercase = locale.to_s.downcase.to_sym
147
+ memo[lowercase] = locale unless lowercase == locale
148
+ memo
149
+ end
150
+ end
151
+
141
152
  end
142
153
 
143
154
  end
@@ -23,11 +23,7 @@ module TwitterCldr
23
23
  protected
24
24
 
25
25
  def format_plaintext(token, index, obj, options)
26
- if match = token.value.match(/([\s]*)'(.*)'([\s]*)/)
27
- match.captures.join
28
- else
29
- token.value
30
- end
26
+ token.value.gsub(/'([^']+)'/, '\1') # remove single-quote escaping for "real" characters
31
27
  end
32
28
 
33
29
  def format_composite(token, index, obj, options)
@@ -28,7 +28,7 @@ module TwitterCldr
28
28
  # @ TODO: these need to be cheap to create
29
29
  data_reader = data_reader_for(type)
30
30
  tokens = data_reader.tokenizer.tokenize(data_reader.pattern)
31
- data_reader.formatter.format(tokens, base_in_timezone)
31
+ data_reader.formatter.format(tokens, base_in_timezone, chain_params)
32
32
  end
33
33
  end
34
34
 
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = "3.1.0"
7
+ VERSION = "3.1.1"
8
8
  end
@@ -76,6 +76,14 @@ describe Rules do
76
76
  :one, :two, :few, :other
77
77
  ])
78
78
  end
79
+
80
+ it "works with upercase region code" do
81
+ expect(TwitterCldr::Formatters::Plurals::Rules.all_for('en-gb')).to match_array([:one, :other])
82
+ end
83
+
84
+ it "works with lowercase region code" do
85
+ expect(TwitterCldr::Formatters::Plurals::Rules.all_for('en-gb')).to match_array([:one, :other])
86
+ end
79
87
  end
80
88
 
81
89
  describe "#all" do
@@ -45,6 +45,10 @@ describe LocalizedDateTime do
45
45
  # notice there are no single quotes around the "at"
46
46
  expect(date_time.localize(:en).to_long_s).to eq("September 20, 1987 at 10:05:00 PM UTC")
47
47
  end
48
+
49
+ it 'should stringify with proper time zone' do
50
+ expect(date_time.localize(:en).with_timezone('America/Los_Angeles').to_long_s).to eq("September 20, 1987 at 3:05:00 PM PST")
51
+ end
48
52
  end
49
53
 
50
54
  describe "#to_date" do
@@ -98,6 +102,14 @@ describe LocalizedDateTime do
98
102
  it "should format using additional patterns" do
99
103
  expect(date_time.localize(:en).to_additional_s("EHms")).to eq("Sun 22:05:00")
100
104
  end
105
+
106
+ it "should properly handle single quotes escaping" do
107
+ expect(date_time.localize(:ru).to_additional_s("GyMMMd")).to eq("20 сент. 1987 г. н. э.")
108
+ end
109
+
110
+ it "should unescape multiple groups" do
111
+ expect(date_time.localize(:es).to_additional_s("yMMMd")).to eq("20 de sept. de 1987")
112
+ end
101
113
  end
102
114
 
103
115
  describe "#to_s" do
@@ -22,6 +22,16 @@ describe TwitterCldr do
22
22
  expect(TwitterCldr.supported_locale?(:'zh-tw')).to be_true
23
23
  expect(TwitterCldr.supported_locale?(:msa)).to be_true
24
24
  end
25
+
26
+ it "should work with lowercase region codes" do
27
+ expect(TwitterCldr.supported_locale?('en-gb')).to be_true
28
+ expect(TwitterCldr.supported_locale?('zh-hant')).to be_true
29
+ end
30
+
31
+ it "should work with upper case region codes" do
32
+ expect(TwitterCldr.supported_locale?('en-GB')).to be_true
33
+ expect(TwitterCldr.supported_locale?('zh-Hant')).to be_true
34
+ end
25
35
  end
26
36
 
27
37
  describe "#supported_locales" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_cldr
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json