singleton-ruby 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -0
  3. data/lib/sgtn-client/api/source.rb +16 -5
  4. data/lib/sgtn-client/api/t.rb +22 -0
  5. data/lib/sgtn-client/api/translation.rb +30 -2
  6. data/lib/sgtn-client/core/config.rb +0 -7
  7. data/lib/sgtn-client/core/exceptions.rb +1 -1
  8. data/lib/sgtn-client/sgtn-client.rb +1 -0
  9. data/lib/version.rb +1 -1
  10. data/spec/config/locales/default/JAVA/default.yml +4 -2
  11. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json +8 -0
  12. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json +8 -0
  13. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json +8 -0
  14. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json +8 -0
  15. data/spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json +8 -0
  16. data/spec/config/locales/l10n/bundles/{logInsight → test}/4.8.1/creation.json +0 -0
  17. data/spec/config/locales/l10n/bundles/{logInsight → test}/4.8.1/version.json +0 -0
  18. data/spec/config/sgtnclient-invalidate.yml +3 -7
  19. data/spec/config/sgtnclient.yml +3 -7
  20. data/spec/spec_helper.rb +1 -8
  21. data/spec/unit/cache_spec.rb +4 -4
  22. data/spec/unit/offclient_spec.rb +24 -8
  23. data/spec/unit/onclient_spec.rb +7 -7
  24. data/spec/unit/request_spec.rb +22 -0
  25. metadata +37 -52
  26. data/lib/generators/sgtnclient/USAGE +0 -3
  27. data/lib/generators/sgtnclient/install_generator.rb +0 -15
  28. data/lib/generators/sgtnclient/templates/sgtnclient.rb +0 -2
  29. data/lib/generators/sgtnclient/templates/sgtnclient.yml +0 -33
  30. data/spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_de.json +0 -11
  31. data/spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_en.json +0 -12
  32. data/spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_latest.json +0 -11
  33. data/spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hans.json +0 -11
  34. data/spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hant.json +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 978dd434bf07cb9ccc6966760af86f85259105512b5a4118474b859d43186cf6
4
- data.tar.gz: 89629f003c872b85c49cb9b5fdcca99e5fedd51b7d10d6888f6c1246abf03da8
3
+ metadata.gz: ffce54daa3338aaac24e5f302d46ea2b0d786def7c20dc5d737d5f8e839844d2
4
+ data.tar.gz: 934df8d9afc326b09981f12460e822db864ccb35f3e992c67b066689258343bf
5
5
  SHA512:
6
- metadata.gz: 4692a75171757d89bc02f9daaef93486362d1eddd31e4d4f56d615bf1323034d5a8ca322f3ba7c8f170f8905da4e6064beaa04e6ce5d62323045b03655a0744a
7
- data.tar.gz: 88c5610594c579322fc2fe3c33689e00330412351f4b82f3f782c9e55ef7eaab40f98c20123e1c8b985c3a6f74408e01b6e5d950aabd5f695205d9f6aad8be73
6
+ metadata.gz: 6ec453c3a483d728b165cf734a2aaf361f4be3582579ec1853b49aa9ac3ece43fd1ffb1215b42a13bb90662ad53c16d723eb8123a747d7a5aeeb3bc22310639a
7
+ data.tar.gz: 2a073e29ebe320b9336156d80832f89f1b05300398d8ca5fb0551cc51772aa33359ee71652d0bc538d7e29e6f52b44bebc054232ec9bf06b22a7368710d61329
data/README.md CHANGED
@@ -7,5 +7,49 @@
7
7
  ## Run Unit Test
8
8
  rake spec:unit
9
9
 
