singleton-ruby 0.1.6 → 0.2.0
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 +4 -4
- data/lib/sgtn-client/api/source.rb +6 -4
- data/lib/sgtn-client/api/translation.rb +10 -13
- 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 +63 -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: e74b238c58ac91cb373e48cd664ef4c8115bbb811b8ceb0427a82979b5d6bdfe
|
4
|
+
data.tar.gz: ae96f56fd84a59d82ce60d9aceea55baac70bc2004c1d87d00f94dee6a9ff2a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bae2bb630c92a26d5fc84141fda89193d48d373fefa8c1a48090cac524fc485cc0a80ee1de0076ca56e577a69e3774ace36d1ede442828a4025294a113c88223
|
7
|
+
data.tar.gz: 713f0b37a528eb1c1f5e1c50519985d7821b2fac1182912194a3f7ef17e09671a38ec34c073109d46edbe939e3ade572d1ef433a642e1dcbffdd79cd45b48116
|
@@ -17,11 +17,13 @@ module SgtnClient
|
|
17
17
|
else
|
18
18
|
SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
|
19
19
|
end
|
20
|
-
if items.nil?
|
21
|
-
return key
|
20
|
+
if items.nil? || items[locale][key].nil?
|
21
|
+
SgtnClient.logger.debug "Source not found, return key: " + key
|
22
|
+
#return key
|
23
|
+
return nil
|
24
|
+
else
|
25
|
+
return items[locale][key]
|
22
26
|
end
|
23
|
-
str = items[locale][key]
|
24
|
-
return str
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.getSources(component, locale)
|
@@ -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
|
@@ -60,7 +59,12 @@ module SgtnClient
|
|
60
59
|
|
61
60
|
default = SgtnClient::Config.configurations.default
|
62
61
|
if items.nil? || items["messages"] == nil
|
63
|
-
items =
|
62
|
+
items = {}
|
63
|
+
s = SgtnClient::Source.getSources(component, default)
|
64
|
+
default_component, value = s.first
|
65
|
+
items["component"] = default_component
|
66
|
+
items["messages"] = value
|
67
|
+
items["locale"] = 'source'
|
64
68
|
end
|
65
69
|
return items
|
66
70
|
end
|
@@ -113,13 +117,6 @@ module SgtnClient
|
|
113
117
|
return obj
|
114
118
|
end
|
115
119
|
|
116
|
-
def self.is_json?(value)
|
117
|
-
result = MultiJson.load(value)
|
118
|
-
result.is_a?(Hash) || result.is_a?(Array)
|
119
|
-
rescue => exception
|
120
|
-
false
|
121
|
-
end
|
122
|
-
|
123
120
|
end
|
124
121
|
|
125
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,63 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 2
|
5
|
+
def l_full_s(locale = TwitterCldr.locale, *args)
|
6
|
+
timezone = args[0]
|
7
|
+
display_name = args[1]
|
8
|
+
if timezone.nil?
|
9
|
+
self.localize(locale).to_full_s
|
10
|
+
elsif display_name.nil?
|
11
|
+
self.localize(locale).with_timezone(timezone).to_full_s
|
12
|
+
else
|
13
|
+
tz = TwitterCldr::Timezones::Timezone.instance(timezone, locale)
|
14
|
+
tz.display_name_for(self, display_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
LOCALIZE
|
18
|
+
|
19
|
+
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
20
|
+
def l_long_s(locale = TwitterCldr.locale, *args)
|
21
|
+
timezone = args[0]
|
22
|
+
display_name = args[1]
|
23
|
+
if timezone.nil?
|
24
|
+
self.localize(locale).to_long_s
|
25
|
+
elsif display_name.nil?
|
26
|
+
self.localize(locale).with_timezone(timezone).to_long_s
|
27
|
+
else
|
28
|
+
tz = TwitterCldr::Timezones::Timezone.instance(timezone, locale)
|
29
|
+
tz.display_name_for(self, display_name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
LOCALIZE
|
33
|
+
|
34
|
+
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
35
|
+
def l_medium_s(locale = TwitterCldr.locale, *args)
|
36
|
+
timezone = args[0]
|
37
|
+
display_name = args[1]
|
38
|
+
if timezone.nil?
|
39
|
+
self.localize(locale).to_medium_s
|
40
|
+
elsif display_name.nil?
|
41
|
+
self.localize(locale).with_timezone(timezone).to_medium_s
|
42
|
+
else
|
43
|
+
tz = TwitterCldr::Timezones::Timezone.instance(timezone, locale)
|
44
|
+
tz.display_name_for(self, display_name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
LOCALIZE
|
48
|
+
|
49
|
+
|
50
|
+
DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
51
|
+
def l_short_s(locale = TwitterCldr.locale, *args)
|
52
|
+
timezone = args[0]
|
53
|
+
display_name = args[1]
|
54
|
+
if timezone.nil?
|
55
|
+
self.localize(locale).to_short_s
|
56
|
+
elsif display_name.nil?
|
57
|
+
self.localize(locale).with_timezone(timezone).to_short_s
|
58
|
+
else
|
59
|
+
tz = TwitterCldr::Timezones::Timezone.instance(timezone, locale)
|
60
|
+
tz.display_name_for(self, display_name)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
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-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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
|
+
date: 2021-11-23 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
|