singleton-client-test 0.7.0.36 → 0.7.0.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sgtn-client/core/config.rb +4 -1
- data/lib/sgtn-client/loader/loader_factory.rb +1 -1
- data/lib/sgtn-client/loader/local_translation.rb +0 -2
- data/lib/sgtn-client/loader/server.rb +1 -1
- data/lib/sgtn-client/loader/single_loader.rb +11 -9
- data/lib/sgtn-client/loader/source.rb +2 -1
- data/lib/sgtn-client/sgtn-client.rb +4 -0
- data/lib/sgtn-client/util/locale-util.rb +29 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e774b278cf5b49efb41f194eeb40fab549670a57fbc0197600c272e71f15a795
|
4
|
+
data.tar.gz: e921a5d1ee1c3535597fca5991ca7c02b210ee731a7b7434f2bcd47cc958d7ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d505a75cea1047514cf6f6bbcc666b26f136307f8bcbe6d2952524c557fd4156bfe29125f9688eb7c9ac8d04237ef344901f9526a5cf8faae39b32439ae3223
|
7
|
+
data.tar.gz: 0e4ce99bcdcb6ec25d177a8aefd53e28a4beee4f1fe11c4c9be203c4e33e4f66e91d5f790e886a4f542c396acf5fc1355f5ae96e90c22d5387a478f11b1dedbb
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'erb'
|
5
5
|
require 'yaml'
|
6
|
-
|
6
|
+
require 'observer'
|
7
7
|
|
8
8
|
module SgtnClient
|
9
9
|
#include Exceptions
|
@@ -40,6 +40,7 @@ module SgtnClient
|
|
40
40
|
|
41
41
|
|
42
42
|
class Config
|
43
|
+
extend Observable
|
43
44
|
|
44
45
|
attr_accessor :username, :password, :signature, :app_id, :cert_path,
|
45
46
|
:token, :token_secret, :subject,
|
@@ -182,6 +183,8 @@ module SgtnClient
|
|
182
183
|
def bundles.locales
|
183
184
|
@locales ||= reduce(Set.new) { |locales, id| locales << id.locale }
|
184
185
|
end
|
186
|
+
changed
|
187
|
+
notify_observers(:available_locales)
|
185
188
|
end
|
186
189
|
bundles.locales
|
187
190
|
end
|
@@ -22,7 +22,7 @@ module SgtnClient
|
|
22
22
|
raise SgtnClient::SingletonError, 'no translation is available!' if loaders.empty?
|
23
23
|
|
24
24
|
chain_loader = Class.new(Chain)
|
25
|
-
chain_loader.include SourceComparer
|
25
|
+
chain_loader.include SourceComparer
|
26
26
|
chain_loader.include SingleLoader
|
27
27
|
chain_loader.include Cache
|
28
28
|
|
@@ -21,8 +21,6 @@ module SgtnClient
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def load_bundle(component, locale)
|
24
|
-
return if locale == CONSTS::REAL_SOURCE_LOCALE # return when querying source
|
25
|
-
|
26
24
|
SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] component=#{component}, locale=#{locale}"
|
27
25
|
|
28
26
|
file_name = BUNDLE_PREFIX + locale + BUNDLE_SUFFIX
|
@@ -23,7 +23,7 @@ module SgtnClient
|
|
23
23
|
def initialize(config)
|
24
24
|
@server_url = config['vip_server']
|
25
25
|
|
26
|
-
product_root = format('
|
26
|
+
product_root = format('i18n/api/v2/translation/products/%s/versions/%s', config['product_name'], config['version'])
|
27
27
|
|
28
28
|
@bundle_url = "#{product_root}/locales/%s/components/%s"
|
29
29
|
@locales_url = "#{product_root}/localelist"
|
@@ -12,12 +12,9 @@ module SgtnClient
|
|
12
12
|
def load_bundle(component, locale)
|
13
13
|
SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
|
14
14
|
|
15
|
-
@single_bundle_loader ||= single_loader { |c,l| super(c,l) }
|
15
|
+
@single_bundle_loader ||= single_loader { |c, l| super(c, l) }
|
16
16
|
id = CacheUtil.get_cachekey(component, locale)
|
17
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
18
|
end
|
22
19
|
|
23
20
|
def available_bundles
|
@@ -25,21 +22,26 @@ module SgtnClient
|
|
25
22
|
|
26
23
|
@single_available_bundles_loader ||= single_loader { super }
|
27
24
|
@single_available_bundles_loader.operate(CONSTS::AVAILABLE_BUNDLES_KEY)&.value
|
28
|
-
ensure
|
29
|
-
@single_available_bundles_loader.remove_object(CONSTS::AVAILABLE_BUNDLES_KEY)
|
30
25
|
end
|
31
26
|
|
32
27
|
private
|
28
|
+
|
33
29
|
def single_loader(&block)
|
34
|
-
|
30
|
+
loader = nil
|
31
|
+
none_alive = proc { |_, thread| thread.nil? }
|
35
32
|
creator = proc do |id, _, *args|
|
36
33
|
Thread.new do
|
37
34
|
SgtnClient.logger.debug "start single loading #{id}"
|
38
|
-
|
35
|
+
begin
|
36
|
+
block.call(*args)
|
37
|
+
ensure
|
38
|
+
# delete thread from hash after finish
|
39
|
+
loader.remove_object(id)
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
SgtnClient::SingleOperation.new(none_alive, &creator)
|
44
|
+
loader = SgtnClient::SingleOperation.new(none_alive, &creator)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
3
|
|
4
4
|
require 'pathname'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
7
|
module SgtnClient
|
7
8
|
module Common
|
@@ -24,7 +25,7 @@ module SgtnClient
|
|
24
25
|
total_messages = {}
|
25
26
|
|
26
27
|
(@source_bundle_path + component).glob('**/*.{yml, yaml}') do |f|
|
27
|
-
bundle = YAML.
|
28
|
+
bundle = YAML.load(File.read(f))
|
28
29
|
messages = bundle&.first&.last # TODO: Warn about inconsistent source locale
|
29
30
|
if messages.is_a?(Hash)
|
30
31
|
total_messages.merge!(messages)
|
@@ -4,6 +4,9 @@
|
|
4
4
|
module SgtnClient
|
5
5
|
LOGFILE_SHIFT_AGE = 4
|
6
6
|
|
7
|
+
module Common
|
8
|
+
autoload :BundleID, "sgtn-client/common/data"
|
9
|
+
end
|
7
10
|
module Core
|
8
11
|
autoload :Cache, "sgtn-client/core/cache"
|
9
12
|
end
|
@@ -18,6 +21,7 @@ module SgtnClient
|
|
18
21
|
autoload :LocaleUtil, "sgtn-client/util/locale-util"
|
19
22
|
autoload :FileUtil, "sgtn-client/util/file-util"
|
20
23
|
autoload :CacheUtil, "sgtn-client/util/cache-util"
|
24
|
+
autoload :StringUtil, "sgtn-client/util/string-util"
|
21
25
|
|
22
26
|
module Formatters
|
23
27
|
autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
|
@@ -1,23 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright 2022 VMware, Inc.
|
2
4
|
# SPDX-License-Identifier: EPL-2.0
|
5
|
+
|
3
6
|
require 'set'
|
4
7
|
|
5
8
|
module SgtnClient
|
6
9
|
class LocaleUtil
|
7
10
|
MAP_LOCALES = {
|
8
|
-
'zh-
|
9
|
-
'zh-
|
10
|
-
'zh-
|
11
|
-
'zh-
|
11
|
+
'zh-cn' => 'zh-hans',
|
12
|
+
'zh-tw' => 'zh-hant',
|
13
|
+
'zh-hans-cn' => 'zh-hans',
|
14
|
+
'zh-hant-tw' => 'zh-hant'
|
12
15
|
}.freeze
|
16
|
+
LOCALE_SEPARATOR = '-'
|
13
17
|
|
14
18
|
def self.get_best_locale(locale)
|
19
|
+
return locale if Config.available_locales.include?(locale)
|
20
|
+
|
15
21
|
return get_fallback_locale if locale.nil?
|
16
22
|
|
17
23
|
locale = locale.to_s
|
18
24
|
return get_fallback_locale if locale.empty?
|
19
25
|
|
20
|
-
get_best_match(locale.gsub('_',
|
26
|
+
get_best_match(locale.gsub('_', LOCALE_SEPARATOR).downcase)
|
21
27
|
end
|
22
28
|
|
23
29
|
def self.is_source_locale(locale = nil)
|
@@ -26,12 +32,12 @@ module SgtnClient
|
|
26
32
|
|
27
33
|
def self.get_best_match(locale)
|
28
34
|
locale = MAP_LOCALES[locale] || locale
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
return get_fallback_locale if index.nil?
|
35
|
+
lowercase_locales_map[locale] or begin
|
36
|
+
index = locale.rindex(LOCALE_SEPARATOR)
|
37
|
+
return get_fallback_locale if index.nil?
|
33
38
|
|
34
|
-
|
39
|
+
get_best_match(locale[0...index])
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
def self.get_source_locale
|
@@ -47,6 +53,18 @@ module SgtnClient
|
|
47
53
|
@fallback_locale ||= get_default_locale || get_source_locale || 'en'
|
48
54
|
end
|
49
55
|
|
50
|
-
|
56
|
+
def self.lowercase_locales_map
|
57
|
+
@lowercase_locales_map ||= Config.available_locales.each_with_object({}) do |locale, memo|
|
58
|
+
memo[locale.to_s.downcase] = locale
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.reset_available_locales(type)
|
63
|
+
@lowercase_locales_map = nil if type == :available_locales
|
64
|
+
end
|
65
|
+
|
66
|
+
SgtnClient::Config.add_observer(self, :reset_available_locales)
|
67
|
+
|
68
|
+
private_class_method :get_best_match, :lowercase_locales_map, :reset_available_locales
|
51
69
|
end
|
52
70
|
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.0.
|
4
|
+
version: 0.7.0.39
|
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-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|