10
+ ## Usage
11
+
12
+ Basic Usage:
13
+
14
+ ```ruby
15
+ require 'singleton-ruby'
16
+
17
+ include SgtnClient
18
+
19
+ SgtnClient.load(file, mode)
20
+
21
+ SgtnClient::Source.loadBundles(locale)
22
+
23
+ @Result = SgtnClient::Translation.getString(component, key, locale)
24
+
25
+ ```
26
+ ## API
27
+
28
+ ### Get a string's translation
29
+ SgtnClient::Translation.getString(component, key, locale)
30
+
31
+ ### Get a string's translation and format it with placeholders
32
+ SgtnClient::Translation.getString_f(component, key, args, locale)
33
+
34
+ ### Get a component's translations
35
+ SgtnClient::Translation.getStrings(component, locale)
36
+
37
+
38
+ ## API with request_store
39
+
40
+ Before call below APIs(without locale and component arguments), it requires to set the locale
41
+ and component add the initial codes.
42
+
43
+ ### Get a string's translation
44
+ SgtnClient::T.s(key)
45
+
46
+ ### Get a string's translation and format it with placeholders
47
+ SgtnClient::T.s_f(key, args)
48
+
49
+ ### Get a component's translations
50
+ SgtnClient::T.c()
51
+
52
+
53
+
10
54
 
11
55
 
@@ -2,7 +2,7 @@ require 'erb'
2
2
  require 'yaml'
3
3
 
4
4
  module SgtnClient
5
-
5
+
6
6
  autoload :CacheUtil, "sgtn-client/util/cache-util"
7
7
 
8
8
  class Source
@@ -24,21 +24,33 @@ module SgtnClient
24
24
  return str
25
25
  end
26
26
 
27
+ def self.getSources(component, locale)
28
+ cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
29
+ items = SgtnClient::CacheUtil.get_cache(cache_key)
30
+ if items.nil?
31
+ items = getBundle(component, locale)
32
+ SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
33
+ SgtnClient::CacheUtil.write_cache(cache_key, items)
34
+ else
35
+ SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
36
+ end
37
+ return items
38
+ end
39
+
27
40
  def self.loadBundles(locale)
28
41
  env = SgtnClient::Config.default_environment
42
+ SgtnClient::Config.configurations.default = locale
29
43
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
30
- SgtnClient.logger.debug "Loading [" + locale + "] bundles from path: " + source_bundle
44
+ SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
31
45
  Dir.children(source_bundle).each do |component|
32
46
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
33
47
  bundle = read_yml(yamlfile)
34
48
  cachekey = SgtnClient::CacheUtil.get_cachekey(component, locale)
35
49
  SgtnClient::CacheUtil.write_cache(cachekey,bundle)
36
50
  end
37
-
38
51
  end
39
52
 
40
53
  private
41
-
42
54
  def self.getBundle(component, locale)
43
55
  env = SgtnClient::Config.default_environment
44
56
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
@@ -57,7 +69,6 @@ module SgtnClient
57
69
  erb.filename = file_name
58
70
  YAML.load(erb.result)
59
71
  end
60
-
61
72
  end
62
73
 
63
74
  end
@@ -0,0 +1,22 @@
1
+ module SgtnClient
2
+ class T < Translation
3
+
4
+ def self.s(key)
5
+ locale = RequestStore.store[:locale]
6
+ component = RequestStore.store[:component]
7
+ return getString(component, key, locale)
8
+ end
9
+
10
+ def self.s_f(key, args)
11
+ locale = RequestStore.store[:locale]
12
+ component = RequestStore.store[:component]
13
+ return getString_f(component, key, args, locale)
14
+ end
15
+
16
+ def self.c()
17
+ locale = RequestStore.store[:locale]
18
+ component = RequestStore.store[:component]
19
+ return getStrings(component, locale)
20
+ end
21
+ end
22
+ end
@@ -21,18 +21,46 @@ module SgtnClient
21
21
  else
22
22
  SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
23
23
  end
24
+
25
+ default = SgtnClient::Config.configurations.default
24
26
  if items.nil? || items["messages"] == nil
25
- return SgtnClient::Source.getSource(component, key, "default")
27
+ return SgtnClient::Source.getSource(component, key, default)
26
28
  end
27
29
  str = items["messages"][key]
28
30
  if str.nil?
29
- return SgtnClient::Source.getSource(component, key, "default")
31
+ return SgtnClient::Source.getSource(component, key, default)
30
32
  else
31
33
  return str
32
34
  end
35
+ end
33
36
 
