singleton-ruby 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2e9bf60e2c6e5a1c59e1d0b25a9acb3d7f645c08aab5365d725895bd5a0c5f0
4
- data.tar.gz: 54d2803ac84376f0df6223d9aa3d4eb1a553f8b93214acc1591c95566de5346d
3
+ metadata.gz: 978dd434bf07cb9ccc6966760af86f85259105512b5a4118474b859d43186cf6
4
+ data.tar.gz: 89629f003c872b85c49cb9b5fdcca99e5fedd51b7d10d6888f6c1246abf03da8
5
5
  SHA512:
6
- metadata.gz: 1e8775d0142dddcfef46c2ba781ed0885f16854fccab273f2483f1fbd0e6744cc1a360d569f3e32c92acc40ebd001864c45448eeaa70443095952a81eab79b2d
7
- data.tar.gz: 3b009b345f63e0c97fcbe983b15673ea82199264fef1135ac3e0922677bf07fd1695ba5c011ad5932730266cb08228dccb5d5ff68670289df80ae98f146a13cd
6
+ metadata.gz: 4692a75171757d89bc02f9daaef93486362d1eddd31e4d4f56d615bf1323034d5a8ca322f3ba7c8f170f8905da4e6064beaa04e6ce5d62323045b03655a0744a
7
+ data.tar.gz: 88c5610594c579322fc2fe3c33689e00330412351f4b82f3f782c9e55ef7eaab40f98c20123e1c8b985c3a6f74408e01b6e5d950aabd5f695205d9f6aad8be73
@@ -7,12 +7,11 @@ module SgtnClient
7
7
 
8
8
  class Source
9
9
 
10
- def self.getSource(component, key)
11
- locale = "en"
10
+ def self.getSource(component, key, locale)
12
11
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
13
12
  items = SgtnClient::CacheUtil.get_cache(cache_key)
14
13
  if items.nil?
15
- items = getBundle(component)
14
+ items = getBundle(component, locale)
16
15
  SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
17
16
  SgtnClient::CacheUtil.write_cache(cache_key, items)
18
17
  else
@@ -40,10 +39,10 @@ module SgtnClient
40
39
 
41
40
  private
42
41
 
43
- def self.getBundle(component)
42
+ def self.getBundle(component, locale)
44
43
  env = SgtnClient::Config.default_environment
45
44
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
46
- bundlepath = source_bundle + "/" + component + "/en.yml"
45
+ bundlepath = source_bundle + "/" + component + "/" + locale + ".yml"
47
46
  SgtnClient.logger.debug "Getting source from bundle: " + bundlepath
48
47
  begin
49
48
  bundle = read_yml(bundlepath)
@@ -6,26 +6,27 @@ module SgtnClient
6
6
  autoload :Request, "sgtn-client/core/request"
7
7
  autoload :Cache, "sgtn-client/core/cache"
8
8
  autoload :CacheUtil, "sgtn-client/util/cache-util"
9
+ autoload :LocaleUtil, "sgtn-client/util/locale-util"
9
10
  end
10
11
 
11
12
  class Translation
12
13
 
13
14
  def self.getString(component, key, locale)
14
- cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
15
+ flocale = SgtnClient::LocaleUtil.fallback(locale)
16
+ cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
15
17
  items = SgtnClient::CacheUtil.get_cache(cache_key)
16
18
  if items.nil?
17
- items = getTranslations(component, locale)
19
+ items = getTranslations(component, flocale)
18
20
  SgtnClient::CacheUtil.write_cache(cache_key, items)
19
21
  else
20
22
  SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
21
23
  end
22
- if items.nil?
23
- return SgtnClient::Source.getSource(component, key)
24
+ if items.nil? || items["messages"] == nil
25
+ return SgtnClient::Source.getSource(component, key, "default")
24
26
  end
25
-
26
27
  str = items["messages"][key]
27
28
  if str.nil?
28
- return SgtnClient::Source.getSource(component, key)
29
+ return SgtnClient::Source.getSource(component, key, "default")
29
30
  else
