singleton-client-test 0.7.0.31 → 0.7.0.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sgtn-client/api/source.rb +10 -66
  3. data/lib/sgtn-client/api/t.rb +20 -18
  4. data/lib/sgtn-client/api/translation.rb +82 -117
  5. data/lib/sgtn-client/cldr/core_ext.rb +4 -1
  6. data/lib/sgtn-client/cldr/localized_date.rb +4 -1
  7. data/lib/sgtn-client/cldr/localized_datetime.rb +4 -1
  8. data/lib/sgtn-client/cldr/localized_str.rb +3 -1
  9. data/lib/sgtn-client/cldr/localized_time.rb +4 -1
  10. data/lib/sgtn-client/common/data.rb +30 -0
  11. data/lib/sgtn-client/common/single_operation.rb +34 -0
  12. data/lib/sgtn-client/core/cache.rb +14 -80
  13. data/lib/sgtn-client/core/config.rb +39 -3
  14. data/lib/sgtn-client/core/exceptions.rb +3 -0
  15. data/lib/sgtn-client/core/logging.rb +3 -1
  16. data/lib/sgtn-client/exceptions.rb +6 -0
  17. data/lib/sgtn-client/formatters/plurals/plural_formatter.rb +4 -1
  18. data/lib/sgtn-client/loader/cache.rb +71 -0
  19. data/lib/sgtn-client/loader/chain_loader.rb +49 -0
  20. data/lib/sgtn-client/loader/consts.rb +15 -0
  21. data/lib/sgtn-client/loader/loader_factory.rb +33 -0
  22. data/lib/sgtn-client/loader/local_translation.rb +50 -0
  23. data/lib/sgtn-client/loader/server.rb +94 -0
  24. data/lib/sgtn-client/loader/single_loader.rb +46 -0
  25. data/lib/sgtn-client/loader/source.rb +53 -0
  26. data/lib/sgtn-client/loader/source_comparer.rb +58 -0
  27. data/lib/sgtn-client/sgtn-client.rb +7 -1
  28. data/lib/sgtn-client/util/cache-util.rb +33 -44
  29. data/lib/sgtn-client/util/locale-util.rb +48 -31
  30. data/lib/sgtn-client/util/string-util.rb +12 -0
  31. data/lib/sgtn-client/util/validate-util.rb +4 -7
  32. data/lib/singleton-client.rb +15 -0
  33. data/lib/singleton-ruby.rb +5 -0
  34. data/lib/version.rb +2 -0
  35. metadata +43 -147
  36. data/lib/sgtn-client/core/request.rb +0 -21
  37. data/lib/sgtn-client/util/file-util.rb +0 -34
@@ -1,8 +1,17 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
1
4
  require 'erb'
2
5
  require 'yaml'
3
6
 
7
+
4
8
  module SgtnClient
5
9
  #include Exceptions
10
+
11
+ module TranslationLoader
12
+ autoload :LoaderFactory, 'sgtn-client/loader/loader_factory'
13
+ end
14
+
6
15
  module Configuration
7
16
 
8
17
  def config
@@ -39,7 +48,7 @@ module SgtnClient
39
48
  :mode, :endpoint, :merchant_endpoint, :platform_endpoint, :ipn_endpoint,
40
49
  :rest_endpoint, :rest_token_endpoint, :client_id, :client_secret,
41
50
  :openid_endpoint, :openid_redirect_uri, :openid_client_id, :openid_client_secret,
42
- :verbose_logging, :product_name, :version, :vip_server, :bundle_mode,
51
+ :verbose_logging, :product_name, :version, :vip_server,
43
52
  :translation_bundle, :source_bundle, :cache_expiry_period, :disable_cache, :default_language
44
53
 
45
54
 
@@ -149,6 +158,34 @@ module SgtnClient
149
158
  Logging.logger
150
159
  end
151
160
 
161
+
162
+ def loader
163
+ @loader ||= begin
164
+ config = SgtnClient::Config.configurations[SgtnClient::Config.default_environment]
165
+ SgtnClient::TranslationLoader::LoaderFactory.create(config)
166
+ end
167
+ end
168
+
169
+ def available_bundles
170
+ loader.available_bundles
171
+ rescue StandardError => e
172
+ SgtnClient.logger.error 'failed to get available bundles'
173
+ SgtnClient.logger.error e
174
+ Set.new
175
+ end
176
+
177
+ def available_locales
178
+ bundles = available_bundles
179
+ return Set.new if bundles.nil? || bundles.empty?
180
+
181
+ unless bundles.respond_to?(:locales)
182
+ def bundles.locales
183
+ @locales ||= reduce(Set.new) { |locales, id| locales << id.locale }
184
+ end
185
+ end
186
+ bundles.locales
187
+ end
188
+
152
189
  private