37
+ def self.getString_f(component, key, args, locale)
38
+ s = getString(component, key, locale)
39
+ puts 1111
40
+ puts SgtnClient::Config.configurations.default
41
+ puts s
42
+ return s % args
34
43
  end
35
44
 
45
+ def self.getStrings(component, locale)
46
+ flocale = SgtnClient::LocaleUtil.fallback(locale)
47
+ cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
48
+ items = SgtnClient::CacheUtil.get_cache(cache_key)
49
+ if items.nil?
50
+ items = getTranslations(component, flocale)
51
+ SgtnClient::CacheUtil.write_cache(cache_key, items)
52
+ else
53
+ SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
54
+ end
55
+
56
+ default = SgtnClient::Config.configurations.default
57
+ if items.nil? || items["messages"] == nil
58
+ items = SgtnClient::Source.getSources(component, default)
59
+ end
60
+ return items
61
+ end
62
+
63
+
36
64
  private
37
65
 
38
66
  def self.getTranslations(component, locale)
@@ -65,13 +65,6 @@ module SgtnClient
65
65
  class << self
66
66
 
67
67
  @@config_cache = {}
68
-
69
- # Load configurations from file
70
- # === Arguments
71
- # * <tt>file_name</tt> -- Configuration file path
72
- # * <tt>default_environment</tt> (Optional) -- default environment configuration to load
73
- # === Example
74
- # Config.load('config/paypal.yml', 'development')
75
68
  def load(file_name, default_env = default_environment)
76
69
  @@config_cache = {}
77
70
  @@configurations = read_configurations(file_name)
@@ -14,7 +14,7 @@ module SgtnClient
14
14
  def to_s
15
15
  begin
16
16
  response_body = JSON.parse(response.body)
17
- debug_id = response["paypal-debug-id"]
17
+ debug_id = response["sgtn-debug-id"]
18
18
  debug_id = response["correlation-id"] if debug_id.to_s == ''
19
19
  debug_id = response_body["debug_id"] if debug_id.to_s == ''
20
20
  rescue
@@ -4,6 +4,7 @@ module SgtnClient
4
4
  end
5
5
 
6
6
  autoload :Translation, "sgtn-client/api/translation"
7
+ autoload :T, "sgtn-client/api/t"
7
8
  autoload :Source, "sgtn-client/api/source"
8
9
  autoload :Config, "sgtn-client/core/config"
9
10
  autoload :Logging, "sgtn-client/core/logging"
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 1, 0].freeze
2
+ VERSION_INFO = [0, 1, 4].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
@@ -1,3 +1,5 @@
1
1
  default:
2
- hello: "Hello world"
3
- com.vmware.loginsight.web.settings.stats.StatsTable.host: "Host"
2
+ helloworld: "Hello world"
3
+ hello: "Hello"
4
+ welcome: "%s, welcome login %s!"
5
+ login: "%s login %s!"
@@ -0,0 +1,8 @@
1
+ {
2
+ "component" : "JAVA",
3
+ "messages" : {
4
+ "helloworld" : "Hallo Welt",
5
+ "welcome": "%s, Willkommen in der %s des Logins!!"
6
+ },
7
+ "locale" : "de"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "component" : "JAVA",
3
+ "messages" : {
4
+ "helloworld" : "Hello world",
5
+ "welcome": "%s, welcome login %s!"
6
+ },
7
+ "locale" : "en"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "component" : "JAVA",
3
+ "messages" : {
4
+ "helloworld" : "Hello world",
5
+ "welcome": "%s, welcome login %s!"
6
+ },
7
+ "locale" : "latest"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "component" : "JAVA",
3
+ "messages" : {
4
+ "helloworld" : "你好世界",
5
+ "welcome": "%s,欢迎登录%s!"
6
+ },
7
+ "locale" : "zh-Hans"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "component" : "JAVA",
3
+ "messages" : {
4
+ "helloworld" : "你好,世界",
5
+ "welcome": "%s,歡迎登錄%s!"
6
+ },
7
+ "locale" : "zh-Hant"
8
+ }
@@ -1,9 +1,5 @@
1
1
  test: &default
2
2
 
