singleton-cldr-rb 0.0.2 → 0.0.6

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
  SHA256:
3
- metadata.gz: 845cfeef4a78ab21efc58f2423be0f4a59de9bea0ec257a62109c0b856d1a3cb
4
- data.tar.gz: 48865d6f5d41d786ee87293d6b5437ba385b7b8f2b3d640dfb728d291c45d487
3
+ metadata.gz: c24fff8e11426fa8b758819b4f49dc6fd133ca6d671ef9546b89571cef069263
4
+ data.tar.gz: 185e28fc6aa72a570aeb86e615f347343bb9af32a5c0416e16ee7c10d9bc596d
5
5
  SHA512:
6
- metadata.gz: b576815fb4cf31aeb39b5672565d480e9be6bf8e95148e43fc22d8628b35c2b7d0b26a9aeec02766dd29c5de6acd5283f01f11d91f373ba8a280adeb2b1fd495
7
- data.tar.gz: 07414e9410802c6063fb2719c25e64c66c910ac13965e196b5e83635d4db69aa5bff9039eab0fcc1b7140ee779b4ffe4ac2b098251c0f8d1f641f90b2664908e
6
+ metadata.gz: 643c696253f19bf9a9c21f2cfeb154fb53404f7e957773b8d2e7cc261457e4c87589f17fb3bc7d4ae86b4c5f78d9ccb2fb988f9c98306d350d0fc47eaacb9cfe
7
+ data.tar.gz: 62f63ab8d65b849fe1e3cd418d679e19b565b39ff993fca88c2a2ab77ab0d72a867ec7023ce200cb709c217d3dca59246242639ea301b10549ff4b81df193fd5
@@ -1,3 +1,4 @@
1
1
  require 'sgtn-cldr/cldr/localized_datetime'
2
2
  require 'sgtn-cldr/cldr/localized_date'
3
- require 'sgtn-cldr/cldr/localized_time'
3
+ require 'sgtn-cldr/cldr/localized_time'
4
+ require 'sgtn-cldr/cldr/localized_str'
@@ -0,0 +1,11 @@
1
+
2
+ String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
3
+ def to_plural_s(locale, arg)
4
+ num_str = SgtnCldr::Formatters::PluralFormatter.new(locale).num_s(self, arg)
5
+ if num_str.nil? || num_str.empty?
6
+ self.localize(locale) % arg
7
+ else
8
+ num_str
9
+ end
10
+ end
11
+ LOCALIZE
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module SgtnCldr
4
+ module Formatters
5
+ class PluralFormatter
6
+
7
+ attr_reader :locale
8
+
9
+ def initialize(locale = TwitterCldr.locale)
10
+ @locale = TwitterCldr.convert_locale(locale)
11
+ end
12
+
13
+ def num_s(string, replacements)
14
+ reg = Regexp.union(
15
+ /%<(\{.*?\})>/
16
+ )
17
+ string.gsub(reg) do |match|
18
+ count_placeholder, patterns = if $1
19
+ pluralization_hash = JSON.parse($1)
20
+ if pluralization_hash.is_a?(Hash) && pluralization_hash.size == 1
21
+ pluralization_hash.first
22
+ else
23
+ raise ArgumentError.new('expected a Hash with a single key')
24
+ end
25
+ else
26
+ raise ArgumentError.new('invalide format')
27
+ end
28
+ count = replacements[count_placeholder.to_sym].to_s
29
+ if patterns.is_a?(Hash)
30
+ return TwitterCldr::Utils.deep_symbolize_keys(patterns)[count.to_sym]
31
+ else
32
+ raise ArgumentError.new('expected patterns to be a Hash')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -3,12 +3,14 @@ module SgtnCldr
3
3
  autoload :Cache, "sgtn-cldr/core/cache"
4
4
  end
5
5
 
6
- autoload :Translation, "sgtn-cldr/api/translation"
7
- autoload :Source, "sgtn-cldr/api/source"
8
6
  autoload :Config, "sgtn-cldr/core/config"
9
7
  autoload :Logging, "sgtn-cldr/core/logging"
10
8
  autoload :Exceptions, "sgtn-cldr/core/exceptions"
11
9
  autoload :ValidateUtil, "sgtn-cldr/util/validate-util"
10
+
11
+ module Formatters
12
+ autoload :PluralFormatter, "sgtn-cldr/formatters/plurals/plural_formatter"
13
+ end
12
14
 
13
15
  class << self
14
16
  def configure(options = {}, &block)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 0, 2].freeze
