singleton-ruby 0.1.7 → 0.1.8
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/api/translation.rb +6 -14
- 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 +37 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8b76321098ddc3fbe0600be0b766f3e1162d546bf162ca564e896cf570cbbfe
|
4
|
+
data.tar.gz: 8a87437293352085857b30878de95c74e2d9de24066c659e86ccd38fab7e811d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5230c379270046dd49f65164dbe68d71620944bebb09b338522e9b2753c858ad2a40dc7ed0a26c71468ea5ed6de02874217d1fe7542ca584b803fd7c1cada8e
|
7
|
+
data.tar.gz: cbbffd1ea904726238bdf5ef8662d82fcba89cca29416ac4424210ebd10077bcb5fbd7f1a152bf7157426634258c98b0a6143aef7462e85bbdd4db97e79d7e40
|
@@ -36,11 +36,10 @@ module SgtnClient
|
|
36
36
|
|
37
37
|
def self.getString_f(component, key, args, locale)
|
38
38
|
s = getString(component, key, locale)
|
39
|
-
if
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
39
|
+
if args.is_a?(Hash)
|
40
|
+
args.each do |source, arg|
|
41
|
+
s.gsub! "{#{source}}", arg
|
42
|
+
end
|
44
43
|
elsif args.is_a?(Array)
|
45
44
|
s = sprintf s % args
|
46
45
|
end
|
@@ -62,8 +61,8 @@ module SgtnClient
|
|
62
61
|
if items.nil? || items["messages"] == nil
|
63
62
|
items = {}
|
64
63
|
s = SgtnClient::Source.getSources(component, default)
|
65
|
-
|
66
|
-
items["component"] =
|
64
|
+
default_component, value = s.first
|
65
|
+
items["component"] = default_component
|
67
66
|
items["messages"] = value
|
68
67
|
items["locale"] = 'source'
|
69
68
|
end
|
@@ -118,13 +117,6 @@ module SgtnClient
|
|
118
117
|
return obj
|
119
118
|
end
|
120
119
|
|
121
|
-
def self.is_json?(value)
|
122
|
-
result = MultiJson.load(value)
|
123
|
-
result.is_a?(Hash) || result.is_a?(Array)
|
124
|
-
rescue => exception
|
125
|
-
false
|
126
|
-
end
|
127
|
-
|
128
120
|
end
|
129
121
|
|
130
122
|
end
|
@@ -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 |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
|
@@ -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-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
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-10 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
|
@@ -271,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
305
|
- !ruby/object:Gem::Version
|
272
306
|
version: '0'
|
273
307
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
308
|
+
rubygems_version: 3.2.3
|
275
309
|
signing_key:
|
276
310
|
specification_version: 4
|
277
311
|
summary: Singleton Ruby client
|