singleton-client-test 0.7.0.0 → 0.7.0.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
  SHA256:
3
- metadata.gz: d44c85a34a9f591e36539181809f432fee53baa8de8bb5c1dee17b297682ccc3
4
- data.tar.gz: 0e6425988c63c02c07f752fbb39a38df9e77fa26127ad63f3ed0a1b22dd40be7
3
+ metadata.gz: 18e3c63e4f2d2bd694a17f3d7d3f9ba785dc5f2a6d0fe7f3971536e4dc254da3
4
+ data.tar.gz: 17af22e9a379406291fcabecb8671f8aa3ae8912cc8da8764f020f977f7315a2
5
5
  SHA512:
6
- metadata.gz: 1cfda19b992dbf32f22df24f6605baa638eb1bed0468676c0ee41b371a282caf6e7901ff4e155c82ad4ff9910d57366fff4613cb00e2dd24207d5dd132c2f4d0
7
- data.tar.gz: 7fc1aec877988888461fe8059dda699261571db1f4cf52ef11570ab668299ec7b6b8583da911c308fe79717207af5e8aefafb3f904cd897e8115e1547c753989
6
+ metadata.gz: b96b5453f83960094ac20261ada08fd5904e238e5cb4cc27903d05e6584cc893403bd6ddd26399a94f45ad9a666c4645fdbcadd27ad40e338375eccef09e531b
7
+ data.tar.gz: 589d34460c469601c7b04cbcad0ddfd831af1ba477f243b521c4526ce85b0209f7769c6a4e6e15de28e7fbd18f79d6fd62eb7803d941cdfccc24e102d78de8b3
@@ -0,0 +1,4 @@
1
+ require 'sgtn-client/cldr/localized_datetime'
2
+ require 'sgtn-client/cldr/localized_date'
3
+ require 'sgtn-client/cldr/localized_time'
4
+ require 'sgtn-client/cldr/localized_str'
@@ -0,0 +1,27 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
5
+ def l_full_s(locale = TwitterCldr.locale)
6
+ self.to_datetime().localize(locale).to_date().to_full_s
7
+ end
8
+ LOCALIZE
9
+
10
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
11
+ def l_long_s(locale = TwitterCldr.locale)
12
+ self.to_datetime().localize(locale).to_date().to_long_s
13
+ end
14
+ LOCALIZE
15
+
16
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
17
+ def l_medium_s(locale = TwitterCldr.locale)
18
+ self.to_datetime().localize(locale).to_date().to_medium_s
19
+ end
20
+ LOCALIZE
21
+
22
+
23
+ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
+ def l_short_s(locale = TwitterCldr.locale)
25
+ self.to_datetime().localize(locale).to_date().to_short_s
26
+ end
27
+ LOCALIZE
@@ -0,0 +1,27 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
5
+ def l_full_s(locale = TwitterCldr.locale)
6
+ self.localize(locale).to_full_s
7
+ end
8
+ LOCALIZE
9
+
10
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
11
+ def l_long_s(locale = TwitterCldr.locale)
12
+ self.localize(locale).to_long_s
13
+ end
14
+ LOCALIZE
15
+
16
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
17
+ def l_medium_s(locale = TwitterCldr.locale)
18
+ self.localize(locale).to_medium_s
19
+ end
20
+ LOCALIZE
21
+
22
+
23
+ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
+ def l_short_s(locale = TwitterCldr.locale)
25
+ self.localize(locale).to_short_s
26
+ end
27
+ LOCALIZE
@@ -0,0 +1,11 @@
1
+
2
+ String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
3
+ def to_plural_s(locale, arg)
4
+ num_str = SgtnClient::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,27 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
5
+ def l_full_s(locale = TwitterCldr.locale)
6
+ self.localize(locale).to_full_s
7
+ end
8
+ LOCALIZE
9
+
10
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
11
+ def l_long_s(locale = TwitterCldr.locale)
12
+ self.localize(locale).to_long_s
13
+ end
14
+ LOCALIZE
15
+
16
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
17
+ def l_medium_s(locale = TwitterCldr.locale)
18
+ self.localize(locale).to_medium_s
19
+ end
20
+ LOCALIZE
21
+
22
+
23
+ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
+ def l_short_s(locale = TwitterCldr.locale)
25
+ self.localize(locale).to_short_s
26
+ end
27
+ LOCALIZE
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module SgtnClient
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
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
@@ -12,6 +12,11 @@ module SgtnClient
12
12
  autoload :ValidateUtil, "sgtn-client/util/validate-util"
13
13
  autoload :LocaleUtil, "sgtn-client/util/locale-util"
14
14
 
15
+ module Formatters
16
+ autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
17
+ end
18
+
19
+
15
20
  class << self
16
21
  def configure(options = {}, &block)
17
22
  SgtnClient::Config.configure(options, &block)
@@ -1,2 +1,3 @@
1
1
  require "sgtn-client/sgtn-client"
2
-
2
+ require 'sgtn-client/cldr/core_ext'
3
+ require 'twitter_cldr'
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 1, 7].freeze
2
+ VERSION_INFO = [0, 1, 8].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-client-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.0
4
+ version: 0.7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware G11n Team
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: twitter_cldr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6.6'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: webmock
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -230,6 +244,20 @@ dependencies:
230
244
  - - "~>"
231
245
  - !ruby/object:Gem::Version
232
246
  version: '1.0'
247
+ - !ruby/object:Gem::Dependency
248
+ name: twitter_cldr
249
+ requirement: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - "~>"
252
+ - !ruby/object:Gem::Version
253
+ version: '6.6'
254
+ type: :runtime
255
+ prerelease: false
256
+ version_requirements: !ruby/object:Gem::Requirement
257
+ requirements:
258
+ - - "~>"
259
+ - !ruby/object:Gem::Version
260
+ version: '6.6'
233
261
  description: Singleton Ruby client
234
262
  email: g11n-vip-project@vmware.com
235
263
  executables: []
@@ -241,11 +269,17 @@ files:
241
269
  - lib/sgtn-client/api/source.rb
242
270
  - lib/sgtn-client/api/t.rb
243
271
  - lib/sgtn-client/api/translation.rb
272
+ - lib/sgtn-client/cldr/core_ext.rb
273
+ - lib/sgtn-client/cldr/localized_date.rb
274
+ - lib/sgtn-client/cldr/localized_datetime.rb
275
+ - lib/sgtn-client/cldr/localized_str.rb
276
+ - lib/sgtn-client/cldr/localized_time.rb
244
277
  - lib/sgtn-client/core/cache.rb
245
278
  - lib/sgtn-client/core/config.rb
246
279
  - lib/sgtn-client/core/exceptions.rb
247
280
  - lib/sgtn-client/core/logging.rb
248
281
  - lib/sgtn-client/core/request.rb
282
+ - lib/sgtn-client/formatters/plurals/plural_formatter.rb
249
283
  - lib/sgtn-client/sgtn-client.rb
250
284
  - lib/sgtn-client/util/cache-util.rb
251
285
  - lib/sgtn-client/util/locale-util.rb