singleton-ruby 0.1.5 → 0.1.9

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: 4a1123e189882d4867128d6933adccda07f53b44ff5b9206ef4d90d6210cc8d7
4
- data.tar.gz: fa5d43b9fb1b15aab4008cf0d3fa6138137d96eed5eacb8b92c26c79d75f46a8
3
+ metadata.gz: 8b9a86b24b35f77b5d2abea8686d2ab8a9819ea5e5b4957e6997234262d4cc24
4
+ data.tar.gz: 9328b24f10c0a97a77cc6b7168fdadedc9b3a935b7c54409b260d9c03440d7fc
5
5
  SHA512:
6
- metadata.gz: fe0b2657ce521442d0987728ce63993f27b928d618a55e8a9e0b020a632ae797c37fc8ad3316295c08292dc08b3d8a2a8f57a4581e2a8e143e10ecf312182e2d
7
- data.tar.gz: 2fe5be7449a0e5bcd2fa5b9264a35bd625e8987518539f78498ba07da09c6c3269eba4bdfe703b56a932b426c9ac68ac36ad43654866970944923ee097065eb2
6
+ metadata.gz: cec4722423baf395e872eef3e07c444ec4c3001e6b86b50fab653782ed460e3504fd2145445970fedf3f62332c0f4c8384cd54794eeb8069f91bcf9baf16b29e
7
+ data.tar.gz: ce55d5ee39549d7137b095e3541200d6d26c2fd26ae0fdaf594bf2aaacf3cfca8b11c680be2973d9bda1fff1ba5416fa5a8a0d21544439f5fdc4b92451cdc581
@@ -17,11 +17,12 @@ 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?
20
+ if items.nil? || items[locale][key].nil?
21
+ SgtnClient.logger.debug "Source not found, return key: " + key
21
22
  return key
23
+ else
24
+ return items[locale][key]
22
25
  end
23
- str = items[locale][key]
24
- return str
25
26
  end
26
27
 
27
28
  def self.getSources(component, locale)
@@ -36,7 +36,14 @@ module SgtnClient
36
36
 
37
37
  def self.getString_f(component, key, args, locale)
38
38
  s = getString(component, key, locale)
39
- return sprintf s % args
39
+ if args.is_a?(Hash)
40
+ args.each do |source, arg|
41
+ s.gsub! "{#{source}}", arg
42
+ end
43
+ elsif args.is_a?(Array)
44
+ s = sprintf s % args
45
+ end
46
+ return s
40
47
  end
41
48
 
42
49
  def self.getStrings(component, locale)
@@ -52,7 +59,12 @@ module SgtnClient
52
59
 
53
60
  default = SgtnClient::Config.configurations.default
54
61
  if items.nil? || items["messages"] == nil
55
- items = SgtnClient::Source.getSources(component, default)
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'
56
68
  end
57
69
  return items
58
70
  end
@@ -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, 5].freeze
2
+ VERSION_INFO = [0, 1, 9].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
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.5
4
+ version: 0.1.9
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-08-27 00:00:00.000000000 Z
11
+ date: 2021-11-18 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.0.9
308
+ rubygems_version: 3.2.3
275
309
  signing_key:
276
310
  specification_version: 4
277
311
  summary: Singleton Ruby client