3
- # Credentials for REST APIs
4
- client_id: tee
5
- client_secret: 89987
6
-
7
3
  # Mode can be 'live' or 'sandbox'
8
4
  mode: sandbox1
9
5
 
@@ -14,16 +10,16 @@ test: &default
14
10
  signature: sfds-RWy
15
11
  # # With Certificate
16
12
  # cert_path: "config/cert_key.pem"
17
- sandbox_email_address: linr@vmware.com
13
+ sandbox_email_address: linr@aa.com
18
14
 
19
15
  # #Product Name
20
- product_name: logInsight
16
+ product_name: test
21
17
 
22
18
  # # bundle version
23
19
  version: 4.8
24
20
 
25
21
  # # HTTP Proxy
26
- vip_server: https://g11n-vip-dev-1.eng.vmware.com:8090
22
+ vip_server: https://server:8090
27
23
 
28
24
  # # mode of bundle: online/offline
29
25
  bundle_mode: offline1www
@@ -1,9 +1,5 @@
1
1
  test: &default
2
2
 
3
- # Credentials for REST APIs
4
- client_id: tee
5
- client_secret: 89987
6
-
7
3
  # Mode can be 'live' or 'sandbox'
8
4
  mode: sandbox
9
5
 
@@ -14,16 +10,16 @@ test: &default
14
10
  signature: sfds-RWy
15
11
  # # With Certificate
16
12
  # cert_path: "config/cert_key.pem"
17
- sandbox_email_address: linr@vmware.com
13
+ sandbox_email_address: linr@aa.com
18
14
 
19
15
  # #Product Name
20
- product_name: logInsight
16
+ product_name: test
21
17
 
22
18
  # # bundle version
23
19
  version: 4.8.1
24
20
 
25
21
  # # HTTP Proxy
26
- vip_server: https://g11n-vip-dev-1.eng.vmware.com:8090
22
+ vip_server: https://server:8090
27
23
 
28
24
  # # mode of bundle: online/offline
29
25
  bundle_mode: offline
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'bundler/setup'
2
2
  require_relative '../lib/sgtn-client/sgtn-client.rb'
3
- require 'twitter_cldr'
3
+ require 'logger'
4
4
 
5
5
  if ENV['COVERAGE']
6
6
  require 'simplecov'
@@ -12,29 +12,22 @@ if ENV['COVERAGE']
12
12
  end
13
13
 
14
14
  Bundler.require :default, :test
15
- #SgtnClient.load("./spec/config/sgtnclient.yml", "test")
16
-
17
- #require 'SgtnClient'
18
15
 
19
16
  include SgtnClient
20
17
  include SgtnClient::Logging
21
18
  include SgtnClient::Exceptions
22
19
 
23
- require 'logger'
24
-
25
20
  SgtnClient.load("./spec/config/sgtnclient.yml", "test", './sgtnclient.log')
26
21
 
27
22
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
28
23
 
29
24
  # Set logger for http
30
25
  http_log = File.open(File.expand_path('../log/http.log', __FILE__), "w")
31
- #Payment.api.http.set_debug_output(http_log)
32
26
 
33
27
  RSpec.configure do |config|
34
28
  config.filter_run_excluding :integration => true
35
29
  config.filter_run_excluding :disabled => true
36
30
  config.include SampleData
37
- # config.include PayPal::SDK::REST::DataTypes
38
31
  end
39
32
 
40
33
  WebMock.allow_net_connect!
@@ -5,7 +5,7 @@ describe SgtnClient do
5
5
 
6
6
  before :each do
7
7
  env = SgtnClient::Config.default_environment
8
- SgtnClient::Config.configurations[env]["bundle_mode"] = 'online'
8
+ SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
9
9
  SgtnClient::Config.configurations[env]["cache_expiry_period"] = 1
10
10
  SgtnClient::Source.loadBundles("default")
11
11
  end
@@ -14,10 +14,10 @@ describe SgtnClient do
14
14
 
15
15
  # get translation from server
16
16
  SgtnClient.logger.debug "----------Start to get translation from server---------"
17
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
17
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
18
18
  # get translation from cache
19
19
  SgtnClient.logger.debug "----------Start to get translation from cache---------"
