singleton-client-test 0.7.0.29 → 0.7.0.32

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: 56c3f8abf44f8fd425c81ffa852171a0ce02fe75b4b4005c7cfb691de45baccf
4
- data.tar.gz: cdf801d6908dff8e70012372cdf97502698e10215a0dd23d7688796efe0caad8
3
+ metadata.gz: 7c3518e9f8e872dd00acd151a9157c273f274c5398d773c42e75d07e0667413b
4
+ data.tar.gz: 0eec546d1df60f066a1f346c04da0cac374f1944980477ccb32b5055a70e62b0
5
5
  SHA512:
6
- metadata.gz: b5c32aed4ff94f04c7413a07f2c4ab1f113216cbc59bfff3e82e88211a8ea052defec92e1fb132e283b4dd21bf3e1a50d053a69a42a33679f320d2d509741d1a
7
- data.tar.gz: c2bd59d99dfa74e05c8bb882eac12b78ae7ae5f792136aae08a8fae41afb8f091d64715aa16b52e492dcd176c9611cd923e113dc822840fa0563d95d1d2703e4
6
+ metadata.gz: b8eb7e6e83057a56fa3a0d618b14ef83e61458319ccbbea388028961bbeae0ea061c82c87ed34f89cfe43c2336fc390b4ffe6801c1e9e6c85e43a2c4dd366e9f
7
+ data.tar.gz: 10eb576187a7ff47e04e409ff292862397e956de6adfbe9f2a39565cd5219c22397a959a23b399c96627aeab85562992f0abc92edec3a590f0ec7a7b610c4794
@@ -1,3 +1,5 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
1
3
 
2
4
  module SgtnClient
3
5
 
@@ -6,18 +8,18 @@ module SgtnClient
6
8
  class Source
7
9
 
8
10
  def self.getSource(component, key, locale)
11
+ SgtnClient.logger.debug "[Source][getSource]component=#{component}, key=#{key}, locale=#{locale}"
9
12
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
10
13
  expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
11
14
  if items.nil?
12
- items = getBundle(component, locale)
13
- SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
15
+ items = getBundle(component, locale)
14
16
  SgtnClient::CacheUtil.write_cache(cache_key, items)
15
17
  else
16
- SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
18
+ SgtnClient.logger.debug "[Source][getSource]getting sources from cache with key: " + cache_key
17
19
  end
18
- s = items.nil?? nil : items[locale][key]
20
+ s = (items.nil? || items[locale].nil?)? nil : items[locale][key]
19
21
  if items.nil? || s.nil?
20
- SgtnClient.logger.debug "Source not found, return key: " + key
22
+ SgtnClient.logger.debug "[Source][getSource]source not found, return key: " + key
21
23
  #return key
22
24
  return nil
23
25
  else
@@ -26,23 +28,23 @@ module SgtnClient
26
28
  end
27
29
 
28
30
  def self.getSources(component, locale)
31
+ SgtnClient.logger.debug "[Source][getSources]component=#{component}, locale=#{locale}"
29
32
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
30
33
  expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
31
34
  if items.nil? || expired
32
35
  items = getBundle(component, locale)
33
- SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
34
36
  SgtnClient::CacheUtil.write_cache(cache_key, items)
35
37
  else
36
- SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
38
+ SgtnClient.logger.debug "[Source][getSources]getting sources from cache with key: " + cache_key
37
39
  end
38
40
  return items
39
41
  end
40
42
 
41
43
  def self.loadBundles(locale)
44
+ SgtnClient.logger.debug "[Source][loadBundles]locale=#{locale}"
42
45
  env = SgtnClient::Config.default_environment
43
46
  SgtnClient::Config.configurations.default = locale
44
47
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
45
- SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
46
48
  Dir.foreach(source_bundle) do |component|
47
49
  next if component == '.' || component == '..'
48
50
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
@@ -54,10 +56,10 @@ module SgtnClient
54
56
 
55
57
  private
56
58
  def self.getBundle(component, locale)
59
+ SgtnClient.logger.debug "[Source][getBundle]component=#{component}, locale=#{locale}"
57
60
  env = SgtnClient::Config.default_environment
