singleton-client-test 0.7.0.32 → 0.7.0.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -28
- data/lib/sgtn-client/api/source.rb +7 -65
- data/lib/sgtn-client/api/t.rb +16 -17
- data/lib/sgtn-client/api/translation.rb +77 -122
- data/lib/sgtn-client/common/data.rb +30 -0
- data/lib/sgtn-client/common/single_operation.rb +34 -0
- data/lib/sgtn-client/core/cache.rb +12 -81
- data/lib/sgtn-client/core/config.rb +35 -2
- data/lib/sgtn-client/exceptions.rb +6 -0
- data/lib/sgtn-client/loader/cache.rb +71 -0
- data/lib/sgtn-client/loader/chain_loader.rb +49 -0
- data/lib/sgtn-client/loader/consts.rb +15 -0
- data/lib/sgtn-client/loader/loader_factory.rb +33 -0
- data/lib/sgtn-client/loader/local_translation.rb +50 -0
- data/lib/sgtn-client/loader/server.rb +94 -0
- data/lib/sgtn-client/loader/single_loader.rb +46 -0
- data/lib/sgtn-client/loader/source.rb +53 -0
- data/lib/sgtn-client/loader/source_comparer.rb +58 -0
- data/lib/sgtn-client/sgtn-client.rb +1 -0
- data/lib/sgtn-client/util/cache-util.rb +30 -38
- data/lib/sgtn-client/util/locale-util.rb +44 -38
- data/lib/sgtn-client/util/string-util.rb +12 -0
- data/lib/sgtn-client/util/validate-util.rb +1 -6
- data/lib/singleton-client.rb +15 -0
- data/lib/singleton-ruby.rb +2 -0
- metadata +43 -147
- data/lib/sgtn-client/core/request.rb +0 -24
- data/lib/sgtn-client/util/file-util.rb +0 -37
@@ -1,46 +1,52 @@
|
|
1
1
|
# Copyright 2022 VMware, Inc.
|
2
2
|
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
require 'set'
|
3
4
|
|
4
5
|
module SgtnClient
|
6
|
+
class LocaleUtil
|
7
|
+
MAP_LOCALES = {
|
8
|
+
'zh-CN' => 'zh-Hans',
|
9
|
+
'zh-TW' => 'zh-Hant',
|
10
|
+
'zh-Hans-CN' => 'zh-Hans',
|
11
|
+
'zh-Hant-TW' => 'zh-Hant'
|
12
|
+
}.freeze
|
5
13
|
|
6
|
-
|
14
|
+
def self.get_best_locale(locale)
|
15
|
+
return get_fallback_locale if locale.nil?
|
7
16
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
def self.get_source_locale
|
41
|
-
env = SgtnClient::Config.default_environment
|
42
|
-
source_locale = SgtnClient::Config.configurations[env]["default_language"]
|
43
|
-
source_locale || 'en'
|
44
|
-
end
|
17
|
+
locale = locale.to_s
|
18
|
+
return get_fallback_locale if locale.empty?
|
19
|
+
|
20
|
+
get_best_match(locale.gsub('_', '-'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.is_source_locale(locale = nil)
|
24
|
+
locale == get_source_locale
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_best_match(locale)
|
28
|
+
locale = MAP_LOCALES[locale] || locale
|
29
|
+
return locale if Config.available_locales.include?(locale)
|
30
|
+
|
31
|
+
index = locale.rindex('-')
|
32
|
+
return get_fallback_locale if index.nil?
|
33
|
+
|
34
|
+
get_best_match(locale[0...index])
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.get_source_locale
|
38
|
+
'en'
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.get_default_locale
|
42
|
+
env = SgtnClient::Config.default_environment
|
43
|
+
SgtnClient::Config.configurations[env]['default_language']
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_fallback_locale
|
47
|
+
@fallback_locale ||= get_default_locale || get_source_locale || 'en'
|
45
48
|
end
|
49
|
+
|
50
|
+
private_class_method :get_best_match
|
51
|
+
end
|
46
52
|
end
|
@@ -14,12 +14,7 @@ module SgtnClient
|
|
14
14
|
if mode != 'sandbox' && mode != 'live'
|
15
15
|
messages = messages + "Configuration[mode] has to be 'sandbox' or 'live'!\n"
|
16
16
|
end
|
17
|
-
|
18
|
-
bundle_mode = SgtnClient::Config.configurations[env]["bundle_mode"]
|
19
|
-
if bundle_mode != 'offline' && bundle_mode != 'online'
|
20
|
-
messages = messages + "Configuration[bundle_mode] has to be 'offline' or 'online'!\n"
|
21
|
-
end
|
22
|
-
|
17
|
+
|
23
18
|
#version = SgtnClient::Config.configurations[env]["version"]
|
24
19
|
#if version.is_a? Integer
|
25
20
|
#messages = messages + "Configuration[version] has to be standard as '#.#.#, e.g '1.0.0'!\n"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
4
|
+
require_relative 'singleton-ruby'
|
5
|
+
|
6
|
+
module Singleton # :nodoc:
|
7
|
+
# load configuration from a file
|
8
|
+
def self.load_config(*args)
|
9
|
+
SgtnClient.load(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
extend SgtnClient::Translation::Implementation
|
13
|
+
|
14
|
+
private_class_method :getString, :getString_p, :getString_f, :getStrings
|
15
|
+
end
|
data/lib/singleton-ruby.rb
CHANGED
metadata
CHANGED
@@ -1,85 +1,35 @@
|
|
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.35
|
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-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: multi_json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: request_store
|
14
|
+
name: rdoc
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
44
16
|
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
|
-
- - "~>"
|
17
|
+
- - ">="
|
53
18
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
-
|
56
|
-
name: twitter_cldr
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
19
|
+
version: 2.4.2
|
20
|
+
- - "<"
|
60
21
|
- !ruby/object:Gem::Version
|
61
|
-
version: '6.
|
22
|
+
version: '6.0'
|
62
23
|
type: :development
|
63
24
|
prerelease: false
|
64
25
|
version_requirements: !ruby/object:Gem::Requirement
|
65
26
|
requirements:
|
66
|
-
- - "
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '6.6'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: webmock
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
27
|
+
- - ">="
|
74
28
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
29
|
+
version: 2.4.2
|
30
|
+
- - "<"
|
81
31
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
32
|
+
version: '6.0'
|
83
33
|
- !ruby/object:Gem::Dependency
|
84
34
|
name: rspec
|
85
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,54 +44,6 @@ dependencies:
|
|
94
44
|
- - "~>"
|
95
45
|
- !ruby/object:Gem::Version
|
96
46
|
version: '3.0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: pry-doc
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rdoc
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 2.4.2
|
132
|
-
- - "<"
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: '6.0'
|
135
|
-
type: :development
|
136
|
-
prerelease: false
|
137
|
-
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
requirements:
|
139
|
-
- - ">="
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: 2.4.2
|
142
|
-
- - "<"
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: '6.0'
|
145
47
|
- !ruby/object:Gem::Dependency
|
146
48
|
name: rubocop
|
147
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,93 +59,75 @@ dependencies:
|
|
157
59
|
- !ruby/object:Gem::Version
|
158
60
|
version: '0.49'
|
159
61
|
- !ruby/object:Gem::Dependency
|
160
|
-
name:
|
62
|
+
name: webmock
|
161
63
|
requirement: !ruby/object:Gem::Requirement
|
162
64
|
requirements:
|
163
|
-
- - "
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: 1.7.0
|
166
|
-
- - "<"
|
65
|
+
- - "~>"
|
167
66
|
- !ruby/object:Gem::Version
|
168
67
|
version: '2.0'
|
169
|
-
type: :
|
68
|
+
type: :development
|
170
69
|
prerelease: false
|
171
70
|
version_requirements: !ruby/object:Gem::Requirement
|
172
71
|
requirements:
|
173
|
-
- - "
|
174
|
-
- !ruby/object:Gem::Version
|
175
|
-
version: 1.7.0
|
176
|
-
- - "<"
|
72
|
+
- - "~>"
|
177
73
|
- !ruby/object:Gem::Version
|
178
74
|
version: '2.0'
|
179
75
|
- !ruby/object:Gem::Dependency
|
180
|
-
name:
|
76
|
+
name: faraday
|
181
77
|
requirement: !ruby/object:Gem::Requirement
|
182
78
|
requirements:
|
183
79
|
- - ">="
|
184
80
|
- !ruby/object:Gem::Version
|
185
|
-
version:
|
186
|
-
- - "<"
|
187
|
-
- !ruby/object:Gem::Version
|
188
|
-
version: '2.0'
|
81
|
+
version: '0'
|
189
82
|
type: :runtime
|
190
83
|
prerelease: false
|
191
84
|
version_requirements: !ruby/object:Gem::Requirement
|
192
85
|
requirements:
|
193
86
|
- - ">="
|
194
87
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
196
|
-
- - "<"
|
197
|
-
- !ruby/object:Gem::Version
|
198
|
-
version: '2.0'
|
88
|
+
version: '0'
|
199
89
|
- !ruby/object:Gem::Dependency
|
200
|
-
name:
|
90
|
+
name: faraday_middleware
|
201
91
|
requirement: !ruby/object:Gem::Requirement
|
202
92
|
requirements:
|
203
93
|
- - ">="
|
204
94
|
- !ruby/object:Gem::Version
|
205
|
-
version: '
|
206
|
-
- - "<"
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '4.0'
|
95
|
+
version: '0'
|
209
96
|
type: :runtime
|
210
97
|
prerelease: false
|
211
98
|
version_requirements: !ruby/object:Gem::Requirement
|
212
99
|
requirements:
|
213
100
|
- - ">="
|
214
101
|
- !ruby/object:Gem::Version
|
215
|
-
version: '
|
216
|
-
- - "<"
|
217
|
-
- !ruby/object:Gem::Version
|
218
|
-
version: '4.0'
|
102
|
+
version: '0'
|
219
103
|
- !ruby/object:Gem::Dependency
|
220
|
-
name:
|
104
|
+
name: multi_json
|
221
105
|
requirement: !ruby/object:Gem::Requirement
|
222
106
|
requirements:
|
223
107
|
- - "~>"
|
224
108
|
- !ruby/object:Gem::Version
|
225
|
-
version: '0
|
109
|
+
version: '1.0'
|
226
110
|
type: :runtime
|
227
111
|
prerelease: false
|
228
112
|
version_requirements: !ruby/object:Gem::Requirement
|
229
113
|
requirements:
|
230
114
|
- - "~>"
|
231
115
|
- !ruby/object:Gem::Version
|
232
|
-
version: '0
|
116
|
+
version: '1.0'
|
233
117
|
- !ruby/object:Gem::Dependency
|
234
|
-
name:
|
118
|
+
name: request_store
|
235
119
|
requirement: !ruby/object:Gem::Requirement
|
236
120
|
requirements:
|
237
|
-
- - "
|
121
|
+
- - ">="
|
238
122
|
- !ruby/object:Gem::Version
|
239
|
-
version: '
|
123
|
+
version: '0'
|
240
124
|
type: :runtime
|
241
125
|
prerelease: false
|
242
126
|
version_requirements: !ruby/object:Gem::Requirement
|
243
127
|
requirements:
|
244
|
-
- - "
|
128
|
+
- - ">="
|
245
129
|
- !ruby/object:Gem::Version
|
246
|
-
version: '
|
130
|
+
version: '0'
|
247
131
|
- !ruby/object:Gem::Dependency
|
248
132
|
name: twitter_cldr
|
249
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,17 +158,29 @@ files:
|
|
274
158
|
- lib/sgtn-client/cldr/localized_datetime.rb
|
275
159
|
- lib/sgtn-client/cldr/localized_str.rb
|
276
160
|
- lib/sgtn-client/cldr/localized_time.rb
|
161
|
+
- lib/sgtn-client/common/data.rb
|
162
|
+
- lib/sgtn-client/common/single_operation.rb
|
277
163
|
- lib/sgtn-client/core/cache.rb
|
278
164
|
- lib/sgtn-client/core/config.rb
|
279
165
|
- lib/sgtn-client/core/exceptions.rb
|
280
166
|
- lib/sgtn-client/core/logging.rb
|
281
|
-
- lib/sgtn-client/
|
167
|
+
- lib/sgtn-client/exceptions.rb
|
282
168
|
- lib/sgtn-client/formatters/plurals/plural_formatter.rb
|
169
|
+
- lib/sgtn-client/loader/cache.rb
|
170
|
+
- lib/sgtn-client/loader/chain_loader.rb
|
171
|
+
- lib/sgtn-client/loader/consts.rb
|
172
|
+
- lib/sgtn-client/loader/loader_factory.rb
|
173
|
+
- lib/sgtn-client/loader/local_translation.rb
|
174
|
+
- lib/sgtn-client/loader/server.rb
|
175
|
+
- lib/sgtn-client/loader/single_loader.rb
|
176
|
+
- lib/sgtn-client/loader/source.rb
|
177
|
+
- lib/sgtn-client/loader/source_comparer.rb
|
283
178
|
- lib/sgtn-client/sgtn-client.rb
|
284
179
|
- lib/sgtn-client/util/cache-util.rb
|
285
|
-
- lib/sgtn-client/util/file-util.rb
|
286
180
|
- lib/sgtn-client/util/locale-util.rb
|
181
|
+
- lib/sgtn-client/util/string-util.rb
|
287
182
|
- lib/sgtn-client/util/validate-util.rb
|
183
|
+
- lib/singleton-client.rb
|
288
184
|
- lib/singleton-ruby.rb
|
289
185
|
- lib/version.rb
|
290
186
|
homepage: https://github.com/vmware/singleton
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# Copyright 2022 VMware, Inc.
|
2
|
-
# SPDX-License-Identifier: EPL-2.0
|
3
|
-
|
4
|
-
require 'rest-client'
|
5
|
-
require 'multi_json'
|
6
|
-
|
7
|
-
module SgtnClient::Core
|
8
|
-
class Request
|
9
|
-
def self.get(url)
|
10
|
-
SgtnClient.logger.debug "[Request][get]url=#{url}"
|
11
|
-
res = RestClient::Resource.new(
|
12
|
-
url,
|
13
|
-
:verify_ssl => false
|
14
|
-
).get
|
15
|
-
begin
|
16
|
-
obj = MultiJson.load(res)
|
17
|
-
rescue MultiJson::ParseError => exception
|
18
|
-
exception.data
|
19
|
-
exception.cause
|
20
|
-
end
|
21
|
-
return obj
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# Copyright 2022 VMware, Inc.
|
2
|
-
# SPDX-License-Identifier: EPL-2.0
|
3
|
-
|
4
|
-
require 'erb'
|
5
|
-
require 'yaml'
|
6
|
-
|
7
|
-
module SgtnClient
|
8
|
-
|
9
|
-
class FileUtil
|
10
|
-
|
11
|
-
@mutex = Mutex.new
|
12
|
-
|
13
|
-
def self.read_json(bundlepath)
|
14
|
-
SgtnClient.logger.debug "[FileUtil]read json file from: " + bundlepath
|
15
|
-
@mutex.synchronize do
|
16
|
-
data_hash = nil
|
17
|
-
begin
|
18
|
-
file = File.read(bundlepath)
|
19
|
-
data_hash = MultiJson.load(file)
|
20
|
-
rescue => exception
|
21
|
-
SgtnClient.logger.error exception.message
|
22
|
-
end
|
23
|
-
return data_hash
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.read_yml(file_name)
|
28
|
-
SgtnClient.logger.debug "[FileUtil]read yml file from: " + file_name
|
29
|
-
@mutex.synchronize do
|
30
|
-
erb = ERB.new(File.read(file_name))
|
31
|
-
erb.filename = file_name
|
32
|
-
YAML.load(erb.result)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|