2
+ VERSION_INFO = [0, 0, 6].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'twitter_cldr'
3
+
4
+ describe SgtnCldr do
5
+ describe "Plural" do
6
+
7
+ before :each do
8
+
9
+ end
10
+
11
+ it "plural" do
12
+ str = 'there %<{ "cat_count": { "one": "is one cat", "zero":"is no cat", "two": "are two cats", "few": "are some cats", "many": "are many cats", "other": "are %{cat_count} cats" } }> in the room'
13
+ expect(str.to_plural_s(:cy, { :cat_count => 1 })).to eq 'there is one cat in the room'
14
+ expect(str.to_plural_s(:cy, { :cat_count => 0 })).to eq 'there is no cat in the room'
15
+ expect(str.to_plural_s(:cy, { :cat_count => 5 })).to eq 'there are 5 cats in the room'
16
+ expect(str.to_plural_s(:cy, { :cat_count => 3 })).to eq 'there are some cats in the room'
17
+ expect(str.to_plural_s(:cy, { :cat_count => 2 })).to eq 'there are two cats in the room'
18
+ s = '%<{"count": {"0": "no horse", "one": "one horse", "other": "%{count} horses"}}>'
19
+ expect(s.to_plural_s(:cy, { :count => 0 })).to eq 'no horse'
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-cldr-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware G11n Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-08 00:00:00.000000000 Z
11
+ date: 2021-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -216,34 +216,6 @@ dependencies:
216
216
  - - "~>"
217
217
  - !ruby/object:Gem::Version
218
218
  version: '0.8'
219
- - !ruby/object:Gem::Dependency
220
- name: rest-client
221
- requirement: !ruby/object:Gem::Requirement
222
- requirements:
223
- - - "~>"
224
- - !ruby/object:Gem::Version
225
- version: '2.0'
226
- type: :runtime
227
- prerelease: false
228
- version_requirements: !ruby/object:Gem::Requirement
229
- requirements:
230
- - - "~>"
231
- - !ruby/object:Gem::Version
232
- version: '2.0'
233
- - !ruby/object:Gem::Dependency
234
- name: multi_json
235
- requirement: !ruby/object:Gem::Requirement
236
- requirements:
237
- - - "~>"
238
- - !ruby/object:Gem::Version
239
- version: '1.0'
240
- type: :runtime
241
- prerelease: false
242
- version_requirements: !ruby/object:Gem::Requirement
243
- requirements:
244
- - - "~>"
245
- - !ruby/object:Gem::Version
246
- version: '1.0'
247
219
  - !ruby/object:Gem::Dependency
248
220
  name: twitter_cldr
249
221
  requirement: !ruby/object:Gem::Requirement
@@ -271,12 +243,14 @@ files:
271
243
  - lib/sgtn-cldr/cldr/core_ext.rb
272
244
  - lib/sgtn-cldr/cldr/localized_date.rb
273
245
  - lib/sgtn-cldr/cldr/localized_datetime.rb
246
+ - lib/sgtn-cldr/cldr/localized_str.rb
274
247
  - lib/sgtn-cldr/cldr/localized_time.rb
275
248
  - lib/sgtn-cldr/core/cache.rb
276
249
  - lib/sgtn-cldr/core/config.rb
277
250
  - lib/sgtn-cldr/core/exceptions.rb
278
251
  - lib/sgtn-cldr/core/logging.rb
279
252
  - lib/sgtn-cldr/core/request.rb
253
+ - lib/sgtn-cldr/formatters/plurals/plural_formatter.rb
280
254
  - lib/sgtn-cldr/sgtn-cldr.rb
281
255
  - lib/sgtn-cldr/util/cache-util.rb
282
256
  - lib/sgtn-cldr/util/validate-util.rb
@@ -287,6 +261,7 @@ files:
287
261
  - spec/spec_helper.rb
288
262
  - spec/support/sample_data.rb
289
263
  - spec/unit/datetime_spec.rb
264
+ - spec/unit/plural_spec.rb
290
265
  homepage: https://github.com/vmware/singleton
291
266
  licenses:
292
267
  - MIT
@@ -306,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
281
  - !ruby/object:Gem::Version
307
282
  version: '0'
308
283
  requirements: []
309
- rubygems_version: 3.1.4
284
+ rubygems_version: 3.0.9
310
285
  signing_key:
311
286
  specification_version: 4
312
287
  summary: Singleton cldr for L2 support
@@ -316,3 +291,4 @@ test_files:
316
291
  - spec/spec_helper.rb
317
292
  - spec/support/sample_data.rb
318
293
  - spec/unit/datetime_spec.rb
294
+ - spec/unit/plural_spec.rb