58
61
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
59
62
  bundlepath = source_bundle + "/" + component + "/" + locale + ".yml"
60
- SgtnClient.logger.debug "Getting source from bundle: " + bundlepath
61
63
  begin
62
64
  bundle = SgtnClient::FileUtil.read_yml(bundlepath)
63
65
  rescue => exception
@@ -68,4 +70,4 @@ module SgtnClient
68
70
 
69
71
  end
70
72
 
71
- end
73
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  module SgtnClient
2
5
  class T < Translation
3
6
 
@@ -19,4 +22,4 @@ module SgtnClient
19
22
  return getStrings(component, locale)
20
23
  end
21
24
  end
22
- end
25
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'multi_json'
2
5
 
3
6
  module SgtnClient
@@ -12,22 +15,24 @@ module SgtnClient
12
15
  class Translation
13
16
 
14
17
  def self.getString(component, key, locale)
18
+ SgtnClient.logger.debug "[Translation.getString]component: #{component}, key: #{key}, locale: #{locale}"
15
19
  str = getTranslation(component, key, locale)
16
20
  if str.nil?
17
21
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
18
22
  if str.nil?
19
- SgtnClient.logger.error "Can't find the key '" + key + "' in source path!"
23
+ SgtnClient.logger.debug "[Translation][getString] Missing source string with key: #{key}, component: #{component}, locale: #{locale}"
20
24
  end
21
25
  end
22
26
  str
23
27
  end
24
28
 
25
29
  def self.getString_p(component, key, plural_args, locale)
30
+ SgtnClient.logger.debug "[Translation][getString_p]component=#{component}, key=#{key}, locale=#{locale}"
26
31
  str = getTranslation(component, key, locale)
27
32
  if str.nil?
28
33
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
29
34
  if str.nil?
30
- SgtnClient.logger.error "Can't find the key '" + key + "' in source path!"
35
+ SgtnClient.logger.debug "[Translation][getString_p] Missing source string with key: #{key}, component: #{component}, locale: #{locale}"
31
36
  return nil
32
37
  end
33
38
  str.to_plural_s(:en, plural_args)
@@ -37,6 +42,7 @@ module SgtnClient
37
42
  end
38
43
 
39
44
  def self.getString_f(component, key, args, locale, *optionals)
45
+ SgtnClient.logger.debug "[Translation][getString_f]component=#{component}, key=#{key}, locale=#{locale}"
40
46
  s = getString(component, key, locale, *optionals)
41
47
  if s.nil?
42
48
  return nil
@@ -52,13 +58,15 @@ module SgtnClient
52
58
  end
53
59
 
54
60
  def self.getStrings(component, locale)
61
+ SgtnClient.logger.debug "[Translation][getStrings]component=#{component}, locale=#{locale}"
62
+ locale = SgtnClient::LocaleUtil.get_best_locale(locale)
55
63
  items = get_cs(component, locale)
56
64
  default = SgtnClient::Config.configurations.default
57
65
  if items.nil? || items["messages"] == nil
58
66
  items = {}
59
67
  s = SgtnClient::Source.getSources(component, default)
60
68
  if s.nil?
61
- SgtnClient.logger.error "Can't find the component '" + component + "' in source path!"
69
+ SgtnClient.logger.error "[Translation][getStrings] Missing component: #{component}, locale: #{locale}"
62
70
  else
63
71
  default_component, value = s.first
64
72
  items["component"] = component
@@ -73,6 +81,7 @@ module SgtnClient
73
81
  private
74
82
 
75
83
  def self.getTranslation(component, key, locale)
84
+ locale = SgtnClient::LocaleUtil.get_best_locale(locale)
76
85
  items = get_cs(component, locale)
77
86
  if items.nil? || items["messages"] == nil
78
87
  nil
@@ -82,11 +91,18 @@ module SgtnClient
82
91
  end
83
92
 
84
93
  def self.get_cs(component, locale)
85
- flocale = SgtnClient::LocaleUtil.fallback(locale)
86
- cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
94
+ # source locale always return source bundle
95
+ if locale == LocaleUtil.get_source_locale
96
+ sources = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
97
+ messages = sources&.first&.last
98
+ return {'locale' => locale, 'component' => component, 'messages' => messages} if messages
99
+ end
100
+
101
+ cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
102
+ SgtnClient.logger.debug "[Translation][get_cs]cache_key=#{cache_key}"
87
103
  expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
