singleton-client 0.7.4 → 0.7.5

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: 43d840f37ce5f60b23e16623db0b4393f014eaeaafa0ddf91520225a93bd9c57
4
- data.tar.gz: d3c1e045e6c75f7e09cd2790de733a217516afede51dbfede1224cbabcbd3b53
3
+ metadata.gz: 662845b2e8dcbe69030049114857506ba0e2d5fd0ab98fdf886ddfd07ed1c7a8
4
+ data.tar.gz: bafa7b6a9f9d68e735ad1c830f37ea7f770381cafd7ff4ecda142d1673cec9c3
5
5
  SHA512:
6
- metadata.gz: 56593be0f8686d669216a849592b9100bb47f52087bf10938d1fae79fb123b9b4ee68baa10e8e627c2ef263e79f2f056aac777e2e5ebc3d8d7f5fbd15b758ce5
7
- data.tar.gz: 5eca696945202e002be5c489ee37153d63c6498e4cc8639f5ea3ad11666ac63e4fffee59572e29fbeb0ff4c7489ff29b06a77cb57e2f9f077cde0663ca5e115b
6
+ metadata.gz: 3249cfcdce192e2e04670aefb03fd090c9b436171edeb80bec82d1d62816e8406d7aaaa92e3b85aec0d9e625babbab136d61e3e0d4ecf12d582c0fd99ad5a5c5
7
+ data.tar.gz: c694298fc391a1395ea62b4b3fe7595c5deae8fd1909d01af1b6097a03848583a81e5b0d52ef16339645bc74035f180feae9110cad56f0b67d082a95c72bb3e1
@@ -1,3 +1,5 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
1
3
 
2
4
  module SgtnClient
3
5
 
@@ -15,7 +17,7 @@ module SgtnClient
15
17
  else
16
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
22
  SgtnClient.logger.debug "[Source][getSource]source not found, return key: " + key
21
23
  #return key
@@ -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
@@ -56,6 +59,7 @@ module SgtnClient
56
59
 
57
60
  def self.getStrings(component, locale)
58
61
  SgtnClient.logger.debug "[Translation][getStrings]component=#{component}, locale=#{locale}"
62
+ locale = SgtnClient::LocaleUtil.get_best_locale(locale)
59
63
  items = get_cs(component, locale)
60
64
  default = SgtnClient::Config.configurations.default
61
65
  if items.nil? || items["messages"] == nil
@@ -77,6 +81,7 @@ module SgtnClient
77
81
  private
78
82
 
79
83
  def self.getTranslation(component, key, locale)
84
+ locale = SgtnClient::LocaleUtil.get_best_locale(locale)
80
85
  items = get_cs(component, locale)
81
86
  if items.nil? || items["messages"] == nil
82
87
  nil
@@ -86,12 +91,18 @@ module SgtnClient
86
91
  end
87
92
 
88
93
  def self.get_cs(component, locale)
89
- flocale = SgtnClient::LocaleUtil.fallback(locale)
90
- 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)
91
102
  SgtnClient.logger.debug "[Translation][get_cs]cache_key=#{cache_key}"
92
103
  expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
93
104
  if items.nil? || expired
94
- items = load(component, flocale)
105
+ items = load(component, locale)
95
106
  if items.nil?
96
107
  items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
97
108
  SgtnClient::Core::Cache.put(cache_key, items, 60)
@@ -144,4 +155,4 @@ module SgtnClient
144
155
 
145
156
  end
146
157
 
147
- 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
@@ -97,4 +100,4 @@ module SgtnClient::Core
97
100
  end
98
101
  end
99
102
 
100
- 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,3 +1,6 @@
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
 
@@ -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
@@ -44,7 +49,7 @@ module SgtnClient
44
49
  end
45
50
  file = File.open(file, 'a')
46
51
  file.sync = true
47
- SgtnClient.logger = Logger.new(file)
52
+ SgtnClient.logger = Logger.new(file, LOGFILE_SHIFT_AGE)
48
53
 
49
54
  # Set log level for sandbox mode
50
55
  env = SgtnClient::Config.default_environment
@@ -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
 
@@ -38,14 +41,8 @@ module SgtnClient
38
41
  env = SgtnClient::Config.default_environment
39
42
  product_name = SgtnClient::Config.configurations[env]["product_name"]
40
43
  version = SgtnClient::Config.configurations[env]["version"].to_s
41
- default_l = SgtnClient::Config.configurations[env]["default_language"]
42
- if default_l == nil
43
- default_l = 'en'
44
- end
45
- lc = locale == default_l ? SgtnClient::Config.configurations.default: locale
46
- SgtnClient.logger.debug "[CacheUtil]get cache key: #{lc}"
47
- return product_name + "_" + version + "_" + component + "_" + lc
44
+ product_name + "_" + version + "_" + component + "_" + locale
48
45
  end
49
46
  end
50
47
 
51
- 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
 
@@ -31,4 +34,4 @@ module SgtnClient
31
34
  end
32
35
  end
33
36
 
34
- 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,3 +1,5 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
1
3
 
2
4
  module SgtnClient
3
5
 
@@ -40,4 +42,4 @@ module SgtnClient
40
42
 
41
43
  end
42
44
 
43
- 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
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
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-02-15 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