singleton-client 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sgtn-client/cldr/core_ext.rb +4 -0
- data/lib/sgtn-client/cldr/localized_date.rb +27 -0
- data/lib/sgtn-client/cldr/localized_datetime.rb +27 -0
- data/lib/sgtn-client/cldr/localized_str.rb +11 -0
- data/lib/sgtn-client/cldr/localized_time.rb +27 -0
- data/lib/sgtn-client/formatters/plurals/plural_formatter.rb +38 -0
- data/lib/sgtn-client/sgtn-client.rb +5 -0
- data/lib/singleton-ruby.rb +2 -1
- data/lib/version.rb +1 -1
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3d1aaec2ddcbbb860b477feb06dedcb64b5ec626864c2a89c31e38451e6069f
|
4
|
+
data.tar.gz: c1d3e0125bed7151a337eb8f595a08e74424d2a04b0b6ce3b53d3aac8c66ae49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16da077e3ed50925a0cd0fbd6865c4a9ba05c66bf2dca1b5911a9c494f3669b823dc9653688a80be1b285b1d300dfa70a16524d45bfa9b0079c63c6ecf16f5bb
|
7
|
+
data.tar.gz: 3079b1570e08d8b622013d5e7431ed98339d14f5be83c2c108a649f18f968e4a1d903459861ba4a3f4d29acd553ac706ed6c4d1274769cc9ed1c57c44c846da8
|
@@ -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)
|
data/lib/singleton-ruby.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
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-11-
|
11
|
+
date: 2021-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -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
|