88
104
  if items.nil? || expired
89
- items = load(component, flocale)
105
+ items = load(component, locale)
90
106
  if items.nil?
91
107
  items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
92
108
  SgtnClient::Core::Cache.put(cache_key, items, 60)
@@ -94,7 +110,7 @@ module SgtnClient
94
110
  SgtnClient::CacheUtil.write_cache(cache_key, items)
95
111
  end
96
112
  else
97
- SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
113
+ SgtnClient.logger.debug "[Translation]get translations from cache with key: " + cache_key
98
114
  end
99
115
 
100
116
  return items
@@ -103,6 +119,7 @@ module SgtnClient
103
119
  def self.load(component, locale)
104
120
  env = SgtnClient::Config.default_environment
105
121
  mode = SgtnClient::Config.configurations[env]["bundle_mode"]
122
+ SgtnClient.logger.debug "[Translation][load]mode=#{mode}"
106
123
  if mode == 'offline'
107
124
  return load_o(component, locale)
108
125
  else
@@ -116,7 +133,6 @@ module SgtnClient
116
133
  version = SgtnClient::Config.configurations[env]["version"].to_s
117
134
  translation_bundle = SgtnClient::Config.configurations[env]["translation_bundle"]
118
135
  bundlepath = translation_bundle + "/" + product_name + "/" + version + "/" + component + "/messages_" + locale + ".json"
119
- SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
120
136
  SgtnClient::FileUtil.read_json(bundlepath)
121
137
  end
122
138
 
@@ -124,10 +140,8 @@ module SgtnClient
124
140
  env = SgtnClient::Config.default_environment
125
141
  product_name = SgtnClient::Config.configurations[env]["product_name"]
126
142
  vip_server = SgtnClient::Config.configurations[env]["vip_server"]
127
- SgtnClient.logger.debug "Getting translations from server: " + vip_server
128
143
  version = SgtnClient::Config.configurations[env]["version"].to_s
129
144
  url = vip_server + "/i18n/api/v2/translation/products/" + product_name + "/versions/" + version + "/locales/" + locale + "/components/" + component+ "?checkTranslationStatus=false&machineTranslation=false&pseudo=false"
130
- SgtnClient.logger.debug url
131
145
  begin
132
146
  obj = SgtnClient::Core::Request.get(url)
133
147
  rescue => exception
@@ -141,4 +155,4 @@ module SgtnClient
141
155
 
142
156
  end
143
157
 
144
- end
158
+ end
@@ -1,4 +1,7 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'sgtn-client/cldr/localized_datetime'
2
5
  require 'sgtn-client/cldr/localized_date'
3
6
  require 'sgtn-client/cldr/localized_time'
4
- require 'sgtn-client/cldr/localized_str'
7
+ require 'sgtn-client/cldr/localized_str'
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'date'
2
5
  require 'time'
3
6
 
@@ -24,4 +27,4 @@ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
27
  def l_short_s(locale = TwitterCldr.locale)
25
28
  self.to_datetime().localize(locale).to_date().to_short_s
26
29
  end
27
- LOCALIZE
30
+ LOCALIZE
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'date'
2
5
  require 'time'
3
6
 
@@ -60,4 +63,4 @@ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
60
63
  tz.display_name_for(self, display_name)
61
64
  end
62
65
  end
63
- LOCALIZE
66
+ LOCALIZE
@@ -1,3 +1,5 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
1
3
 
2
4
  String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
3
5
  def to_plural_s(locale, arg)
@@ -8,4 +10,4 @@ String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
8
10
  num_str
9
11
  end
10
12
  end
11
- LOCALIZE
13
+ LOCALIZE
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'date'
2
5
  require 'time'
3
6
 
@@ -24,4 +27,4 @@ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
24
27
  def l_short_s(locale = TwitterCldr.locale)
25
28
  self.localize(locale).to_short_s
26
29
  end
27
- LOCALIZE
30
+ LOCALIZE
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'date'
2
5
 
3
6
  module SgtnClient::Core
