singleton-client-test 0.7.7.6 → 0.7.7.8

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: 3bd55bdad7f46bf9c0cffd42a710cfb6dcae97ecadbbb148af41d2b44be0afca
4
- data.tar.gz: 026ef3a390e9a88691decb97b1131ac31e358c9ede7628a7b698d38899a80465
3
+ metadata.gz: 54400e87e847568bead1be140a4374acced859dc3fa9f3fa954b3ddd3fae7192
4
+ data.tar.gz: 073364cb409f2b2fdfa40d0ebadd6c6d36983c262dad8cd9f1d57bae602d419f
5
5
  SHA512:
6
- metadata.gz: 5792e7d5f543603927732321cf440be37266fdc5a65fdd6075017068bb98fd9e5b8b4c52e8421fb0508166997993117d6c151921243b642ea448fb5ceea2e542
7
- data.tar.gz: 7a8938ba9ffe0b6480a4b83e441b48d48eec98f5e2262019ff5db001e94fe50d404cc3c4277e464cab90ab7141076223b370d2c3a733058d95eecd940f8d8e88
6
+ metadata.gz: 5b213886e41d561eb73c20008920a2ddf87ddd98645f64efdda180f1e157749302494c944f581b87d529ed688e44858d3d0c8cb01cb7eeed9c6a50106b0494f8
7
+ data.tar.gz: efc69bd188f29815770d8c65541ade62268d063cf38a88b3a3cd416ad4c5e961b3bf7e290d4c9faec9510f3ac76e3c15bd6e2070e1e175e2f1969bb09f0d0bae
@@ -39,53 +39,57 @@ module SgtnClient
39
39
  get_translations(component, locale)
40
40
  end
41
41
 
42
- def translate(key, component, locale = nil, **kwargs)
42
+ def translate(key, component, locale = nil, **kwargs, &block)
43
+ translate!(key, component, locale, **kwargs, &block)
44
+ rescue StandardError => e
45
+ SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] {#{key}, #{component}, #{locale}}. #{e}" }
46
+ key
47
+ end
48
+ alias t translate
49
+
50
+ # raise error when translation is not found
51
+ def translate!(key, component, locale = nil, **kwargs, &block)
43
52
  SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] key: #{key}, component: #{component}, locale: #{locale}, args: #{kwargs}" }
44
53
 
45
54
  begin
46
- best_match_locale = LocaleUtil.get_best_locale(locale || SgtnClient.locale, component)
47
- messages, actual_locale = get_bundle_with_fallback(component, best_match_locale)
48
- result = messages&.fetch(key, nil)
55
+ picked_locale = pickup_locale(locale || SgtnClient.locale, component)
56
+ result, actual_locale = get_string!(key, component, picked_locale)
49
57
  rescue StandardError => e
50
- SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] translation is missing. {#{key}, #{component}, #{locale}}. #{e}" }
51
- result = nil
58
+ raise e if block.nil?
52
59
  end
53
-
54
60
  if result.nil?
55
- return key unless block_given?
61
+ raise SingletonError, 'translation is missing.' if block.nil?
56
62
 
57
- result = yield
63
+ result = block.call
58
64
  return if result.nil?
59
65
  end
60
66
 
61
- if kwargs.empty?
62
- result
63
- else
64
- result.localize(actual_locale) % kwargs
65
- end
67
+ kwargs.empty? ? result : interpolate(result, actual_locale, **kwargs)
66
68
  end
67
- alias t translate
69
+ alias t! translate!
68
70
 
69
71
  def get_translations(component, locale = nil)
70
- SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] component: #{component}, locale: #{locale}" }
71
-
72
- best_match_locale = LocaleUtil.get_best_locale(locale || SgtnClient.locale, component)
73
- messages, actual_locale = get_bundle_with_fallback(component, best_match_locale)
74
-
75
- { 'component' => component, 'locale' => actual_locale, 'messages' => messages } if messages
72
+ get_translations!(component, locale)
76
73
  rescue StandardError => e