153
190
  # Read configurations from the given file name
154
191
  # === Arguments
@@ -158,9 +195,8 @@ module SgtnClient
158
195
  erb.filename = file_name
159
196
  YAML.load(erb.result)
160
197
  end
161
-
162
198
 
163
199
  end
164
200
  end
165
201
 
166
- end
202
+ 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
-
@@ -0,0 +1,6 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
5
+ class SingletonError < StandardError; end
6
+ 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
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 VMware, Inc.
4
+ # SPDX-License-Identifier: EPL-2.0
5
+
6
+ module SgtnClient
7
+ autoload :CacheUtil, 'sgtn-client/util/cache-util'
8
+
9
+ module TranslationLoader
10
+ autoload :CONSTS, 'sgtn-client/loader/consts'
11
+
12
+ module Cache # :nodoc:
13
+ # get from cache, return expired data immediately
14
+ def get_bundle(component, locale)
15
+ SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
16
+
17
+ key = SgtnClient::CacheUtil.get_cachekey(component, locale)
18
+ cache_item = SgtnClient::CacheUtil.get_cache(key)
19
+ if cache_item
20
+ if SgtnClient::CacheUtil.is_expired(cache_item)
21
+ Thread.new do # TODO: Use one thread # refresh in background
22
+ begin
23
+ load_bundle(component, locale)
24
+ rescue StandardError => e
25
+ SgtnClient.logger.error "an error occured while loading bundle: component=#{component}, locale=#{locale}"
26
+ SgtnClient.logger.error e
27
+ end
28
+ end
29
+ end
30
+ return cache_item.dig(:items)
31
+ end
32
+
33
+ load_bundle(component, locale) # refresh synchronously if not in cache
34
+ end
35
+
36
+ # load and save to cache
37
+ def load_bundle(component, locale)
38
+ SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
39
+
40
+ key = SgtnClient::CacheUtil.get_cachekey(component, locale)
41
+ item = super
42
+ SgtnClient::CacheUtil.write_cache(key, item) if item
43
+ item
44
+ end
45
+
46
+ def available_bundles
47
+ SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}]"
48
+
49
+ cache_item = SgtnClient::CacheUtil.get_cache(CONSTS::AVAILABLE_BUNDLES_KEY)
50
+ if cache_item
51
+ if SgtnClient::CacheUtil.is_expired(cache_item)
52
+ Thread.new do # TODO: Use one thread
53
+ begin
54
+ item = super
55
+ SgtnClient::CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
56
+ rescue StandardError => e
57
+ SgtnClient.logger.error 'an error occured while loading available bundles.'
58
+ SgtnClient.logger.error e
59
+ end
60
+ end
61
+ end
62
+ return cache_item.dig(:items)
63
+ end
64
+
65
+ item = super
66
+ SgtnClient::CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
67
+ item
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,49 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
5
+ module TranslationLoader
6
+ class Chain
7
+ attr_accessor :loaders
8
+
9
+ def initialize(*loaders)
10
+ self.loaders = loaders
11
+ end
12
+
13
+ def load_bundle(component, locale)
14
+ exception = nil
15
+
16
+ loaders.each do |loader|
17
+ begin
18
+ bundle = loader.load_bundle(component, locale)
19
+ return bundle if bundle
20
+ rescue StandardError => e
21
+ exception = e
22
+ SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] {component: #{component},locale: #{locale}}, failed on #{loader.class}: #{e}"
23
+ end
24
+ end
25
+
26
+ raise exception || SgtnClient::SingletonError.new("can't load component: #{component}, locale: #{locale}")
27
+ end
28
+
29
+ def available_bundles
30
+ exception = nil
31
+ total_data = Set.new
32
+
33
+ loaders.each do |loader|
34
+ begin
35
+ item = loader.available_bundles
36
+ total_data += item
37
+ rescue StandardError => e
38
+ exception = e
39
+ SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] failed on #{loader.class}: #{e}"
40
+ end
41
+ end
42
+
43
+ raise exception if total_data.empty? && exception
44
+
45
+ total_data
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
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
8
+ module CONSTS
9
+ OLD_SOURCE_LOCALE = 'old_source'
10
+ REAL_SOURCE_LOCALE = 'latest'
11
+
12
+ AVAILABLE_BUNDLES_KEY = 'available_bundles'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
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
+
14
+ module LoaderFactory
15
+ def self.create(config)
16
+ SgtnClient.logger.info "[#{method(__callee__).owner}.#{__callee__}] config=#{config}"
17
+
18
+ loaders = []
19
+ loaders << Source.new(config) if config['source_bundle']
20
+ loaders << SgtnServer.new(config) if config['vip_server']
21
+ loaders << LocalTranslation.new(config) if config['translation_bundle']
22
+ raise SgtnClient::SingletonError, 'no translation is available!' if loaders.empty?
23
+
24
+ chain_loader = Class.new(Chain)
25
+ chain_loader.include SourceComparer if config['source_bundle'] || config['vip_server']
26
+ chain_loader.include SingleLoader
27
+ chain_loader.include Cache
28
+
29
+ chain_loader.new(*loaders)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ require 'multi_json'
5
+
6
+ module SgtnClient
7
+ module Common
8
+ autoload :BundleID, 'sgtn-client/common/data'
9
+ end
10
+
11
+ module TranslationLoader
12
+ autoload :CONSTS, 'sgtn-client/loader/consts'
13
+
14
+ class LocalTranslation
15
+ BUNDLE_PREFIX = 'messages_'.freeze
16
+ BUNDLE_SUFFIX = '.json'.freeze
17
+
18
+ def initialize(config)
19
+ @base_path = Pathname.new(config['translation_bundle']) + config['product_name'] + config['version'].to_s
20
+ end
21
+
22
+ def load_bundle(component, locale)
23
+ return if locale == CONSTS::REAL_SOURCE_LOCALE # return when querying source
24
+
25
+ SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] component=#{component}, locale=#{locale}"
26
+
27
+ file_name = BUNDLE_PREFIX + locale + BUNDLE_SUFFIX
28
+ file_path = @base_path + component + file_name
29
+
30
+ bundle_data = JSON.parse(File.read(file_path))
31
+ messages = bundle_data['messages']
32
+
33
+ raise SgtnClient::SingletonError, "no messages in local bundle file: #{file_path}." unless messages
34
+
35
+ messages
36
+ end
37
+
38
+ def available_bundles
39
+ SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}]"
40
+
41
+ @available_bundles ||= begin
42
+ @base_path.glob('*/*.json').reduce(Set.new) do |bundles, f|
43
+ locale = f.basename.to_s.sub(/\A#{BUNDLE_PREFIX}/i, '').sub(/#{BUNDLE_SUFFIX}\z/i, '')
44
+ bundles.add Common::BundleID.new(f.parent.basename.to_s, locale)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 VMware, Inc.
4
+ # SPDX-License-Identifier: EPL-2.0
5
+
6
+ require 'faraday'
7
+ require 'faraday_middleware'
8
+
9
+ module SgtnClient
10
+ module Common
11
+ autoload :BundleID, 'sgtn-client/common/data'
12
+ end
13
+
14
+ module TranslationLoader
15
+ autoload :CONSTS, 'sgtn-client/loader/consts'
16
+
17
+ class SgtnServer
18
+ ERROR_ILLEGAL_DATA = 'server returned illegal data.'
19
+ ERROR_BUSINESS_ERROR = 'server returned business error.'
20
+
21
+ REQUEST_ARGUMENTS = { timeout: 10 }.freeze
22
+
23
+ def initialize(config)
24
+ @server_url = config['vip_server']
25
+
26
+ product_root = format('/i18n/api/v2/translation/products/%s/versions/%s', config['product_name'], config['version'])
27
+
28
+ @bundle_url = "#{product_root}/locales/%s/components/%s"
29
+ @locales_url = "#{product_root}/localelist"
30
+ @components_url = "#{product_root}/componentlist"
31
+ end
32
+
33
+ def load_bundle(component, locale)
34
+ SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] component=#{component}, locale=#{locale}"
35
+
36
+ messages = query_server(format(@bundle_url, locale, component), ['messages'])
37
+ messages
38
+ end
39
+
40
+ def available_bundles
41
+ SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}]"
42
+
43
+ components_thread = Thread.new { available_components }
44
+ available_locales.reduce(Set.new) do |bundles, locale|
45
+ components_thread.value.reduce(bundles) do |inner_bundles, component|
46
+ inner_bundles << Common::BundleID.new(component, locale)
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def available_locales
54
+ query_server(@locales_url, ['locales'])
55
+ end
56
+
57
+ def available_components
58
+ query_server(@components_url, ['components'])
59
+ end
60
+
61
+ def query_server(url, path_to_data = [], queries = nil, headers = nil)
62
+ conn = Faraday.new(@server_url, request: REQUEST_ARGUMENTS) do |f|
63
+ f.response :json # decode response bodies as JSON
64
+ f.use :gzip
65
+ f.response :raise_error
66
+ f.response :logger, SgtnClient.logger, { log_level: :debug }
67
+ end
68
+ resp = conn.get(url, queries, headers)
69
+
70
+ process_business_error(resp.body)
71
+ extract_data(resp.body, path_to_data)
72
+ end
73
+
74
+ def extract_data(parsedbody, path_to_data)
75
+ data = parsedbody.dig('data', *path_to_data)
76
+ raise SgtnClient::SingletonError, "no expected data in response. Body is: #{parsedbody}" unless data
77
+
78
+ data
79
+ end
80
+
81
+ def process_business_error(parsedbody)
82
+ b_code = parsedbody.dig('response', 'code')
83
+ unless b_code >= 200 && b_code < 300 || b_code >= 600 && b_code < 700
84
+ raise SgtnClient::SingletonError, "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}"
85
+ end
86
+
87
+ # 600 means a successful response, 6xx means partial successful.
88
+ SgtnClient.logger.warn "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}" if b_code > 600
89
+ rescue TypeError, ArgumentError, NoMethodError => e
90
+ raise SgtnClient::SingletonError, "#{ERROR_ILLEGAL_DATA} #{e}. Body is: #{parsedbody}"
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
5
+ autoload :SingleOperation, 'sgtn-client/common/single_operation'
6
+ autoload :CacheUtil, 'sgtn-client/util/cache-util'
7
+
8
+ module TranslationLoader
9
+ autoload :CONSTS, 'sgtn-client/loader/consts'
10
+
11
+ module SingleLoader
12
+ def load_bundle(component, locale)
13
+ SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
14
+
15
+ @single_bundle_loader ||= single_loader { |c,l| super(c,l) }
16
+ id = CacheUtil.get_cachekey(component, locale)
17
+ @single_bundle_loader.operate(id, component, locale)&.value
18
+ ensure
19
+ # delete thread from hash after finish
20
+ @single_bundle_loader.remove_object(id)
21
+ end
22
+
23
+ def available_bundles
24
+ SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}]"
25
+
26
+ @single_available_bundles_loader ||= single_loader { super }
27
+ @single_available_bundles_loader.operate(CONSTS::AVAILABLE_BUNDLES_KEY)&.value
28
+ ensure
29
+ @single_available_bundles_loader.remove_object(CONSTS::AVAILABLE_BUNDLES_KEY)
30
+ end
31
+
32
+ private
33
+ def single_loader(&block)
34
+ none_alive = proc { |_, thread| thread.nil? || thread.alive? == false }
35
+ creator = proc do |id, _, *args|
36
+ Thread.new do
37
+ SgtnClient.logger.debug "start single loading #{id}"
38
+ block.call(*args)
39
+ end
40
+ end
41
+
42
+ SgtnClient::SingleOperation.new(none_alive, &creator)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
5
+ module Common
6
+ autoload :BundleID, 'sgtn-client/common/data'
7
+ end
8
+
9
+ module TranslationLoader
10
+ autoload :CONSTS, 'sgtn-client/loader/consts'
11
+
12
+ class Source
13
+ def initialize(config)
14
+ @source_bundle_path = Pathname.new(config['source_bundle'])
15
+ end
16
+
17
+ def load_bundle(component, locale = nil)
18
+ return if locale && locale != CONSTS::REAL_SOURCE_LOCALE # return when NOT querying source
19
+
20
+ SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] component=#{component}"
21
+
22
+ total_messages = {}
23
+
24
+ (@source_bundle_path + component).glob('**/*.{yml, yaml}') do |f|
25
+ bundle = YAML.safe_load(File.read(f))
26
+ messages = bundle&.first&.last # TODO: Warn about inconsistent source locale
27
+ if messages.is_a?(Hash)
28
+ total_messages.merge!(messages)
29
+ else
30
+ SgtnClient.logger.error "[#{method(__callee__).owner}.#{__callee__}] invalid bundle data in #{f}"
31
+ end
32
+ end
33
+
34
+ raise SgtnClient::SingletonError, "no local source messages for component #{component}" if total_messages.empty?
35
+
36
+ total_messages
37
+ end
38
+
39
+ def available_bundles
40
+ SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}]"
41
+
42
+ @available_bundles ||= begin
43
+ @source_bundle_path.children.select(&:directory?).reduce(Set.new) do |bundles, component|
44
+ component.glob('**/*.{yml, yaml}') do |_|
45
+ bundles << Common::BundleID.new(component.basename.to_s, SgtnClient::LocaleUtil.get_source_locale)
46
+ break bundles
47
+ end || bundles
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
5
+ autoload :StringUtil, 'sgtn-client/util/string-util'
6
+ autoload :LocaleUtil, 'sgtn-client/util/locale-util'
7
+
8
+ module TranslationLoader
9
+ autoload :CONSTS, 'sgtn-client/loader/consts'
10
+
11
+ module SourceComparer
12
+ def load_bundle(component, locale)
13
+ SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
14
+
15
+ # source locale and old source locale don't need comparison because they are bases of comparison
16
+ real_locale = cache_to_real_map[locale]
17
+ return super(component, real_locale) if real_locale
18
+
19
+ old_source_bundle_thread = Thread.new { load_bundle(component, CONSTS::OLD_SOURCE_LOCALE) }
20
+ source_bundle_thread = Thread.new { load_bundle(component, LocaleUtil.get_source_locale) }
21
+ translation_bundle = super(component, locale)
22
+
23
+ begin
24
+ old_source_bundle = old_source_bundle_thread.value
25
+ source_bundle = source_bundle_thread.value
26
+ rescue StandardError => e
27
+ SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] failed to load soruce(or old source) bundle. component:#{component}. error: #{e}"
28
+ return translation_bundle
29
+ end
30
+
31
+ compare_source(translation_bundle, old_source_bundle, source_bundle)
32
+ end
33
+
34
+ private
35
+
36
+ def compare_source(translation_bundle, old_source_bundle, source_bundle)
37
+ if !translation_bundle.is_a?(Hash) || !source_bundle.is_a?(Hash) || !old_source_bundle.is_a?(Hash)
38
+ SgtnClient.logger.warn "can't do source comparison because some bundle data are wrong."
39
+ return translation_bundle
40
+ end
41
+
42
+ source_bundle.each do |key, value|
43
+ if old_source_bundle[key] != value || translation_bundle[key].nil?
44
+ translation_bundle[key] = StringUtil.new(value, LocaleUtil.get_source_locale)
45
+ end
46
+ end
47
+ translation_bundle
48
+ end
49
+
50
+ def cache_to_real_map
51
+ @cache_to_real_map ||= {
52
+ LocaleUtil.get_source_locale => CONSTS::REAL_SOURCE_LOCALE,
53
+ CONSTS::OLD_SOURCE_LOCALE => LocaleUtil.get_source_locale
54
+ }.freeze
55
+ end
56
+ end
57
+ end
58
+ 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
@@ -12,6 +17,7 @@ module SgtnClient
12
17
  autoload :ValidateUtil, "sgtn-client/util/validate-util"
13
18
  autoload :LocaleUtil, "sgtn-client/util/locale-util"
14
19
  autoload :FileUtil, "sgtn-client/util/file-util"
20
+ autoload :CacheUtil, "sgtn-client/util/cache-util"
15
21
 
16
22
  module Formatters
17
23
  autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
@@ -44,7 +50,7 @@ module SgtnClient
44
50
  end
45
51
  file = File.open(file, 'a')
46
52
  file.sync = true
47
- SgtnClient.logger = Logger.new(file)
53
+ SgtnClient.logger = Logger.new(file, LOGFILE_SHIFT_AGE)
48
54
 
49
55
  # Set log level for sandbox mode
50
56
  env = SgtnClient::Config.default_environment