@@ -7,13 +10,12 @@ module SgtnClient::Core
7
10
  def self.initialize(disabled=false, opts={})
8
11
  @@opts = opts
9
12
  @mutex = Mutex.new
10
- SgtnClient.logger.debug "Initialize cache......"
11
13
  if disabled == false
12
14
  @@data = Hash.new
13
- SgtnClient.logger.debug "Cache is enabled!"
15
+ SgtnClient.logger.debug "[Cache][initialize]cache is enabled!"
14
16
  else
15
17
  @@data = nil
16
- SgtnClient.logger.debug "Cache is disabled!"
18
+ SgtnClient.logger.debug "[Cache][initialize]cache is disabled!"
17
19
  end
18
20
  end
19
21
 
@@ -21,7 +23,7 @@ module SgtnClient::Core
21
23
  if @@data == nil
22
24
  return nil
23
25
  end
24
- SgtnClient.logger.debug "Get cache keys"
26
+ SgtnClient.logger.debug "[Cache][keys]get cache keys"
25
27
  @@data.keys
26
28
  end
27
29
 
@@ -29,7 +31,7 @@ module SgtnClient::Core
29
31
  if @@data == nil
30
32
  return nil, nil
31
33
  end
32
- SgtnClient.logger.debug "Get cache for key: " + key
34
+ SgtnClient.logger.debug "[Cache][get]get cache for key: " + key
33
35
  invalidate(key)
34
36
  end
35
37
 
@@ -37,7 +39,7 @@ module SgtnClient::Core
37
39
  if @@data == nil
38
40
  return nil
39
41
  end
40
- SgtnClient.logger.debug "Check if the cache has key: #{(@@data.has_key? key)}"
42
+ SgtnClient.logger.debug "[Cache][has]check if the cache has key: #{(@@data.has_key? key)}"
41
43
  @@data.has_key? key
42
44
  end
43
45
 
@@ -48,7 +50,7 @@ module SgtnClient::Core
48
50
  end
49
51
  ttl ||= @@opts[:ttl]
50
52
  # hours from new
51
- SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
53
+ SgtnClient.logger.debug "[Cache][put]put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
52
54
  @@data[key] = Entry.new(Time.now + ttl*60, value)
53
55
  end
54
56
  end
@@ -58,7 +60,7 @@ module SgtnClient::Core
58
60
  if @@data == nil
59
61
  return nil
60
62
  end
61
- SgtnClient.logger.debug "Delete cache for key: " + key
63
+ SgtnClient.logger.debug "[Cache][delete]delete cache for key: " + key
62
64
  @@data.delete key
63
65
  end
64
66
  end
@@ -68,7 +70,7 @@ module SgtnClient::Core
68
70
  if @@data == nil
69
71
  return nil
70
72
  end
71
- SgtnClient.logger.debug "Clear cache!"
73
+ SgtnClient.logger.debug "[Cache][clear]clear cache!"
72
74
  @@data = Hash.new
73
75
  end
74
76
  end
@@ -78,16 +80,16 @@ module SgtnClient::Core
78
80
  if @@data == nil
79
81
  return nil, nil
80
82
  end
81
- SgtnClient.logger.debug "Invalidating expired cache......"
83
+ SgtnClient.logger.debug "[Cache][invalidate]invalidate expired cache......"
82
84
  now = Time.now
83
85
  if has(key)
84
86
  v = @@data[key]
85
87
  expired = false
86
- SgtnClient.logger.debug "Checking cache: key=#{key}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
88
+ SgtnClient.logger.debug "[Cache][invalidate]check cache: key=#{key}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
87
89
  if v[:expiry] < now
88
- SgtnClient.logger.debug "Before deleting the cache: data=#{@@data}"
90
+ SgtnClient.logger.debug "[Cache][invalidate]before deleting the cache: data=#{@@data}"
89
91
  @@data.delete(key)
90
- SgtnClient.logger.debug "After deleting the cache: data=#{@@data}"
92
+ SgtnClient.logger.debug "[Cache][invalidate]after deleting the cache: data=#{@@data}"
91
93
  expired = true
92
94
  end
93
95
  return expired, v[:value]