77
- SgtnClient.logger.error "[#{method(__callee__).owner}.#{__callee__}] translations are missing. {#{component}, #{locale}}. #{e}"
74
+ SgtnClient.logger.error "[#{method(__callee__).owner}.#{__callee__}] {#{component}, #{locale}}. #{e}"
78
75
  nil
79
76
  end
80
77
 
81
- private
78
+ def get_translations!(component, locale = nil)
79
+ SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] component: #{component}, locale: #{locale}" }
82
80
 
83
- def get_bundle(component, locale)
84
- get_bundle!(component, locale)
85
- rescue StandardError => e
86
- SgtnClient.logger.error "[#{method(__callee__).owner}.#{__callee__}] failed to get a bundle. component: #{component}, locale: #{locale}"
87
- SgtnClient.logger.error e
88
- nil
81
+ picked_locale = pickup_locale(locale || SgtnClient.locale, component)
82
+ get_bundle!(component, picked_locale)
83
+ end
84
+
85
+ protected
86
+
87
+ def pickup_locale(locale, component)
88
+ LocaleUtil.get_best_locale(locale, component)
89
+ end
90
+
91
+ def interpolate(translation, locale, **kwargs)
92
+ translation.localize(locale) % kwargs
89
93
  end
90
94
 
91
95
  def get_bundle!(component, locale)
@@ -99,19 +103,15 @@ module SgtnClient
99
103
  raise
100
104
  end
101
105
 
102
- def get_bundle_with_fallback(component, locale)
103
- messages = get_bundle(component, locale)
104
- return messages, locale if messages
105
-
106
- LocaleUtil.locale_fallbacks.each do |l|
107
- next if l == locale
106
+ private
108
107
 
109
- messages = get_bundle(component, l)
110
- return messages, l if messages
111
- end
108
+ def get_string!(key, component, locale)
109
+ bundle = get_bundle!(component, locale)
110
+ [bundle.fetch(key), bundle.locale]
112
111
  end
113
112
  end
114
113
 
115
114
  extend Implementation
115
+ extend Fallbacks
116
116
  end
117
117
  end
@@ -43,20 +43,26 @@ module SgtnClient
43
43
  end
44
44
 
45
45
  def self.age
46
- @age ||= SgtnClient.config.cache_expiry_period * 60
46
+ @age ||= (SgtnClient.config.cache_expiry_period || 24 * 60) * 60
47
47
  end
48
48
  end
49
49
 
50
50
  class BundleData < Hash # :nodoc:
51
51
  include DataInfo
52
52
 
53
- def initialize(*args)
53
+ attr_reader :origin, :locale, :component
54
+
55
+ def initialize(*args, origin: nil, locale: nil, component: nil)
54
56
  if !args.empty? && args[0].is_a?(Hash)
55
57
  update(args[0])
56
58
  super()
57
59
  else
58
60
  super
59
61
  end
62
+
63
+ @origin = origin
64
+ @locale = locale
65
+ @component = component
60
66
  end
61
67
  end
62
68
 
@@ -11,9 +11,13 @@ module SgtnClient
11
11
  include Observable
12
12
  include Singleton
13
13
 
14
- attr_accessor :product_name, :version, :vip_server, :translation_bundle, :source_bundle, :cache_expiry_period, :log_file, :log_level
14
+ attr_accessor :product_name, :version, :vip_server, :translation_bundle, :source_bundle, :cache_expiry_period,
15
+ :log_file, :log_level
16
+ attr_writer :logger, :pseudo_tag
15
17
 
16
- attr_writer :logger
18
+ def pseudo_tag
19
+ @pseudo_tag ||= '@@'
20
+ end
17
21
 
18
22
  def logger
19
23
  @logger ||= if log_file
@@ -0,0 +1,29 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
5
+ module Fallbacks # :nodoc:
6
+ protected
7
+
8
+ def get_bundle!(component, locale)
9
+ error = nil
10
+ localechain(locale) do |l|
11
+ return super(component, l)
12
+ rescue StandardError => e
13
+ error = e
14
+ end
15
+ raise error if error
16
+ end
17
+
18
+ private
19
+
20
+ def localechain(locale)
21
+ yield locale
22
+ LocaleUtil.locale_fallbacks.each do |l|
23
+ next if l == locale
24
+
25
+ yield l
26
+ end
27
+ end
28
+ end
29
+ end
@@ -35,7 +35,7 @@ module SgtnClient
35
35
  def load_bundle(component, locale)
