singleton-client-test 0.7.7.1 → 0.7.7.2
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 +4 -4
- data/lib/sgtn-client/api/source.rb +3 -1
- data/lib/sgtn-client/api/t.rb +0 -2
- data/lib/sgtn-client/api/translation.rb +9 -9
- data/lib/sgtn-client/core/cache.rb +2 -2
- data/lib/sgtn-client/core/config.rb +9 -4
- data/lib/sgtn-client/core/logging.rb +0 -1
- data/lib/sgtn-client/loader/cache.rb +13 -9
- data/lib/sgtn-client/loader/chain_loader.rb +1 -3
- data/lib/sgtn-client/loader/loader_factory.rb +9 -1
- data/lib/sgtn-client/loader/local_translation.rb +7 -2
- data/lib/sgtn-client/loader/server.rb +9 -4
- data/lib/sgtn-client/loader/single_loader.rb +6 -1
- data/lib/sgtn-client/loader/source.rb +8 -3
- data/lib/sgtn-client/loader/source_comparer.rb +5 -0
- data/lib/sgtn-client/sgtn-client.rb +21 -23
- data/lib/sgtn-client/util/cache-util.rb +12 -10
- data/lib/sgtn-client/util/locale-util.rb +5 -3
- data/lib/sgtn-client/util/validate-util.rb +6 -6
- data/lib/singleton-client.rb +6 -6
- data/lib/singleton-ruby.rb +3 -2
- metadata +6 -23
- data/lib/sgtn-client/common.rb +0 -10
- data/lib/sgtn-client/i18n_backend.rb +0 -46
- data/lib/sgtn-client/loader.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c13e66c93eebc3f8b17a1324c204f1fcc1312d49c92ae2f02ae65e422b96db18
|
4
|
+
data.tar.gz: a458454b4ce9c04927cf9d91055cc04c18d92fc7c5f678c8d97e0d81c7aaf000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 011675efc5fec02aaa3fc76accb53b2bbfeb93ab13c3e1c626ae2561c306b2dfe6a43d730d6ad3d1628e665375eb9d956ca92a0e5ec3edd991b69f8c162e74ce
|
7
|
+
data.tar.gz: 71c6364a6ab39df3234afa395db99ce1c55b817c7c70d6a88770224779c3cf1d94386ee767327dad89ded841e82195087288c66360f3988750031a2db163bcaa
|
@@ -4,10 +4,12 @@
|
|
4
4
|
require 'sgtn-client/loader/source'
|
5
5
|
|
6
6
|
module SgtnClient
|
7
|
+
autoload :CacheUtil, 'sgtn-client/util/cache-util'
|
8
|
+
|
7
9
|
class Source
|
8
10
|
def self.loadBundles(locale)
|
9
11
|
SgtnClient.logger.debug "[Source][loadBundles]locale=#{locale}"
|
10
|
-
Config.configurations.default = locale
|
12
|
+
SgtnClient::Config.configurations.default = locale
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/sgtn-client/api/t.rb
CHANGED
@@ -43,7 +43,7 @@ module SgtnClient
|
|
43
43
|
def translate(key, component, locale = nil, **kwargs)
|
44
44
|
SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] key: #{key}, component: #{component}, locale: #{locale}, args: #{kwargs}"
|
45
45
|
|
46
|
-
locale = locale.nil? ? self.locale : LocaleUtil.get_best_locale(locale)
|
46
|
+
locale = locale.nil? ? self.locale : SgtnClient::LocaleUtil.get_best_locale(locale)
|
47
47
|
|
48
48
|
result = get_bundle(component, locale)&.fetch(key, nil)
|
49
49
|
if result.nil? && !LocaleUtil.is_source_locale(locale)
|
@@ -61,7 +61,7 @@ module SgtnClient
|
|
61
61
|
if kwargs.empty?
|
62
62
|
result
|
63
63
|
else
|
64
|
-
locale = result.locale if result.is_a?(StringUtil)
|
64
|
+
locale = result.locale if result.is_a?(SgtnClient::StringUtil)
|
65
65
|
result.localize(locale) % kwargs
|
66
66
|
end
|
67
67
|
end
|
@@ -70,7 +70,7 @@ module SgtnClient
|
|
70
70
|
def get_translations(component, locale = nil)
|
71
71
|
SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] component: #{component}, locale: #{locale}"
|
72
72
|
|
73
|
-
locale = locale.nil? ? self.locale : LocaleUtil.get_best_locale(locale)
|
73
|
+
locale = locale.nil? ? self.locale : SgtnClient::LocaleUtil.get_best_locale(locale)
|
74
74
|
items = get_bundle(component, locale)
|
75
75
|
if items.nil? && !LocaleUtil.is_source_locale(locale)
|
76
76
|
items = get_bundle(component, LocaleUtil.get_source_locale)
|
@@ -81,11 +81,11 @@ module SgtnClient
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def locale
|
84
|
-
RequestStore.store[:locale] ||= LocaleUtil.get_fallback_locale
|
84
|
+
RequestStore.store[:locale] ||= SgtnClient::LocaleUtil.get_fallback_locale
|
85
85
|
end
|
86
86
|
|
87
87
|
def locale=(value)
|
88
|
-
RequestStore.store[:locale] = LocaleUtil.get_best_locale(value)
|
88
|
+
RequestStore.store[:locale] = SgtnClient::LocaleUtil.get_best_locale(value)
|
89
89
|
end
|
90
90
|
|
91
91
|
private
|
@@ -99,13 +99,13 @@ module SgtnClient
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def get_bundle!(component, locale)
|
102
|
-
id = Common::BundleID.new(component, locale)
|
103
|
-
bundles = Config.available_bundles
|
102
|
+
id = SgtnClient::Common::BundleID.new(component, locale)
|
103
|
+
bundles = SgtnClient::Config.available_bundles
|
104
104
|
unless bundles.nil? || bundles.empty? || bundles.include?(id)
|
105
|
-
raise SingletonError, 'bundle is unavailable.'
|
105
|
+
raise SgtnClient::SingletonError, 'bundle is unavailable.'
|
106
106
|
end
|
107
107
|
|
108
|
-
Config.loader.get_bundle(component, locale)
|
108
|
+
SgtnClient::Config.loader.get_bundle(component, locale)
|
109
109
|
end
|
110
110
|
end
|
111
111
|
extend Implementation
|
@@ -3,10 +3,15 @@
|
|
3
3
|
|
4
4
|
require 'erb'
|
5
5
|
require 'yaml'
|
6
|
-
require 'set'
|
7
6
|
require 'observer'
|
8
7
|
|
9
8
|
module SgtnClient
|
9
|
+
#include Exceptions
|
10
|
+
|
11
|
+
module TranslationLoader
|
12
|
+
autoload :LoaderFactory, 'sgtn-client/loader/loader_factory'
|
13
|
+
end
|
14
|
+
|
10
15
|
module Configuration
|
11
16
|
|
12
17
|
def config
|
@@ -125,7 +130,7 @@ module SgtnClient
|
|
125
130
|
if configurations[env]
|
126
131
|
@@config_cache[env] ||= new(configurations[env])
|
127
132
|
else
|
128
|
-
raise Exceptions::MissingConfig.new("Configuration[#{env}] NotFound")
|
133
|
+
raise SgtnClient::Exceptions::MissingConfig.new("Configuration[#{env}] NotFound")
|
129
134
|
end
|
130
135
|
end
|
131
136
|
|
@@ -157,8 +162,8 @@ module SgtnClient
|
|
157
162
|
|
158
163
|
def loader
|
159
164
|
@loader ||= begin
|
160
|
-
config = Config.configurations[Config.default_environment]
|
161
|
-
TranslationLoader::LoaderFactory.create(config)
|
165
|
+
config = SgtnClient::Config.configurations[SgtnClient::Config.default_environment]
|
166
|
+
SgtnClient::TranslationLoader::LoaderFactory.create(config)
|
162
167
|
end
|
163
168
|
end
|
164
169
|
|
@@ -4,16 +4,20 @@
|
|
4
4
|
# SPDX-License-Identifier: EPL-2.0
|
5
5
|
|
6
6
|
module SgtnClient
|
7
|
+
autoload :CacheUtil, 'sgtn-client/util/cache-util'
|
8
|
+
|
7
9
|
module TranslationLoader
|
10
|
+
autoload :CONSTS, 'sgtn-client/loader/consts'
|
11
|
+
|
8
12
|
module Cache # :nodoc:
|
9
13
|
# get from cache, return expired data immediately
|
10
14
|
def get_bundle(component, locale)
|
11
15
|
SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
|
12
16
|
|
13
|
-
key = CacheUtil.get_cachekey(component, locale)
|
14
|
-
cache_item = CacheUtil.get_cache(key)
|
17
|
+
key = SgtnClient::CacheUtil.get_cachekey(component, locale)
|
18
|
+
cache_item = SgtnClient::CacheUtil.get_cache(key)
|
15
19
|
if cache_item
|
16
|
-
if CacheUtil.is_expired(cache_item)
|
20
|
+
if SgtnClient::CacheUtil.is_expired(cache_item)
|
17
21
|
Thread.new do # TODO: Use one thread # refresh in background
|
18
22
|
begin
|
19
23
|
load_bundle(component, locale)
|
@@ -33,22 +37,22 @@ module SgtnClient
|
|
33
37
|
def load_bundle(component, locale)
|
34
38
|
SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
|
35
39
|
|
36
|
-
key = CacheUtil.get_cachekey(component, locale)
|
40
|
+
key = SgtnClient::CacheUtil.get_cachekey(component, locale)
|
37
41
|
item = super
|
38
|
-
CacheUtil.write_cache(key, item) if item
|
42
|
+
SgtnClient::CacheUtil.write_cache(key, item) if item
|
39
43
|
item
|
40
44
|
end
|
41
45
|
|
42
46
|
def available_bundles
|
43
47
|
SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}]"
|
44
48
|
|
45
|
-
cache_item = CacheUtil.get_cache(CONSTS::AVAILABLE_BUNDLES_KEY)
|
49
|
+
cache_item = SgtnClient::CacheUtil.get_cache(CONSTS::AVAILABLE_BUNDLES_KEY)
|
46
50
|
if cache_item
|
47
|
-
if CacheUtil.is_expired(cache_item)
|
51
|
+
if SgtnClient::CacheUtil.is_expired(cache_item)
|
48
52
|
Thread.new do # TODO: Use one thread
|
49
53
|
begin
|
50
54
|
item = super
|
51
|
-
CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
|
55
|
+
SgtnClient::CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
|
52
56
|
rescue StandardError => e
|
53
57
|
SgtnClient.logger.error 'an error occured while loading available bundles.'
|
54
58
|
SgtnClient.logger.error e
|
@@ -59,7 +63,7 @@ module SgtnClient
|
|
59
63
|
end
|
60
64
|
|
61
65
|
item = super
|
62
|
-
CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
|
66
|
+
SgtnClient::CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
|
63
67
|
item
|
64
68
|
end
|
65
69
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# Copyright 2022 VMware, Inc.
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
|
-
require 'set'
|
5
|
-
|
6
4
|
module SgtnClient
|
7
5
|
module TranslationLoader
|
8
6
|
class Chain
|
@@ -25,7 +23,7 @@ module SgtnClient
|
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
|
-
raise exception || SingletonError.new("can't load component: #{component}, locale: #{locale}")
|
26
|
+
raise exception || SgtnClient::SingletonError.new("can't load component: #{component}, locale: #{locale}")
|
29
27
|
end
|
30
28
|
|
31
29
|
def available_bundles
|
@@ -3,6 +3,14 @@
|
|
3
3
|
|
4
4
|
module SgtnClient
|
5
5
|
module TranslationLoader
|
6
|
+
autoload :Source, 'sgtn-client/loader/source'
|
7
|
+
autoload :SgtnServer, 'sgtn-client/loader/server'
|
8
|
+
autoload :LocalTranslation, 'sgtn-client/loader/local_translation'
|
9
|
+
autoload :Chain, 'sgtn-client/loader/chain_loader'
|
10
|
+
autoload :SourceComparer, 'sgtn-client/loader/source_comparer'
|
11
|
+
autoload :SingleLoader, 'sgtn-client/loader/single_loader'
|
12
|
+
autoload :Cache, 'sgtn-client/loader/cache'
|
13
|
+
|
6
14
|
module LoaderFactory
|
7
15
|
def self.create(config)
|
8
16
|
SgtnClient.logger.info "[#{method(__callee__).owner}.#{__callee__}] config=#{config}"
|
@@ -11,7 +19,7 @@ module SgtnClient
|
|
11
19
|
loaders << Source.new(config) if config['source_bundle']
|
12
20
|
loaders << SgtnServer.new(config) if config['vip_server']
|
13
21
|
loaders << LocalTranslation.new(config) if config['translation_bundle']
|
14
|
-
raise SingletonError, 'no translation is available!' if loaders.empty?
|
22
|
+
raise SgtnClient::SingletonError, 'no translation is available!' if loaders.empty?
|
15
23
|
|
16
24
|
chain_loader = Class.new(Chain)
|
17
25
|
chain_loader.include SourceComparer
|
@@ -3,10 +3,15 @@
|
|
3
3
|
|
4
4
|
require 'json'
|
5
5
|
require 'pathname'
|
6
|
-
require 'set'
|
7
6
|
|
8
7
|
module SgtnClient
|
8
|
+
module Common
|
9
|
+
autoload :BundleID, 'sgtn-client/common/data'
|
10
|
+
end
|
11
|
+
|
9
12
|
module TranslationLoader
|
13
|
+
autoload :CONSTS, 'sgtn-client/loader/consts'
|
14
|
+
|
10
15
|
class LocalTranslation
|
11
16
|
BUNDLE_PREFIX = 'messages_'.freeze
|
12
17
|
BUNDLE_SUFFIX = '.json'.freeze
|
@@ -24,7 +29,7 @@ module SgtnClient
|
|
24
29
|
bundle_data = JSON.parse(File.read(file_path))
|
25
30
|
messages = bundle_data['messages']
|
26
31
|
|
27
|
-
raise SingletonError, "no messages in local bundle file: #{file_path}." unless messages
|
32
|
+
raise SgtnClient::SingletonError, "no messages in local bundle file: #{file_path}." unless messages
|
28
33
|
|
29
34
|
messages
|
30
35
|
end
|
@@ -5,10 +5,15 @@
|
|
5
5
|
|
6
6
|
require 'faraday'
|
7
7
|
require 'faraday_middleware'
|
8
|
-
require 'set'
|
9
8
|
|
10
9
|
module SgtnClient
|
10
|
+
module Common
|
11
|
+
autoload :BundleID, 'sgtn-client/common/data'
|
12
|
+
end
|
13
|
+
|
11
14
|
module TranslationLoader
|
15
|
+
autoload :CONSTS, 'sgtn-client/loader/consts'
|
16
|
+
|
12
17
|
class SgtnServer
|
13
18
|
ERROR_ILLEGAL_DATA = 'server returned illegal data.'
|
14
19
|
ERROR_BUSINESS_ERROR = 'server returned business error.'
|
@@ -68,7 +73,7 @@ module SgtnClient
|
|
68
73
|
|
69
74
|
def extract_data(parsedbody, path_to_data)
|
70
75
|
data = parsedbody.dig('data', *path_to_data)
|
71
|
-
raise SingletonError, "no expected data in response. Body is: #{parsedbody}" unless data
|
76
|
+
raise SgtnClient::SingletonError, "no expected data in response. Body is: #{parsedbody}" unless data
|
72
77
|
|
73
78
|
data
|
74
79
|
end
|
@@ -76,13 +81,13 @@ module SgtnClient
|
|
76
81
|
def process_business_error(parsedbody)
|
77
82
|
b_code = parsedbody.dig('response', 'code')
|
78
83
|
unless b_code >= 200 && b_code < 300 || b_code >= 600 && b_code < 700
|
79
|
-
raise SingletonError, "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}"
|
84
|
+
raise SgtnClient::SingletonError, "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}"
|
80
85
|
end
|
81
86
|
|
82
87
|
# 600 means a successful response, 6xx means partial successful.
|
83
88
|
SgtnClient.logger.warn "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}" if b_code > 600
|
84
89
|
rescue TypeError, ArgumentError, NoMethodError => e
|
85
|
-
raise SingletonError, "#{ERROR_ILLEGAL_DATA} #{e}. Body is: #{parsedbody}"
|
90
|
+
raise SgtnClient::SingletonError, "#{ERROR_ILLEGAL_DATA} #{e}. Body is: #{parsedbody}"
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
@@ -2,7 +2,12 @@
|
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
4
|
module SgtnClient
|
5
|
+
autoload :SingleOperation, 'sgtn-client/common/single_operation'
|
6
|
+
autoload :CacheUtil, 'sgtn-client/util/cache-util'
|
7
|
+
|
5
8
|
module TranslationLoader
|
9
|
+
autoload :CONSTS, 'sgtn-client/loader/consts'
|
10
|
+
|
6
11
|
module SingleLoader
|
7
12
|
def load_bundle(component, locale)
|
8
13
|
SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
|
@@ -36,7 +41,7 @@ module SgtnClient
|
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
|
-
loader = SingleOperation.new(none_alive, &creator)
|
44
|
+
loader = SgtnClient::SingleOperation.new(none_alive, &creator)
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
@@ -2,11 +2,16 @@
|
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
4
|
require 'pathname'
|
5
|
-
require 'set'
|
6
5
|
require 'yaml'
|
7
6
|
|
8
7
|
module SgtnClient
|
8
|
+
module Common
|
9
|
+
autoload :BundleID, 'sgtn-client/common/data'
|
10
|
+
end
|
11
|
+
|
9
12
|
module TranslationLoader
|
13
|
+
autoload :CONSTS, 'sgtn-client/loader/consts'
|
14
|
+
|
10
15
|
class Source
|
11
16
|
def initialize(config)
|
12
17
|
@source_bundle_path = Pathname.new(config['source_bundle'])
|
@@ -29,7 +34,7 @@ module SgtnClient
|
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
|
-
raise SingletonError, "no local source messages for component #{component}" if total_messages.empty?
|
37
|
+
raise SgtnClient::SingletonError, "no local source messages for component #{component}" if total_messages.empty?
|
33
38
|
|
34
39
|
total_messages
|
35
40
|
end
|
@@ -40,7 +45,7 @@ module SgtnClient
|
|
40
45
|
@available_bundles ||= begin
|
41
46
|
@source_bundle_path.children.select(&:directory?).reduce(Set.new) do |bundles, component|
|
42
47
|
component.glob('**/*.{yml, yaml}') do |_|
|
43
|
-
bundles << Common::BundleID.new(component.basename.to_s, LocaleUtil.get_source_locale)
|
48
|
+
bundles << Common::BundleID.new(component.basename.to_s, SgtnClient::LocaleUtil.get_source_locale)
|
44
49
|
break bundles
|
45
50
|
end || bundles
|
46
51
|
end
|
@@ -2,7 +2,12 @@
|
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
4
|
module SgtnClient
|
5
|
+
autoload :StringUtil, 'sgtn-client/util/string-util'
|
6
|
+
autoload :LocaleUtil, 'sgtn-client/util/locale-util'
|
7
|
+
|
5
8
|
module TranslationLoader
|
9
|
+
autoload :CONSTS, 'sgtn-client/loader/consts'
|
10
|
+
|
6
11
|
module SourceComparer
|
7
12
|
def load_bundle(component, locale)
|
8
13
|
SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
|
@@ -4,10 +4,9 @@
|
|
4
4
|
module SgtnClient
|
5
5
|
LOGFILE_SHIFT_AGE = 4
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
module Common
|
8
|
+
autoload :BundleID, "sgtn-client/common/data"
|
9
|
+
end
|
11
10
|
module Core
|
12
11
|
autoload :Cache, "sgtn-client/core/cache"
|
13
12
|
end
|
@@ -20,10 +19,9 @@ module SgtnClient
|
|
20
19
|
autoload :Exceptions, "sgtn-client/core/exceptions"
|
21
20
|
autoload :ValidateUtil, "sgtn-client/util/validate-util"
|
22
21
|
autoload :LocaleUtil, "sgtn-client/util/locale-util"
|
22
|
+
autoload :FileUtil, "sgtn-client/util/file-util"
|
23
23
|
autoload :CacheUtil, "sgtn-client/util/cache-util"
|
24
|
-
autoload :StringUtil,
|
25
|
-
autoload :SingletonError, 'sgtn-client/exceptions'
|
26
|
-
autoload :I18nBackend, "sgtn-client/i18n_backend"
|
24
|
+
autoload :StringUtil, "sgtn-client/util/string-util"
|
27
25
|
|
28
26
|
module Formatters
|
29
27
|
autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
|
@@ -32,15 +30,15 @@ module SgtnClient
|
|
32
30
|
|
33
31
|
class << self
|
34
32
|
def configure(options = {}, &block)
|
35
|
-
Config.configure(options, &block)
|
33
|
+
SgtnClient::Config.configure(options, &block)
|
36
34
|
end
|
37
35
|
|
38
36
|
include Logging
|
39
37
|
def load(*args)
|
40
38
|
# load configuration file
|
41
39
|
begin
|
42
|
-
Config.load(args[0], args[1])
|
43
|
-
ValidateUtil.validate_config()
|
40
|
+
SgtnClient::Config.load(args[0], args[1])
|
41
|
+
SgtnClient::ValidateUtil.validate_config()
|
44
42
|
rescue => exception
|
45
43
|
file = File.open('./error.log', 'a')
|
46
44
|
file.sync = true
|
@@ -50,40 +48,40 @@ module SgtnClient
|
|
50
48
|
|
51
49
|
# create log file
|
52
50
|
file = './sgtnclient_d.log'
|
53
|
-
logger.debug "[Client][load]create log file=#{file}"
|
51
|
+
SgtnClient.logger.debug "[Client][load]create log file=#{file}"
|
54
52
|
if args[2] != nil
|
55
53
|
file = args[2]
|
56
54
|
end
|
57
55
|
file = File.open(file, 'a')
|
58
56
|
file.sync = true
|
59
|
-
logger = Logger.new(file, LOGFILE_SHIFT_AGE)
|
57
|
+
SgtnClient.logger = Logger.new(file, LOGFILE_SHIFT_AGE)
|
60
58
|
|
61
59
|
# Set log level for sandbox mode
|
62
|
-
env = Config.default_environment
|
63
|
-
mode = Config.configurations[env]["mode"]
|
64
|
-
logger.debug "[Client][load]set log level, mode=#{mode}"
|
60
|
+
env = SgtnClient::Config.default_environment
|
61
|
+
mode = SgtnClient::Config.configurations[env]["mode"]
|
62
|
+
SgtnClient.logger.debug "[Client][load]set log level, mode=#{mode}"
|
65
63
|
if mode == 'sandbox'
|
66
|
-
logger.level = Logger::DEBUG
|
64
|
+
SgtnClient.logger.level = Logger::DEBUG
|
67
65
|
else
|
68
|
-
logger.level = Logger::INFO
|
66
|
+
SgtnClient.logger.level = Logger::INFO
|
69
67
|
end
|
70
68
|
|
71
69
|
# initialize cache
|
72
|
-
disable_cache = Config.configurations[env]["disable_cache"]
|
73
|
-
logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
|
70
|
+
disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
|
71
|
+
SgtnClient.logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
|
74
72
|
if disable_cache != nil
|
75
|
-
Core::Cache.initialize(disable_cache)
|
73
|
+
SgtnClient::Core::Cache.initialize(disable_cache)
|
76
74
|
else
|
77
|
-
Core::Cache.initialize()
|
75
|
+
SgtnClient::Core::Cache.initialize()
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
79
|
def logger
|
82
|
-
Config.logger
|
80
|
+
SgtnClient::Config.logger
|
83
81
|
end
|
84
82
|
|
85
83
|
def logger=(log)
|
86
|
-
Config.logger = log
|
84
|
+
SgtnClient::Config.logger = log
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
@@ -1,32 +1,34 @@
|
|
1
1
|
# Copyright 2022 VMware, Inc.
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
|
-
require 'time'
|
5
|
-
|
6
4
|
module SgtnClient
|
5
|
+
module Core
|
6
|
+
autoload :Cache, 'sgtn-client/core/cache'
|
7
|
+
end
|
8
|
+
|
7
9
|
class CacheUtil
|
8
10
|
def self.get_cache(cache_key)
|
9
|
-
Core::Cache.get(cache_key)
|
11
|
+
SgtnClient::Core::Cache.get(cache_key)
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.clear_cache
|
13
|
-
Core::Cache.clear
|
15
|
+
SgtnClient::Core::Cache.clear
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.write_cache(cache_key, items)
|
17
19
|
return nil if items.nil? || items.empty?
|
18
20
|
|
19
|
-
env = Config.default_environment
|
20
|
-
cache_expiry_period = Config.configurations[env]['cache_expiry_period']
|
21
|
+
env = SgtnClient::Config.default_environment
|
22
|
+
cache_expiry_period = SgtnClient::Config.configurations[env]['cache_expiry_period']
|
21
23
|
# expired after 24 hours
|
22
24
|
cache_expiry_period = 24 * 60 if cache_expiry_period.nil?
|
23
|
-
Core::Cache.put(cache_key, items, cache_expiry_period)
|
25
|
+
SgtnClient::Core::Cache.put(cache_key, items, cache_expiry_period)
|
24
26
|
end
|
25
27
|
|
26
28
|
def self.get_cachekey(component, locale)
|
27
|
-
env = Config.default_environment
|
28
|
-
product_name = Config.configurations[env]['product_name']
|
29
|
-
version = Config.configurations[env]['version'].to_s
|
29
|
+
env = SgtnClient::Config.default_environment
|
30
|
+
product_name = SgtnClient::Config.configurations[env]['product_name']
|
31
|
+
version = SgtnClient::Config.configurations[env]['version'].to_s
|
30
32
|
product_name + '_' + version + '_' + component + '_' + locale
|
31
33
|
end
|
32
34
|
|
@@ -3,6 +3,8 @@
|
|
3
3
|
# Copyright 2022 VMware, Inc.
|
4
4
|
# SPDX-License-Identifier: EPL-2.0
|
5
5
|
|
6
|
+
require 'set'
|
7
|
+
|
6
8
|
module SgtnClient
|
7
9
|
class LocaleUtil
|
8
10
|
MAP_LOCALES = {
|
@@ -43,8 +45,8 @@ module SgtnClient
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def self.get_default_locale
|
46
|
-
env = Config.default_environment
|
47
|
-
Config.configurations[env]['default_language']
|
48
|
+
env = SgtnClient::Config.default_environment
|
49
|
+
SgtnClient::Config.configurations[env]['default_language']
|
48
50
|
end
|
49
51
|
|
50
52
|
def self.get_fallback_locale
|
@@ -61,7 +63,7 @@ module SgtnClient
|
|
61
63
|
@lowercase_locales_map = nil if type == :available_locales
|
62
64
|
end
|
63
65
|
|
64
|
-
Config.add_observer(self, :reset_available_locales)
|
66
|
+
SgtnClient::Config.add_observer(self, :reset_available_locales)
|
65
67
|
|
66
68
|
private_class_method :get_best_match, :lowercase_locales_map, :reset_available_locales
|
67
69
|
end
|
@@ -6,32 +6,32 @@ module SgtnClient
|
|
6
6
|
class ValidateUtil
|
7
7
|
|
8
8
|
def self.validate_config()
|
9
|
-
env = Config.default_environment
|
9
|
+
env = SgtnClient::Config.default_environment
|
10
10
|
SgtnClient.logger.debug "[ValidateUtil][validate_config] env = #{env}"
|
11
11
|
messages = "\n"
|
12
12
|
|
13
|
-
mode = Config.configurations[env]["mode"]
|
13
|
+
mode = SgtnClient::Config.configurations[env]["mode"]
|
14
14
|
if mode != 'sandbox' && mode != 'live'
|
15
15
|
messages = messages + "Configuration[mode] has to be 'sandbox' or 'live'!\n"
|
16
16
|
end
|
17
17
|
|
18
|
-
#version = Config.configurations[env]["version"]
|
18
|
+
#version = SgtnClient::Config.configurations[env]["version"]
|
19
19
|
#if version.is_a? Integer
|
20
20
|
#messages = messages + "Configuration[version] has to be standard as '#.#.#, e.g '1.0.0'!\n"
|
21
21
|
#end
|
22
22
|
|
23
|
-
cache_expiry_period = Config.configurations[env]["cache_expiry_period"]
|
23
|
+
cache_expiry_period = SgtnClient::Config.configurations[env]["cache_expiry_period"]
|
24
24
|
if cache_expiry_period != nil && (cache_expiry_period.is_a? Integer) == false
|
25
25
|
messages = messages + "Configuration[cache_expiry_period] has to be a number!\n"
|
26
26
|
end
|
27
27
|
|
28
|
-
disable_cache = Config.configurations[env]["disable_cache"]
|
28
|
+
disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
|
29
29
|
if disable_cache != nil && disable_cache != false && disable_cache != true
|
30
30
|
messages = messages + "Configuration[disable_cache] has to be a 'true' or 'false'!\n"
|
31
31
|
end
|
32
32
|
|
33
33
|
if messages != "\n"
|
34
|
-
raise Exceptions::MissingConfig.new(messages)
|
34
|
+
raise SgtnClient::Exceptions::MissingConfig.new(messages)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/lib/singleton-client.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Copyright 2022 VMware, Inc.
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
|
-
require 'forwardable'
|
5
4
|
require_relative 'singleton-ruby'
|
6
5
|
|
7
6
|
module Sgtn # :nodoc:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def_delegators SgtnClient::Translation, :translate, :t, :get_translations, :locale, :locale=
|
7
|
+
# load configuration from a file
|
8
|
+
def self.load_config(*args)
|
9
|
+
SgtnClient.load(*args)
|
12
10
|
end
|
13
11
|
|
14
|
-
|
12
|
+
extend SgtnClient::Translation::Implementation
|
13
|
+
|
14
|
+
private_class_method :getString, :getString_p, :getString_f, :getStrings
|
15
15
|
end
|
data/lib/singleton-ruby.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Copyright 2022 VMware, Inc.
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
|
-
require
|
4
|
+
require "sgtn-client/sgtn-client"
|
5
5
|
require 'sgtn-client/cldr/core_ext'
|
6
|
+
require 'twitter_cldr'
|
6
7
|
|
7
|
-
require 'sgtn-client/
|
8
|
+
require 'sgtn-client/exceptions.rb'
|
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.7.
|
4
|
+
version: 0.7.7.2
|
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-
|
11
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -48,16 +48,16 @@ dependencies:
|
|
48
48
|
name: rubocop
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
53
|
+
version: '0.49'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
60
|
+
version: '0.49'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: webmock
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,20 +142,6 @@ dependencies:
|
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '6.6'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: i18n
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - ">="
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '0'
|
152
|
-
type: :runtime
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - ">="
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: '0'
|
159
145
|
description: Singleton Ruby client
|
160
146
|
email: g11n-vip-project@vmware.com
|
161
147
|
executables: []
|
@@ -172,7 +158,6 @@ files:
|
|
172
158
|
- lib/sgtn-client/cldr/localized_datetime.rb
|
173
159
|
- lib/sgtn-client/cldr/localized_str.rb
|
174
160
|
- lib/sgtn-client/cldr/localized_time.rb
|
175
|
-
- lib/sgtn-client/common.rb
|
176
161
|
- lib/sgtn-client/common/data.rb
|
177
162
|
- lib/sgtn-client/common/single_operation.rb
|
178
163
|
- lib/sgtn-client/core/cache.rb
|
@@ -181,8 +166,6 @@ files:
|
|
181
166
|
- lib/sgtn-client/core/logging.rb
|
182
167
|
- lib/sgtn-client/exceptions.rb
|
183
168
|
- lib/sgtn-client/formatters/plurals/plural_formatter.rb
|
184
|
-
- lib/sgtn-client/i18n_backend.rb
|
185
|
-
- lib/sgtn-client/loader.rb
|
186
169
|
- lib/sgtn-client/loader/cache.rb
|
187
170
|
- lib/sgtn-client/loader/chain_loader.rb
|
188
171
|
- lib/sgtn-client/loader/consts.rb
|
data/lib/sgtn-client/common.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# Copyright 2022 VMware, Inc.
|
2
|
-
# SPDX-License-Identifier: EPL-2.0
|
3
|
-
|
4
|
-
require 'i18n'
|
5
|
-
|
6
|
-
module SgtnClient # :nodoc:
|
7
|
-
# When integrating Singleton in a client application that is already using [I18n::Backend (https://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/), it would be useful to have Singleton override the said module in order to minimize necessary changes. Here is a common usage:
|
8
|
-
#
|
9
|
-
# I18n::Backend::Simple.include(I18n::Backend::Fallbacks) # add fallbacks behavior to current backend
|
10
|
-
# I18n.backend = I18n::Backend::Chain.new(Sgtn::I18nBackend.new(component_name), I18n.backend)
|
11
|
-
# I18n.enforce_available_locales=false # disable available locales check
|
12
|
-
# I18n.default_locale = :en
|
13
|
-
class I18nBackend
|
14
|
-
def initialize(component)
|
15
|
-
@component = component
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialized?
|
19
|
-
@initialized = true
|
20
|
-
end
|
21
|
-
|
22
|
-
def load_translations(*) end
|
23
|
-
|
24
|
-
def store_translations(*) end
|
25
|
-
|
26
|
-
def available_locales
|
27
|
-
SgtnClient::Config.available_locales.to_a
|
28
|
-
end
|
29
|
-
|
30
|
-
def reload!; end
|
31
|
-
|
32
|
-
def eager_load!; end
|
33
|
-
|
34
|
-
def translations; end
|
35
|
-
|
36
|
-
def exists?(locale, key)
|
37
|
-
!!(translate(locale, key) { nil })
|
38
|
-
end
|
39
|
-
|
40
|
-
def translate(locale, key, options)
|
41
|
-
flat_key = I18n::Backend::Flatten.normalize_flat_keys(locale, key, options[:scope], '.')
|
42
|
-
values = options.except(*I18n::RESERVED_KEYS)
|
43
|
-
SgtnClient::Translation.translate(flat_key, @component, locale, **values) { nil }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/lib/sgtn-client/loader.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2022 VMware, Inc.
|
4
|
-
# SPDX-License-Identifier: EPL-2.0
|
5
|
-
|
6
|
-
module SgtnClient
|
7
|
-
module TranslationLoader # :nodoc:
|
8
|
-
autoload :Cache, 'sgtn-client/loader/cache'
|
9
|
-
autoload :Chain, 'sgtn-client/loader/chain_loader'
|
10
|
-
autoload :CONSTS, 'sgtn-client/loader/consts'
|
11
|
-
autoload :LoaderFactory, 'sgtn-client/loader/loader_factory'
|
12
|
-
autoload :LocalTranslation, 'sgtn-client/loader/local_translation'
|
13
|
-
autoload :SgtnServer, 'sgtn-client/loader/server'
|
14
|
-
autoload :SingleLoader, 'sgtn-client/loader/single_loader'
|
15
|
-
autoload :SourceComparer, 'sgtn-client/loader/source_comparer'
|
16
|
-
autoload :Source, 'sgtn-client/loader/source'
|
17
|
-
end
|
18
|
-
end
|