@@ -98,4 +100,4 @@ module SgtnClient::Core
98
100
  end
99
101
  end
100
102
 
101
- end
103
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'erb'
2
5
  require 'yaml'
3
6
 
@@ -163,4 +166,4 @@ module SgtnClient
163
166
  end
164
167
  end
165
168
 
166
- end
169
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'multi_json'
2
5
  require 'pp'
3
6
 
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'logger'
2
5
 
3
6
  module SgtnClient
@@ -47,4 +50,3 @@ module SgtnClient
47
50
  end
48
51
 
49
52
  end
50
-
@@ -1,10 +1,13 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'rest-client'
2
5
  require 'multi_json'
3
6
 
4
7
  module SgtnClient::Core
5
8
  class Request
6
9
  def self.get(url)
7
- #res = RestClient.get(url)
10
+ SgtnClient.logger.debug "[Request][get]url=#{url}"
8
11
  res = RestClient::Resource.new(
9
12
  url,
10
13
  :verify_ssl => false
@@ -18,4 +21,4 @@ module SgtnClient::Core
18
21
  return obj
19
22
  end
20
23
  end
21
- end
24
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'json'
2
5
 
3
6
  module SgtnClient
@@ -35,4 +38,4 @@ module SgtnClient
35
38
  end
36
39
  end
37
40
  end
38
- end
41
+ end
@@ -1,4 +1,9 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  module SgtnClient
5
+ LOGFILE_SHIFT_AGE = 4
6
+
2
7
  module Core
3
8
  autoload :Cache, "sgtn-client/core/cache"
4
9
  end
@@ -38,17 +43,18 @@ module SgtnClient
38
43
 
39
44
  # create log file
40
45
  file = './sgtnclient_d.log'
46
+ SgtnClient.logger.debug "[Client][load]create log file=#{file}"
41
47
  if args[2] != nil
42
48
  file = args[2]
43
49
  end
44
50
  file = File.open(file, 'a')
45
51
  file.sync = true
46
- SgtnClient.logger = Logger.new(file)
52
+ SgtnClient.logger = Logger.new(file, LOGFILE_SHIFT_AGE)
47
53
 
48
54
  # Set log level for sandbox mode
49
55
  env = SgtnClient::Config.default_environment
50
56
  mode = SgtnClient::Config.configurations[env]["mode"]
51
- SgtnClient.logger.info "Current mode is: " + mode
57
+ SgtnClient.logger.debug "[Client][load]set log level, mode=#{mode}"
52
58
  if mode == 'sandbox'
53
59
  SgtnClient.logger.level = Logger::DEBUG
54
60
  else
@@ -57,6 +63,7 @@ module SgtnClient
57
63
 
58
64
  # initialize cache
59
65
  disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
66
+ SgtnClient.logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
60
67
  if disable_cache != nil
61
68
  SgtnClient::Core::Cache.initialize(disable_cache)
62
69
  else
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'erb'
2
5
  require 'yaml'
3
6
 
@@ -11,16 +14,17 @@ module SgtnClient
11
14
 
12
15
  def self.get_cache(cache_key)
13
16
  expired, items = SgtnClient::Core::Cache.get(cache_key)
17
+ SgtnClient.logger.debug "[CacheUtil]get cache with key #{cache_key}, expired #{expired}"
14
18
  return expired, items
15
19
  end
16
20
 
17
21
  def self.clear_cache()
18
22
  SgtnClient::Core::Cache.clear()
23
+ SgtnClient.logger.debug "[CacheUtil]clear cache"
19
24
  end
20
25
 
21
26
  def self.write_cache(cache_key, items)
22
27
  if items.nil?
23
- SgtnClient.logger.debug "write cache with key #{cache_key}, itmes #{items}"
24
28
  return nil
25
29
  end
26
30
  env = SgtnClient::Config.default_environment
@@ -29,6 +33,7 @@ module SgtnClient
29
33
  if cache_expiry_period == nil
30
34
  cache_expiry_period = 24*60
31
35
  end
36
+ SgtnClient.logger.debug "[CacheUtil]write cache with key #{cache_key}, cache_expiry_period #{cache_expiry_period}, itmes #{items}"
32
37
  SgtnClient::Core::Cache.put(cache_key, items, cache_expiry_period)
33
38
  end
34
39
 
@@ -36,13 +41,8 @@ module SgtnClient
36
41
  env = SgtnClient::Config.default_environment
37
42
  product_name = SgtnClient::Config.configurations[env]["product_name"]
38
43
  version = SgtnClient::Config.configurations[env]["version"].to_s
39
- default_l = SgtnClient::Config.configurations[env]["default_language"]
40
- if default_l == nil
41
- default_l = 'en'
42
- end
43
- lc = locale == default_l ? SgtnClient::Config.configurations.default: locale
44
- return product_name + "_" + version + "_" + component + "_" + lc
44
+ product_name + "_" + version + "_" + component + "_" + locale
45
45
  end
46
46
  end
47
47
 
48
- end
48
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'erb'
2
5
  require 'yaml'
3
6
 
@@ -8,6 +11,7 @@ module SgtnClient
8
11
  @mutex = Mutex.new
9
12
 
10
13
  def self.read_json(bundlepath)
14
+ SgtnClient.logger.debug "[FileUtil]read json file from: " + bundlepath
11
15
  @mutex.synchronize do
12
16
  data_hash = nil
13
17
  begin
@@ -21,6 +25,7 @@ module SgtnClient
21
25
  end
22
26
 
23
27
  def self.read_yml(file_name)
28
+ SgtnClient.logger.debug "[FileUtil]read yml file from: " + file_name
24
29
  @mutex.synchronize do
25
30
  erb = ERB.new(File.read(file_name))
26
31
  erb.filename = file_name
@@ -29,4 +34,4 @@ module SgtnClient
29
34
  end
30
35
  end
31
36
 
32
- end
37
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  module SgtnClient
2
5
 
3
6
  DEFAULT_LOCALES = ['en', 'de', 'es', 'fr', 'ko', 'ja', 'zh-Hans', 'zh-Hant']
@@ -10,6 +13,13 @@ module SgtnClient
10
13
  }