20
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
20
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
21
21
 
22
22
  # get from server again after data is expired
23
23
  SgtnClient.logger.debug "----------Sleep 70s---------"
@@ -25,7 +25,7 @@ describe SgtnClient do
25
25
  #sleep 70
26
26
  puts Time.now
27
27
  SgtnClient.logger.debug "----------Start to get translation from expired cache---------"
28
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
28
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
29
29
 
30
30
  SgtnClient.logger.debug "----------End to get translation from server---------"
31
31
  end
@@ -10,27 +10,43 @@ describe SgtnClient do
10
10
  end
11
11
 
12
12
  it "GET" do
13
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
13
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
14
14
  # get from cache in 2nd time
15
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
15
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
16
+
17
+ expect(SgtnClient::Translation.getString_f("JAVA", "welcome", ["机器人", "虚拟世界"], "zh-Hans")).to eq '机器人,欢迎登录虚拟世界!'
18
+ # get from cache in 2nd time
19
+ expect(SgtnClient::Translation.getString_f("JAVA", "welcome", ["机器人", "虚拟世界"], "zh-Hans")).to eq '机器人,欢迎登录虚拟世界!'
16
20
  end
17
21
 
18
22
  it "GET_EN" do
19
- expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
23
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello'
20
24
  # get from cache in 2nd time
21
- expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
25
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello'
22
26
  end
23
27
 
24
28
  it "GET_zh_CN" do
25
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-CN")).to eq '主机'
29
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-CN")).to eq '你好世界'
26
30
  # get from cache in 2nd time
27
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-CN")).to eq '主机'
31
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-CN")).to eq '你好世界'
28
32
  end
29
33
 
30
34
  it "NonExistingKey" do
31
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello world'
35
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
36
+ # get from cache in 2nd time
37
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
38
+
39
+ expect(SgtnClient::Translation.getString_f("JAVA", "login", ["Robot", "VM"], "zh-Hans")).to eq 'Robot login VM!'
40
+ # get from cache in 2nd time
41
+ expect(SgtnClient::Translation.getString_f("JAVA", "login", ["Robot", "VM"], "zh-Hans")).to eq 'Robot login VM!'
42
+ end
43
+
44
+ it "Component" do
45
+ jsonObj = SgtnClient::Translation.getStrings("JAVA", "zh-Hans");
46
+ expect(jsonObj["component"]).to eq 'JAVA'
32
47
  # get from cache in 2nd time
33
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello world'
48
+ jsonObj_c = SgtnClient::Translation.getStrings("JAVA", "zh-Hans");
49
+ expect(jsonObj_c["component"]).to eq 'JAVA'
34
50
  end
35
51
  end
36
52
 
@@ -6,26 +6,26 @@ describe SgtnClient do
6
6
  before :each do
7
7
  env = SgtnClient::Config.default_environment
8
8
  SgtnClient::CacheUtil.clear_cache()
9
- SgtnClient::Config.configurations[env]["bundle_mode"] = 'online'
9
+ SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
10
10
  SgtnClient::Source.loadBundles("default")
11
11
  end
12
12
 
13
13
  it "GET_EN" do
14
- expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
14
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "en")).to eq 'Hello world'
15
15
  # get from cache in 2nd time
16
- expect(SgtnClient::Translation.getString("JAVA", "hello", "en")).to eq 'Hello world'
16
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "en")).to eq 'Hello world'
17
17
  end
18
18
 
19
19
  it "GET" do
20
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
20
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
21
21
  # get from cache in 2nd time
22
- expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
22
+ expect(SgtnClient::Translation.getString("JAVA", "helloworld", "zh-Hans")).to eq '你好世界'
23
23
  end
24
24
 
25
25
  it "NonExistingKey" do
26
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello world'
26
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
27
27
  # get from cache in 2nd time
28
- expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello world'
28
+ expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello'
29
29
  end
30
30
  end