36
36
  SgtnClient.logger.debug { "[#{__FILE__}][#{__callee__}] CacheFiller, component=#{component}, locale=#{locale}" }
37
37
 
38
- @cache_hash[Common::BundleID.new(component, locale)] = Common::BundleData.new(super)
38
+ @cache_hash[Common::BundleID.new(component, locale)] = super
39
39
  end
40
40
 
41
41
  def available_bundles
@@ -6,16 +6,16 @@ require 'set'
6
6
  module SgtnClient
7
7
  module TranslationLoader
8
8
  class Chain
9
- attr_accessor :loaders
9
+ attr_reader :loaders
10
10
 
11
11
  def initialize(*loaders)
12
- self.loaders = loaders
12
+ @loaders = loaders
13
13
  end
14
14
 
15
15
  def load_bundle(component, locale)
16
16
  exception = nil
17
17
 
18
- loaders.each do |loader|
18
+ @loaders.each do |loader|
19
19
  begin
20
20
  bundle = loader.load_bundle(component, locale)
21
21
  return bundle if bundle
@@ -32,7 +32,7 @@ module SgtnClient
32
32
  exception = nil
33
33
  total_data = Set.new
34
34
 
35
- loaders.each do |loader|
35
+ @loaders.each do |loader|
36
36
  begin
37
37
  item = loader.available_bundles
38
38
  total_data += item
@@ -6,7 +6,6 @@
6
6
  module SgtnClient
7
7
  module TranslationLoader
8
8
  module CONSTS
9
- OLD_SOURCE_LOCALE = 'old_source'
10
9
  REAL_SOURCE_LOCALE = 'latest'
11
10
 
12
11
  AVAILABLE_BUNDLES_KEY = 'available_bundles'
@@ -15,6 +15,7 @@ module SgtnClient
15
15
 
16
16
  chain_loader = Class.new(Chain)
17
17
  chain_loader.include SourceComparer
18
+ chain_loader.include Pseudo
18
19
  chain_loader.include CacheFiller
19
20
  chain_loader.include SingleLoader
20
21
  chain_loader.include Cache
@@ -26,17 +26,16 @@ module SgtnClient
26
26
 
27
27
  raise SingletonError, "no messages in local bundle file: #{file_path}." unless messages
28
28
 
29
- messages
29
+ Common::BundleData.new(messages, origin: self, component: component,
30
+ locale: locale == CONSTS::REAL_SOURCE_LOCALE ? LocaleUtil.get_source_locale : locale)
30
31
  end
31
32
 
32
33
  def available_bundles
33
34
  SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}]" }
34
35
 