11
14
 
12
15
  class LocaleUtil
16
+ def self.get_best_locale(locale)
17
+ fallback(process_locale(locale))
18
+ end
19
+ def self.process_locale(locale=nil)
20
+ locale ||= SgtnClient::Config.configurations.default
21
+ locale.to_s
22
+ end
13
23
  def self.fallback(locale)
14
24
  found = SgtnClient::DEFAULT_LOCALES.select {|e| e == locale}
15
25
  if !found.empty?
@@ -27,5 +37,10 @@ module SgtnClient
27
37
  end
28
38
  return locale
29
39
  end
40
+ def self.get_source_locale
41
+ env = SgtnClient::Config.default_environment
42
+ source_locale = SgtnClient::Config.configurations[env]["default_language"]
43
+ source_locale || 'en'
44
+ end
30
45
  end
31
- end
46
+ end
@@ -1,11 +1,13 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
1
3
 
2
4
  module SgtnClient
3
5
 
4
6
  class ValidateUtil
5
7
 
6
8
  def self.validate_config()
7
- SgtnClient.logger.debug "-----------Start to validate configuration's setting itmes-----------"
8
9
  env = SgtnClient::Config.default_environment
10
+ SgtnClient.logger.debug "[ValidateUtil][validate_config] env = #{env}"
9
11
  messages = "\n"
10
12
 
11
13
  mode = SgtnClient::Config.configurations[env]["mode"]
@@ -36,9 +38,8 @@ module SgtnClient
36
38
  if messages != "\n"
37
39
  raise SgtnClient::Exceptions::MissingConfig.new(messages)
38
40
  end
39
- SgtnClient.logger.debug "-----------End to validate configuration's setting itmes-----------"
40
41
  end
41
42
 
42
43
  end
43
44
 
44
- end
45
+ end
@@ -1,3 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require "sgtn-client/sgtn-client"
2
5
  require 'sgtn-client/cldr/core_ext'
3
6
  require 'twitter_cldr'
data/lib/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
1
3
 
2
4
  VERSION_INFO = [0, 2, 1].freeze
3
5
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-client-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.29
4
+ version: 0.7.0.32
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: 2022-01-27 00:00:00.000000000 Z
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client