31
31
 
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'request_store'
3
+
4
+ describe SgtnClient do
5
+ describe "Locale" do
6
+
7
+ before :each do
8
+ env = SgtnClient::Config.default_environment
9
+ SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
10
+ SgtnClient::Source.loadBundles("default")
11
+ RequestStore.store[:locale] = 'zh-Hans'
12
+ RequestStore.store[:component] = 'JAVA'
13
+ end
14
+
15
+ it "GET" do
16
+ expect(SgtnClient::T.s("helloworld")).to eq '你好世界'
17
+ expect(SgtnClient::T.s_f("welcome", ["机器人", "虚拟世界"])).to eq '机器人,欢迎登录虚拟世界!'
18
+ expect(SgtnClient::T.c()["component"]).to eq 'JAVA'
19
+ end
20
+ end
21
+
22
+ end
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.0
4
+ version: 0.1.4
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-26 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: request_store
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: webmock
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -202,20 +216,6 @@ dependencies:
202
216
  - - "~>"
203
217
  - !ruby/object:Gem::Version
204
218
  version: '0.8'
205
- - !ruby/object:Gem::Dependency
206
- name: rest-client
207
- requirement: !ruby/object:Gem::Requirement
208
- requirements:
209
- - - "~>"
210
- - !ruby/object:Gem::Version
211
- version: '2.0'
212
- type: :runtime
213
- prerelease: false
214
- version_requirements: !ruby/object:Gem::Requirement
215
- requirements:
216
- - - "~>"
217
- - !ruby/object:Gem::Version
218
- version: '2.0'
219
219
  - !ruby/object:Gem::Dependency
220
220
  name: multi_json
221
221
  requirement: !ruby/object:Gem::Requirement
@@ -230,22 +230,8 @@ dependencies:
230
230
  - - "~>"
231
231
  - !ruby/object:Gem::Version
232
232
  version: '1.0'
233
- - !ruby/object:Gem::Dependency
234
- name: twitter_cldr
235
- requirement: !ruby/object:Gem::Requirement
236
- requirements:
237
- - - "~>"
238
- - !ruby/object:Gem::Version
239
- version: '6.6'
240
- type: :runtime
241
- prerelease: false
242
- version_requirements: !ruby/object:Gem::Requirement
243
- requirements:
244
- - - "~>"
245
- - !ruby/object:Gem::Version
246
- version: '6.6'
247
- description: A Singleton client for Ruby
248
- email: li@vmware.com
233
+ description: Singleton Ruby client
234
+ email: g11n-vip-project@vmware.com
249
235
  executables: []
250
236
  extensions: []
251
237
  extra_rdoc_files:
@@ -254,11 +240,8 @@ files:
254
240
  - Gemfile
255
241
  - README.md
256
242
  - Rakefile
257
- - lib/generators/sgtnclient/USAGE
258
- - lib/generators/sgtnclient/install_generator.rb
259
- - lib/generators/sgtnclient/templates/sgtnclient.rb
260
- - lib/generators/sgtnclient/templates/sgtnclient.yml
261
243
  - lib/sgtn-client/api/source.rb
244
+ - lib/sgtn-client/api/t.rb
262
245
  - lib/sgtn-client/api/translation.rb
263
246
  - lib/sgtn-client/core/cache.rb
264
247
  - lib/sgtn-client/core/config.rb
@@ -272,13 +255,13 @@ files:
272
255
  - lib/singleton-ruby.rb
273
256
  - lib/version.rb
274
257
  - spec/config/locales/default/JAVA/default.yml
275
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_de.json
276
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_en.json
277
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_latest.json
278
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hans.json
279
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hant.json
280
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/creation.json
281
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/version.json
258
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
259
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
260
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
261
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
262
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
263
+ - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
264
+ - spec/config/locales/l10n/bundles/test/4.8.1/version.json
282
265
  - spec/config/sample_data.yml
283
266
  - spec/config/sgtnclient-invalidate.yml
284
267
  - spec/config/sgtnclient.yml
@@ -292,10 +275,11 @@ files:
292
275
  - spec/unit/logging_spec.rb
293
276
  - spec/unit/offclient_spec.rb
294
277
  - spec/unit/onclient_spec.rb
278
+ - spec/unit/request_spec.rb
295
279
  - spec/unit/version_spec.rb
296
280
  homepage: https://github.com/vmware/singleton