35
- @available_bundles ||= begin
36
- @base_path.glob('*/*.json').reduce(Set.new) do |bundles, f|
37
- locale = f.basename.to_s.sub(/\A#{BUNDLE_PREFIX}/i, '').sub(/#{BUNDLE_SUFFIX}\z/i, '')
38
- bundles.add Common::BundleID.new(f.parent.basename.to_s, locale)
39
- end
36
+ @available_bundles = @base_path.glob('*/*.json').reduce(Set.new) do |bundles, f|
37
+ locale = f.basename.to_s.sub(/\A#{BUNDLE_PREFIX}/i, '').sub(/#{BUNDLE_SUFFIX}\z/i, '')
38
+ bundles.add Common::BundleID.new(f.parent.basename.to_s, locale)
40
39
  end
41
40
  end
42
41
  end
@@ -0,0 +1,21 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ module SgtnClient
5
+ module TranslationLoader
6
+ module Pseudo # :nodoc:
7
+ def initialize(*)
8
+ super
9
+ @pseudo_tag = Sgtn.pseudo_tag
10
+ end
11
+
12
+ def load_bundle(component, locale)
13
+ return super unless locale == Sgtn::PSEUDO_LOCALE
14
+
15
+ SgtnClient.logger.debug { "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}" }
16
+
17
+ super(component, LocaleUtil.get_source_locale).transform_values! { |v| "#{@pseudo_tag}#{v}#{@pseudo_tag}" }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -27,16 +27,18 @@ module SgtnClient
27
27
 
28
28
  @conn = Faraday.new(config.vip_server, request: REQUEST_ARGUMENTS) do |f|
29
29
  f.response :json # decode response bodies as JSON
30
- f.use :gzip
31
30
  f.response :raise_error
32
31
  f.response :logger, config.logger, { log_level: :debug, headers: false, bodies: true }
32
+ f.use :gzip
33
33
  end
34
34
  end
35
35
 
36
36
  def load_bundle(component, locale)
37
37
  SgtnClient.logger.debug { "[#{method(__callee__).owner}.#{__callee__}] component=#{component}, locale=#{locale}" }
38
38
 
39
- query_server(format(@bundle_url, locale, component), ['messages'])
39
+ data = query_server(format(@bundle_url, locale, component), ['messages'])
40
+ Common::BundleData.new(data, origin: self, component: component,
41
+ locale: locale == CONSTS::REAL_SOURCE_LOCALE ? LocaleUtil.get_source_locale : locale)
40
42
  end
41
43
 
42
44
  def available_bundles
@@ -7,7 +7,7 @@ require 'yaml'
7
7
 
8
8
  module SgtnClient
9
9
  module TranslationLoader
10
- class Source
10
+ class Source # :nodoc:
11
11
  def initialize(config)
12
12
  @source_bundle_path = Pathname.new(config.source_bundle)
13
13
  end
@@ -31,7 +31,7 @@ module SgtnClient
31
31
 
32
32
  raise SingletonError, "no local source messages for component #{component}" if total_messages.empty?
33
33
 
34
- total_messages
34
+ Common::BundleData.new(total_messages, origin: self, component: component, locale: LocaleUtil.get_source_locale)
35
35
  end
36
36
 
37
37
  def available_bundles
@@ -11,41 +11,45 @@ module SgtnClient
11
11
  real_locale = cache_to_real_map[locale]
12
12
  return super(component, real_locale) if real_locale
13
13
 
14
- old_source_bundle_thread = Thread.new { load_bundle(component, CONSTS::OLD_SOURCE_LOCALE) }
15
14
  source_bundle_thread = Thread.new { load_bundle(component, LocaleUtil.get_source_locale) }
16
- translation_bundle = super(component, locale)
15
+ translation_bundle = super
16
+
17
+ begin
18
+ old_source_bundle = translation_bundle.origin.load_bundle(component, old_source_locale(locale))
19
+ rescue StandardError => e
20
+ SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] failed to load old source bundle. component:#{component}. error: #{e}"
21
+ end
17
22
 
18
23
  begin
19
- old_source_bundle = old_source_bundle_thread.value
20
24
  source_bundle = source_bundle_thread.value
21
25
  rescue StandardError => e
22
- SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] failed to load soruce(or old source) bundle. component:#{component}. error: #{e}"
26
+ SgtnClient.logger.error "[#{__FILE__}][#{__callee__}] failed to load source bundle. component:#{component}. error: #{e}"
23
27
  return translation_bundle
24
28
  end
25
29
 
26
30
  compare_source(translation_bundle, old_source_bundle, source_bundle)
27
31
  end
28
32
 
29
- private
33
+ protected
30
34
 
31
- def compare_source(translation_bundle, old_source_bundle, source_bundle)
32
- if !translation_bundle.is_a?(Hash) || !source_bundle.is_a?(Hash) || !old_source_bundle.is_a?(Hash)
33
- SgtnClient.logger.warn "can't do source comparison because some bundle data are wrong."
34
- return translation_bundle
35
- end
35
+ def old_source_locale(_locale)
36
+ LocaleUtil.get_source_locale
37
+ end
36
38
 