30
31
  return str
31
32
  end
@@ -67,6 +68,7 @@ module SgtnClient
67
68
  SgtnClient.logger.debug "Getting translations from server: " + vip_server
68
69
  version = SgtnClient::Config.configurations[env]["version"].to_s
69
70
  url = vip_server + "/i18n/api/v2/translation/products/" + product_name + "/versions/" + version + "/locales/" + locale + "/components/" + component+ "?checkTranslationStatus=false&machineTranslation=false&pseudo=false"
71
+ SgtnClient.logger.debug url
70
72
  begin
71
73
  obj = SgtnClient::Core::Request.get(url)
72
74
  rescue => exception
@@ -9,6 +9,7 @@ module SgtnClient
9
9
  autoload :Logging, "sgtn-client/core/logging"
10
10
  autoload :Exceptions, "sgtn-client/core/exceptions"
11
11
  autoload :ValidateUtil, "sgtn-client/util/validate-util"
12
+ autoload :LocaleUtil, "sgtn-client/util/locale-util"
12
13
 
13
14
  class << self
14
15
  def configure(options = {}, &block)
@@ -14,6 +14,10 @@ module SgtnClient
14
14
  return items
15
15
  end
16
16
 
17
+ def self.clear_cache()
18
+ SgtnClient::Core::Cache.clear()
19
+ end
20
+
17
21
  def self.write_cache(cache_key, items)
18
22
  env = SgtnClient::Config.default_environment
19
23
  cache_expiry_period = SgtnClient::Config.configurations[env]["cache_expiry_period"]