297
281
  licenses:
298
- - MIT
282
+ - EPL
299
283
  metadata: {}
300
284
  post_install_message:
301
285
  rdoc_options: []
@@ -315,16 +299,16 @@ requirements: []
315
299
  rubygems_version: 3.0.9
316
300
  signing_key:
317
301
  specification_version: 4
318
- summary: Singleton client for Ruby.
302
+ summary: Singleton Ruby client
319
303
  test_files:
320
304
  - spec/config/locales/default/JAVA/default.yml
321
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_de.json
322
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_en.json
323
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_latest.json
324
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hans.json
325
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hant.json
326
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/creation.json
327
- - spec/config/locales/l10n/bundles/logInsight/4.8.1/version.json
305
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_de.json
306
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_en.json
307
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_latest.json
308
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hans.json
309
+ - spec/config/locales/l10n/bundles/test/4.8.1/JAVA/messages_zh-Hant.json
310
+ - spec/config/locales/l10n/bundles/test/4.8.1/creation.json
311
+ - spec/config/locales/l10n/bundles/test/4.8.1/version.json
328
312
  - spec/config/sample_data.yml
329
313
  - spec/config/sgtnclient-invalidate.yml
330
314
  - spec/config/sgtnclient.yml
@@ -338,4 +322,5 @@ test_files:
338
322
  - spec/unit/logging_spec.rb
339
323
  - spec/unit/offclient_spec.rb
340
324
  - spec/unit/onclient_spec.rb
325
+ - spec/unit/request_spec.rb
341
326
  - spec/unit/version_spec.rb