37
- source_bundle.each do |key, value|
38
- if old_source_bundle[key] != value || translation_bundle[key].nil?
39
- translation_bundle[key] = StringUtil.new(value, LocaleUtil.get_source_locale)
39
+ def compare_source(translation_bundle, old_source_bundle, source_bundle)
40
+ source_bundle.each do |k, v|
41
+ if translation_bundle[k].nil? || (!old_source_bundle.nil? && old_source_bundle[k] != v)
42
+ translation_bundle[k] = LocalizedString.new(v, LocaleUtil.get_source_locale) if v
40
43
  end
41
44
  end
42
45
  translation_bundle
43
46
  end
44
47
 
48
+ private
49
+
45
50
  def cache_to_real_map
46
51
  @cache_to_real_map ||= {
47
- LocaleUtil.get_source_locale => CONSTS::REAL_SOURCE_LOCALE,
48
- CONSTS::OLD_SOURCE_LOCALE => LocaleUtil.get_source_locale
52
+ LocaleUtil.get_source_locale => CONSTS::REAL_SOURCE_LOCALE
49
53
  }.freeze
50
54
  end
51
55
  end
@@ -11,6 +11,7 @@ module SgtnClient
11
11
  autoload :CONSTS, 'sgtn-client/loader/consts'
12
12
  autoload :LoaderFactory, 'sgtn-client/loader/loader_factory'
13
13
  autoload :LocalTranslation, 'sgtn-client/loader/local_translation'
14
+ autoload :Pseudo, 'sgtn-client/loader/pseudo'
14
15
  autoload :SgtnServer, 'sgtn-client/loader/server'
15
16
  autoload :SingleLoader, 'sgtn-client/loader/single_loader'
16
17
  autoload :SourceComparer, 'sgtn-client/loader/source_comparer'
@@ -9,15 +9,15 @@ module SgtnClient # :nodoc:
9
9
  autoload :TranslationLoader, 'sgtn-client/loader'
10
10
  autoload :SingleOperation, 'sgtn-client/common/single_operation'
11
11
  autoload :Translation, 'sgtn-client/api/translation'
12
+ autoload :Fallbacks, 'sgtn-client/fallbacks'
12
13
  autoload :T, 'sgtn-client/api/t'
13
14
  autoload :Source, 'sgtn-client/api/source'
14
15
  autoload :Config, 'sgtn-client/core/config'
15
16
  autoload :Exceptions, 'sgtn-client/core/exceptions'
16
17
  autoload :ValidateUtil, 'sgtn-client/util/validate-util'
17
18
  autoload :LocaleUtil, 'sgtn-client/util/locale-util'
18
- autoload :StringUtil, 'sgtn-client/util/string-util'
19
+ autoload :LocalizedString, 'sgtn-client/util/localized_string'
19
20
  autoload :SingletonError, 'sgtn-client/exceptions'
20
- autoload :I18nBackend, 'sgtn-client/i18n_backend'
21
21
 
22
22
  module Formatters # :nodoc:
23
23
  autoload :PluralFormatter, 'sgtn-client/formatters/plurals/plural_formatter'
@@ -15,40 +15,38 @@ module SgtnClient
15
15
  }.freeze
16
16
  LOCALE_SEPARATOR = '-'
17
17
  EN_LOCALE = 'en'
18
- @locale_match_results = Concurrent::Map.new
18
+
19
+ @locale_match_results = Concurrent::Map.new do |hash, component|
20
+ components = SgtnClient.config.available_components
21
+ unless components.empty? || components.include?(component)
22
+ raise SingletonError, "component '#{component}' doesn't exist!"
23
+ end
24
+
25
+ hash[component] = Concurrent::Map.new
26
+ end
19
27
  @lowercase_locales_map = Concurrent::Map.new
20
28
 
21
29
  def self.get_best_locale(locale, component)
22
- component_result = @locale_match_results[component] ||= begin
23
- components = SgtnClient.config.available_components
24
- unless components.empty? || components.include?(component)
25
- raise SingletonError, "component '#{component}' doesn't exist!"
30
+ return locale if SgtnClient.config.available_locales(component).include?(locale)
31
+
32
+ component_result = @locale_match_results[component]
33
+ component_result[locale] ||= begin
34
+ if component_result.size >= 50
35
+ component_result.delete(component_result.keys[Random.rand(component_result.size)])
26
36
  end