@@ -0,0 +1,31 @@
1
+ module SgtnClient
2
+
3
+ DEFAULT_LOCALES = ['en', 'de', 'es', 'fr', 'ko', 'ja', 'zh-Hans', 'zh-Hant']
4
+
5
+ MAP_LOCALES = {
6
+ "zh-CN" =>"zh-Hans",
7
+ "zh-TW" =>"zh-Hant",
8
+ "zh-Hans-CN" =>"zh-Hans",
9
+ "zh-Hant-TW" =>"zh-Hant",
10
+ }
11
+
12
+ class LocaleUtil
13
+ def self.fallback(locale)
14
+ found = SgtnClient::DEFAULT_LOCALES.select {|e| e == locale}
15
+ if !found.empty?
16
+ return found[0]
17
+ end
18
+ if SgtnClient::MAP_LOCALES.key?(locale)
19
+ return SgtnClient::MAP_LOCALES[locale]
20
+ end
21
+ parts = locale.split("-")
22
+ if parts.size > 1
23
+ f = SgtnClient::DEFAULT_LOCALES.select {|e| e == parts[0]}
24
+ if !f.empty?
25
+ return f[0]
26
+ end
27
+ end
28
+ return locale
29
+ end
30
+ end
31
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 0, 9].freeze
2
+ VERSION_INFO = [0, 1, 0].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
@@ -0,0 +1,3 @@
1
+ default:
2
+ hello: "Hello world"
3
+ com.vmware.loginsight.web.settings.stats.StatsTable.host: "Host"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "component" : "JAVA",
3
3
  "messages" : {
4
- "hello": "@hello@",
4
+ "hello": "Hello world",
5
5
  "com.vmware.loginsight.web.settings.stats.StatsTable.host" : "Host",
6
6
  "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond" : "Events Ingestion Rate (Per Second)",
7
7
  "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond.help" : "The actual ingestion rate (syslog + API) of each node after message rebalancing.<br />Log Insight nodes will rebalance messages to attempt uniform ingestion per node for balanced retention and performance.<br /><br />Note that the ingestion rate of each node must be below the ingestion rate configuration maximum for a node.<br /><br />For the actual rate of events being sent directly to each node prior to message rebalancing, see the Syslog Events Incoming Rate (Per Second) and API Events Incoming Rate (Per Second) tables below.",
@@ -7,7 +7,7 @@ describe SgtnClient do
7
7
  env = SgtnClient::Config.default_environment
8
8
  SgtnClient::Config.configurations[env]["bundle_mode"] = 'online'
9
9
  SgtnClient::Config.configurations[env]["cache_expiry_period"] = 1
10
- SgtnClient::Source.loadBundles("en")
10
+ SgtnClient::Source.loadBundles("default")
11
11
  end
12
12
 
13
13
  it "GETTranslation" do
@@ -15,7 +15,6 @@ describe SgtnClient do
15
15
  # get translation from server
16
16
  SgtnClient.logger.debug "----------Start to get translation from server---------"
17
17
  expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
18
-
19
18
  # get translation from cache
20
19
  SgtnClient.logger.debug "----------Start to get translation from cache---------"
21
20
  expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe SgtnClient do
4
+ describe "Locale" do
5
+
6
+ before :each do
7
+ end
8
+
9
+ it "fallback" do
10
+ expect(SgtnClient::LocaleUtil.fallback('ja-JP')).to eq 'ja'
11
+ expect(SgtnClient::LocaleUtil.fallback('de-DE')).to eq 'de'
12
+ expect(SgtnClient::LocaleUtil.fallback('zh')).to eq 'zh'
13
+ expect(SgtnClient::LocaleUtil.fallback('zh-Hans')).to eq 'zh-Hans'
14
+ expect(SgtnClient::LocaleUtil.fallback('zh-Hant')).to eq 'zh-Hant'
15
+ expect(SgtnClient::LocaleUtil.fallback('zh-CN')).to eq 'zh-Hans'
16
+ expect(SgtnClient::LocaleUtil.fallback('zh-TW')).to eq 'zh-Hant'
17
+ expect(SgtnClient::LocaleUtil.fallback('zh-Hans-CN')).to eq 'zh-Hans'
18
+ expect(SgtnClient::LocaleUtil.fallback('zh-Hant-TW')).to eq 'zh-Hant'
19
+ expect(SgtnClient::LocaleUtil.fallback('kong-kong')).to eq 'kong-kong'
20
+ end
21
+ end
22
+
23
+ end
@@ -6,7 +6,7 @@ describe SgtnClient do
6
6
  before :each do
7
7
  env = SgtnClient::Config.default_environment
8
8
  SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
9
- SgtnClient::Source.loadBundles("en")
9
+ SgtnClient::Source.loadBundles("default")
10
10
  end
11
11
 
12
12
  it "GET" do
@@ -15,10 +15,16 @@ describe SgtnClient do
15
15
  expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
16
16
  end
17
17
 
18
+ it "GET_EN" do
19
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
20
+ # get from cache in 2nd time
21
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
22
+ end
23
+
18
24
  it "GET_zh_CN" do
19
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh_CN")).to eq '主机'
25
+ expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-CN")).to eq '主机'
20
26
  # get from cache in 2nd time
21
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh_CN")).to eq '主机'
27
+ expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-CN")).to eq '主机'
22
28
  end
23
29
 
24
30
  it "NonExistingKey" do
@@ -5,8 +5,15 @@ describe SgtnClient do
5
5
 
6
6
  before :each do
7
7
  env = SgtnClient::Config.default_environment
8
+ SgtnClient::CacheUtil.clear_cache()
8
9
  SgtnClient::Config.configurations[env]["bundle_mode"] = 'online'
9
- SgtnClient::Source.loadBundles("en")
10
+ SgtnClient::Source.loadBundles("default")
11
+ end
12
+
13
+ it "GET_EN" do
14
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
15
+ # get from cache in 2nd time
16
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
10
17
  end
11
18
 
12
19
  it "GET" do
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.0.9
4
+ version: 0.1.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-07-08 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -267,16 +267,16 @@ files:
267
267
  - lib/sgtn-client/core/request.rb
268
268
  - lib/sgtn-client/sgtn-client.rb
269
269
  - lib/sgtn-client/util/cache-util.rb
270
+ - lib/sgtn-client/util/locale-util.rb
270
271
  - lib/sgtn-client/util/validate-util.rb
271
272
  - lib/singleton-ruby.rb
272
273
  - lib/version.rb
273
- - spec/config/locales/default/JAVA/en.yml
274
+ - spec/config/locales/default/JAVA/default.yml
274
275
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_de.json
275
276
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_en.json
276
277
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_latest.json
277
278
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hans.json
278
279
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hant.json
279
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh_CN.json
280
280
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/creation.json
281
281
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/version.json
282
282
  - spec/config/sample_data.yml
@@ -288,9 +288,10 @@ files:
288
288
  - spec/unit/cache_spec.rb
289
289
  - spec/unit/config_spec.rb
290
290
  - spec/unit/inconfig_spec.rb
291
+ - spec/unit/locale_spec.rb
291
292
  - spec/unit/logging_spec.rb
292
293
  - spec/unit/offclient_spec.rb
293
- - spec/unit/restclient_spec.rb
294
+ - spec/unit/onclient_spec.rb
294
295
  - spec/unit/version_spec.rb
295
296
  homepage: https://github.com/vmware/singleton
296
297
  licenses:
@@ -311,18 +312,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
312
  - !ruby/object:Gem::Version
312
313
  version: '0'
313
314
  requirements: []
314
- rubygems_version: 3.1.4
315
+ rubygems_version: 3.0.9
315
316
  signing_key:
316
317
  specification_version: 4
317
318
  summary: Singleton client for Ruby.
318
319
  test_files:
319
- - spec/config/locales/default/JAVA/en.yml
320
+ - spec/config/locales/default/JAVA/default.yml
320
321
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_de.json
321
322
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_en.json
322
323
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_latest.json
323
324
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hans.json
324
325
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hant.json
325
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh_CN.json
326
326
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/creation.json
327
327
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/version.json
328
328
  - spec/config/sample_data.yml
@@ -334,7 +334,8 @@ test_files:
334
334
  - spec/unit/cache_spec.rb
335
335
  - spec/unit/config_spec.rb
336
336
  - spec/unit/inconfig_spec.rb
337
+ - spec/unit/locale_spec.rb
337
338
  - spec/unit/logging_spec.rb
338
339
  - spec/unit/offclient_spec.rb
339
- - spec/unit/restclient_spec.rb
340
+ - spec/unit/onclient_spec.rb
340
341
  - spec/unit/version_spec.rb
@@ -1,2 +0,0 @@
1
- en:
2
- hello: "Hello world"
@@ -1,11 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "com.vmware.loginsight.web.settings.stats.StatsTable.host" : "主机",
5
- "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond" : "事件载入速率 (每秒)",
6
- "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond.help" : "消息再平衡之后每个节点的实际载入速率 (syslog + API)。<br />Log Insight 节点将再平衡消息以尝试每节点的统一载入,从而实现平衡保留和性能。<br /><br />请注意,每个节点的载入速率必须低于配置的最大节点载入速率。<br /><br />有关消息再平衡之前直接发送到每个节点的事件的实际速率,请参见下述“Syslog 事件入站速率 (每秒)”和“API 事件入站速率 (每秒)”表。",
7
- "com.vmware.loginsight.web.settings.stats.StatsTableType.syslogEventsIncomingRatePerSecond" : "Syslog 事件入站速率 (每秒)",
8
- "com.vmware.loginsight.web.utilities.EmailUtil.upgrade.body48" : "{0} 现在正在运行版本 {1}。下面是 {1} 版本中新增的一些出色功能。我们感谢您一如既往地支持,同时非常重视您通过 Twitter 针对我们的 {3} 和 {4} 提供的反馈。<br /><br /><b>vRealize Log Insight 服务器功能</b><br />• TODO 增加服务器功能。<br /><br /><b>vRealize Log Insight 代理功能</b><br />• TODO 增加代理功能。<br /><br />有关 {0} 的新功能的详细信息,请查看 {0} v{1} {2}。<br /><br />祝您使用愉快!<br />{0} 团队<br /><br />"
9
- },
10
- "locale" : "zh-Hans"
11
- }