@@ -1,3 +0,0 @@
1
- To copy a PayPal SDK default configuration and initializer to your Rails App.
2
-
3
- rails g sgtnclient:install
@@ -1,15 +0,0 @@
1
- module SgtnClient
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
5
-
6
- def copy_config_file
7
- copy_file "sgtnclient.yml", "config/sgtnclient.yml"
8
- end
9
-
10
- def copy_initializer_file
11
- copy_file "sgtnclient.rb", "config/initializers/sgtnclient.rb"
12
- end
13
- end
14
- end
15
- end
@@ -1,2 +0,0 @@
1
- SgtnClient.load("config/sgtnclient.yml", Rails.env)
2
- PSgtnClient.logger = Rails.logger
@@ -1,33 +0,0 @@
1
- test: &default
2
-
3
- # Credentials for REST APIs
4
- client_id: tee
5
- client_secret: 89987
6
-
7
- # Mode can be 'live' or 'sandbox'
8
- mode: sandbox
9
-
10
- # Credentials for Classic APIs
11
- app_id: APP-80W284485P519543T
12
- username: linr
13
- password: fdasf
14
- signature: sfds-RWy
15
- # # With Certificate
16
- # cert_path: "config/cert_key.pem"
17
- sandbox_email_address: linr@vmware.com
18
-
19
- # #Product Name
20
- product_name: logInsight
21
-
22
- # # bundle version
23
- version: 4.8.1
24
-
25
- # # HTTP Proxy
26
- vip_server: https://g11n-vip-dev-1.eng.vmware.com:8090
27
-
28
- development:
29
- <<: *default
30
-
31
- production:
32
- <<: *default
33
- mode: live
@@ -1,11 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "com.vmware.loginsight.web.settings.stats.StatsTable.host" : "Host",
5
- "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond" : "Erfassungsrate für Ereignisse (pro Sekunde)",
6
- "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond.help" : "Die tatsächliche Erfassungsrate (Syslog + API) jedes Knotens nach der Nachrichtenneuverteilung.<br />Log Insight-Knoten verteilen Nachrichten neu, um eine gleichmäßige Erfassung pro Knoten zu erzielen und für eine ausgewogene Aufbewahrung und Leistung zu sorgen.<br /><br />Beachten Sie, dass die Erfassungsrate für jeden Knoten unter der konfigurierten maximalen Erfassungsrate eines Knotens liegen muss.<br /><br />Informationen zur tatsächlichen Rate der Ereignisse, die vor der Nachrichtenneuverteilung direkt an jeden Knoten gesandt werden, finden Sie in den Tabellen \"Eingangsrate für Syslog-Ereignisse (pro Sekunde)\" und \"Eingangsrate für API-Ereignisse (pro Sekunde)\" unten.",
7
- "com.vmware.loginsight.web.settings.stats.StatsTableType.syslogEventsIncomingRatePerSecond" : "Eingangsrate für Syslog-Ereignisse (pro Sekunde)",
8
- "com.vmware.loginsight.web.utilities.EmailUtil.upgrade.body48" : "Auf {0} wird nun Version {1} ausgeführt. Es folgen einige interessante neue Funktionen der Version {1}. Wir schätzen wie immer Ihre anhaltende Unterstützung und freuen uns auf Ihre Rückmeldungen unter {3} und {4} auf Twitter.<br /><br /><b>vRealize Log Insight-Serverfunktionen</b><br />• TODO weitere Serverfunktionen hinzufügen.<br /><br /><b>vRealize Log Insight-Agentenfunktionen</b><br />• TODO weitere Agentenfunktionen hinzufügen.<br /><br />Weitere Informationen zu den neuen Funktionen von {0} finden Sie unter {0} v{1} {2}.<br /><br />Viel Spaß bei der Protokollierung<br />Das {0}-Team<br /><br />"
9
- },
10
- "locale" : "de"
11
- }
@@ -1,12 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "hello": "Hello world",
5
- "com.vmware.loginsight.web.settings.stats.StatsTable.host" : "Host",
6
- "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond" : "Events Ingestion Rate (Per Second)",
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.",
8
- "com.vmware.loginsight.web.settings.stats.StatsTableType.syslogEventsIncomingRatePerSecond" : "Syslog Events Incoming Rate (Per Second)",
9
- "com.vmware.loginsight.web.actions.settings.HealthActionBean.machineLearningAliases" : "Machine Learning Aliases"
10
- },
11
- "locale" : "en"
12
- }
@@ -1,11 +0,0 @@
1
- {
2
- "component" : "JAVA",
3
- "messages" : {
4
- "com.vmware.loginsight.web.settings.stats.StatsTableType.queryOrigin" : "Query Origin",
5
- "com.vmware.loginsight.web.settings.stats.StatsTableType.queryOrigin.help" : "The origin refers to where the query originated from:<br /><br />Interactive Analytics<br />• <span style=\"font-weight: bold;\">Chart</span> - visualization above the search bar<br />• <span style=\"font-weight: bold;\">Events</span> - tab below the search bar<br />• <span style=\"font-weight: bold;\">Event Types</span> - tab below the search bar<br />• <span style=\"font-weight: bold;\">Event Trends</span> - tab below the search bar<br />• <span style=\"font-weight: bold;\">Alerts</span> - from the alert icon to the right of the search bar<br />• <span style=\"font-weight: bold;\">Facet</span> - chart when expanding a field<br /><br />Internal<br />• <span style=\"font-weight: bold;\">Precompute</span> - cache queries<br />• <span style=\"font-weight: bold;\">Schema</span>\t- machine learning queries<br />• <span style=\"font-weight: bold;\">Tools</span> - internal-only<br />• <span style=\"font-weight: bold;\">Other</span> - internal-only<br />",
6
- "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond" : "Events Ingestion Rate (Per Second)",
7
- "com.vmware.loginsight.web.settings.stats.StatsTable.host" : "Host",
8
- "com.vmware.loginsight.web.utilities.EmailUtil.upgrade.body48" : "{0} is now running version {1}. Below are some of the exciting new features we've added to the {1} release. As always, we appreciate your continued support and value your feedback in our {3} and {4} on Twitter.<br /><br /><b>vRealize Log Insight Server Features</b><br />• TODO add server features.<br /><br /><b>vRealize Log Insight Agent Features</b><br />• TODO add agent features.<br /><br />For more information about {0}'s new features, take a look at the {0} v{1} {2}.<br /><br />Happy Logging,<br />The {0} Team<br /><br \\>"
9
- },
10
- "locale" : "latest"
11
- }
@@ -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
- }
@@ -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-Hant"
11
- }