27
37
 
28
- Concurrent::Map.new
38
+ locale = locale.to_s
39
+ if locale.empty?
40
+ get_fallback_locale
41
+ else
42
+ candidates = lowercase_locales_map(component)
43
+ if candidates.empty?
44
+ locale
45
+ else
46
+ get_best_match(locale.gsub('_', LOCALE_SEPARATOR).downcase, candidates)
47
+ end
48
+ end
29
49
  end
30
-
31
- component_result[locale] ||= begin
32
- component_result.delete(component_result.keys[Random.rand(component_result.size)]) if component_result.size >= 50
33
-
34
- if SgtnClient.config.available_locales(component).include?(locale)
35
- locale
36
- elsif locale.nil?
37
- get_fallback_locale
38
- else
39
- locale = locale.to_s
40
- if locale.empty?
41
- get_fallback_locale
42
- else
43
- candidates = lowercase_locales_map(component)
44
- if candidates.empty?
45
- locale
46
- else
47
- get_best_match(locale.gsub('_', LOCALE_SEPARATOR).downcase, candidates)
48
- end
49
- end
50
- end
51
- end
52
50
  end
53
51
 
54
52
  def self.get_best_match(locale, candidates)
@@ -74,7 +72,7 @@ module SgtnClient
74
72
  end
75
73
 
76
74
  def self.locale_fallbacks
77
- @locale_fallbacks ||= [get_default_locale, get_source_locale, EN_LOCALE].uniq(&:to_s) - [nil, '']
75
+ @locale_fallbacks ||= ([get_default_locale, get_source_locale, EN_LOCALE].uniq(&:to_s) - [nil, '']).freeze
78
76
  end
79
77
 
80
78
  def self.lowercase_locales_map(component)
@@ -2,9 +2,9 @@
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
4
  module SgtnClient
5
- class StringUtil < String
6
- def initialize(str, locale)
7
- super(str)
5
+ class LocalizedString < String
6
+ def initialize(value, locale)
7
+ super(value)
8
8
  @locale = locale
9
9
  end
10
10
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'i18n'
5
5
 
6
- module SgtnClient # :nodoc:
6
+ module Sgtn # :nodoc:
7
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
8
  #
9
9
  # I18n::Backend::Simple.include(I18n::Backend::Fallbacks) # add fallbacks behavior to current backend
@@ -13,6 +13,10 @@ module SgtnClient # :nodoc:
13
13
  class I18nBackend
14
14
  def initialize(component)
15
15
  @component = component
16
+ @translation = Class.new do
17
+ include SgtnClient::Translation::Implementation
18
+ include Sgtn::Pseudo
19
+ end.new
16
20
  end
17
21
 
18
22
  def initialized?
@@ -34,13 +38,13 @@ module SgtnClient # :nodoc:
34
38
  def translations; end
35
39
 
36
40
  def exists?(locale, key, options)
37
- !!(translate(locale, key, options) { nil })
41
+ !!translate(locale, key, options)
38
42
  end
39
43
 
40
44
  def translate(locale, key, options)
41
45
  flat_key = I18n::Backend::Flatten.normalize_flat_keys(locale, key, options[:scope], '.')
42
46
  values = options.except(*I18n::RESERVED_KEYS)
43
- Translation.translate(flat_key, @component, locale, **values) { nil }
47
+ @translation.translate(flat_key, @component, locale, **values) { nil }
44
48
  end
45
49
 
46
50
  def localize(locale, object, format, options) end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 VMware, Inc.
4
+ # SPDX-License-Identifier: EPL-2.0
5
+
6
+ module Sgtn
7
+ module Pseudo # :nodoc:
8
+ protected
9
+
10
+ def pickup_locale(locale, _component)
11
+ locale == PSEUDO_LOCALE ? PSEUDO_LOCALE : super
12
+ end
13
+ end
14
+ end
@@ -5,6 +5,15 @@ require 'forwardable'
5
5
  require_relative 'singleton-ruby'
6
6
 
7
7
  module Sgtn # :nodoc:
8
+ autoload :Pseudo, 'singleton-client/pseudo'
9
+ autoload :I18nBackend, 'singleton-client/i18n_backend'
10
+
11
+ extend SgtnClient::Translation::Implementation
12
+ extend SgtnClient::Fallbacks
13
+ extend Sgtn::Pseudo
14
+
15
+ PSEUDO_LOCALE = 'pseudo'.freeze
16
+
8
17
  class << self
9
18
  extend Forwardable
10
19
 
@@ -13,14 +22,6 @@ module Sgtn # :nodoc:
13
22
  SgtnClient.load(config_file, env)
14
23
  end
15
24
 
16
- def_delegator SgtnClient::Config, :instance, :config
17
- delegate %i[translate t get_translations] => SgtnClient::Translation,
18
- %i[locale locale=] => SgtnClient,
19
- %i[logger product_name version vip_server translation_bundle
20
- source_bundle cache_expiry_period log_file log_level].flat_map { |m|
21
- [m, "#{m}=".to_sym]
22
- } => :config
23
-
24
25
  def with_locale(tmp_locale = nil)
25
26
  if tmp_locale.nil?
26
27
  yield
@@ -34,7 +35,11 @@ module Sgtn # :nodoc:
34
35
  end
35
36
  end
36
37
  end
37
- end
38
38
 
39
- I18nBackend = SgtnClient::I18nBackend
39
+ def_delegator SgtnClient::Config, :instance, :config
40
+ delegate %i[locale locale=] => SgtnClient,
41
+ %i[logger product_name version vip_server translation_bundle
42
+ source_bundle cache_expiry_period log_file log_level
43
+ pseudo_tag ].flat_map { |m| [m, "#{m}=".to_sym] } => :config
44
+ end
40
45
  end
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.6
4
+ version: 0.7.7.8
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-08-30 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -144,23 +144,26 @@ files:
144
144
  - lib/sgtn-client/core/config.rb
145
145
  - lib/sgtn-client/core/exceptions.rb
146
146
  - lib/sgtn-client/exceptions.rb
147
+ - lib/sgtn-client/fallbacks.rb
147
148
  - lib/sgtn-client/formatters/plurals/plural_formatter.rb
148
- - lib/sgtn-client/i18n_backend.rb
149
149
  - lib/sgtn-client/loader.rb
150
150
  - lib/sgtn-client/loader/cache.rb
151
151
  - lib/sgtn-client/loader/chain_loader.rb
152
152
  - lib/sgtn-client/loader/consts.rb
153
153
  - lib/sgtn-client/loader/loader_factory.rb
154
154
  - lib/sgtn-client/loader/local_translation.rb
155
+ - lib/sgtn-client/loader/pseudo.rb
155
156
  - lib/sgtn-client/loader/server.rb
156
157
  - lib/sgtn-client/loader/single_loader.rb
157
158
  - lib/sgtn-client/loader/source.rb
158
159
  - lib/sgtn-client/loader/source_comparer.rb
159
160
  - lib/sgtn-client/sgtn-client.rb
160
161
  - lib/sgtn-client/util/locale-util.rb
161
- - lib/sgtn-client/util/string-util.rb
162
+ - lib/sgtn-client/util/localized_string.rb
162
163
  - lib/sgtn-client/util/validate-util.rb
163
164
  - lib/singleton-client.rb
165
+ - lib/singleton-client/i18n_backend.rb
166
+ - lib/singleton-client/pseudo.rb
164
167
  - lib/singleton-ruby.rb
165
168
  - lib/version.rb
166
169
  homepage: https://github.com/vmware/singleton
@@ -182,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
185
  - !ruby/object:Gem::Version
183
186
  version: '0'
184
187
  requirements: []
185
- rubygems_version: 3.2.22
188
+ rubygems_version: 3.3.26
186
189
  signing_key:
187
190
  specification_version: 4
188
191
  summary: Singleton Ruby client