singleton-client 0.7.4 → 0.7.5
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/api/source.rb +4 -2
- data/lib/sgtn-client/api/t.rb +4 -1
- data/lib/sgtn-client/api/translation.rb +15 -4
- data/lib/sgtn-client/cldr/core_ext.rb +4 -1
- data/lib/sgtn-client/cldr/localized_date.rb +4 -1
- data/lib/sgtn-client/cldr/localized_datetime.rb +4 -1
- data/lib/sgtn-client/cldr/localized_str.rb +3 -1
- data/lib/sgtn-client/cldr/localized_time.rb +4 -1
- data/lib/sgtn-client/core/cache.rb +4 -1
- data/lib/sgtn-client/core/config.rb +4 -1
- data/lib/sgtn-client/core/exceptions.rb +3 -0
- data/lib/sgtn-client/core/logging.rb +3 -1
- data/lib/sgtn-client/core/request.rb +4 -1
- data/lib/sgtn-client/formatters/plurals/plural_formatter.rb +4 -1
- data/lib/sgtn-client/sgtn-client.rb +6 -1
- data/lib/sgtn-client/util/cache-util.rb +5 -8
- data/lib/sgtn-client/util/file-util.rb +4 -1
- data/lib/sgtn-client/util/locale-util.rb +16 -1
- data/lib/sgtn-client/util/validate-util.rb +3 -1
- data/lib/singleton-ruby.rb +3 -0
- data/lib/version.rb +2 -0
- 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: 662845b2e8dcbe69030049114857506ba0e2d5fd0ab98fdf886ddfd07ed1c7a8
|
4
|
+
data.tar.gz: bafa7b6a9f9d68e735ad1c830f37ea7f770381cafd7ff4ecda142d1673cec9c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3249cfcdce192e2e04670aefb03fd090c9b436171edeb80bec82d1d62816e8406d7aaaa92e3b85aec0d9e625babbab136d61e3e0d4ecf12d582c0fd99ad5a5c5
|
7
|
+
data.tar.gz: c694298fc391a1395ea62b4b3fe7595c5deae8fd1909d01af1b6097a03848583a81e5b0d52ef16339645bc74035f180feae9110cad56f0b67d082a95c72bb3e1
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
1
3
|
|
2
4
|
module SgtnClient
|
3
5
|
|
@@ -15,7 +17,7 @@ module SgtnClient
|
|
15
17
|
else
|
16
18
|
SgtnClient.logger.debug "[Source][getSource]getting sources from cache with key: " + cache_key
|
17
19
|
end
|
18
|
-
s = items.nil
|
20
|
+
s = (items.nil? || items[locale].nil?)? nil : items[locale][key]
|
19
21
|
if items.nil? || s.nil?
|
20
22
|
SgtnClient.logger.debug "[Source][getSource]source not found, return key: " + key
|
21
23
|
#return key
|
@@ -68,4 +70,4 @@ module SgtnClient
|
|
68
70
|
|
69
71
|
end
|
70
72
|
|
71
|
-
end
|
73
|
+
end
|
data/lib/sgtn-client/api/t.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
1
4
|
require 'multi_json'
|
2
5
|
|
3
6
|
module SgtnClient
|
@@ -56,6 +59,7 @@ module SgtnClient
|
|
56
59
|
|
57
60
|
def self.getStrings(component, locale)
|
58
61
|
SgtnClient.logger.debug "[Translation][getStrings]component=#{component}, locale=#{locale}"
|
62
|
+
locale = SgtnClient::LocaleUtil.get_best_locale(locale)
|
59
63
|
items = get_cs(component, locale)
|
60
64
|
default = SgtnClient::Config.configurations.default
|
61
65
|
if items.nil? || items["messages"] == nil
|
@@ -77,6 +81,7 @@ module SgtnClient
|
|
77
81
|
private
|
78
82
|
|
79
83
|
def self.getTranslation(component, key, locale)
|
84
|
+
locale = SgtnClient::LocaleUtil.get_best_locale(locale)
|
80
85
|
items = get_cs(component, locale)
|
81
86
|
if items.nil? || items["messages"] == nil
|
82
87
|
nil
|
@@ -86,12 +91,18 @@ module SgtnClient
|
|
86
91
|
end
|
87
92
|
|
88
93
|
def self.get_cs(component, locale)
|
89
|
-
|
90
|
-
|
94
|
+
# source locale always return source bundle
|
95
|
+
if locale == LocaleUtil.get_source_locale
|
96
|
+
sources = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
|
97
|
+
messages = sources&.first&.last
|
98
|
+
return {'locale' => locale, 'component' => component, 'messages' => messages} if messages
|
99
|
+
end
|
100
|
+
|
101
|
+
cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
|
91
102
|
SgtnClient.logger.debug "[Translation][get_cs]cache_key=#{cache_key}"
|
92
103
|
expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
|
93
104
|
if items.nil? || expired
|
94
|
-
items = load(component,
|
105
|
+
items = load(component, locale)
|
95
106
|
if items.nil?
|
96
107
|
items = SgtnClient::Source.getSources(component, SgtnClient::Config.configurations.default)
|
97
108
|
SgtnClient::Core::Cache.put(cache_key, items, 60)
|
@@ -144,4 +155,4 @@ module SgtnClient
|
|
144
155
|
|
145
156
|
end
|
146
157
|
|
147
|
-
end
|
158
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
1
4
|
require 'sgtn-client/cldr/localized_datetime'
|
2
5
|
require 'sgtn-client/cldr/localized_date'
|
3
6
|
require 'sgtn-client/cldr/localized_time'
|
4
|
-
require 'sgtn-client/cldr/localized_str'
|
7
|
+
require 'sgtn-client/cldr/localized_str'
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
1
4
|
require 'date'
|
2
5
|
require 'time'
|
3
6
|
|
@@ -24,4 +27,4 @@ Date.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
|
24
27
|
def l_short_s(locale = TwitterCldr.locale)
|
25
28
|
self.to_datetime().localize(locale).to_date().to_short_s
|
26
29
|
end
|
27
|
-
LOCALIZE
|
30
|
+
LOCALIZE
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
1
4
|
require 'date'
|
2
5
|
require 'time'
|
3
6
|
|
@@ -60,4 +63,4 @@ DateTime.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
|
60
63
|
tz.display_name_for(self, display_name)
|
61
64
|
end
|
62
65
|
end
|
63
|
-
LOCALIZE
|
66
|
+
LOCALIZE
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
1
3
|
|
2
4
|
String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
3
5
|
def to_plural_s(locale, arg)
|
@@ -8,4 +10,4 @@ String.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
|
8
10
|
num_str
|
9
11
|
end
|
10
12
|
end
|
11
|
-
LOCALIZE
|
13
|
+
LOCALIZE
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
1
4
|
require 'date'
|
2
5
|
require 'time'
|
3
6
|
|
@@ -24,4 +27,4 @@ Time.class_eval <<-LOCALIZE, __FILE__, __LINE__ + 1
|
|
24
27
|
def l_short_s(locale = TwitterCldr.locale)
|
25
28
|
self.localize(locale).to_short_s
|
26
29
|
end
|
27
|
-
LOCALIZE
|
30
|
+
LOCALIZE
|
@@ -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
|
@@ -44,7 +49,7 @@ module SgtnClient
|
|
44
49
|
end
|
45
50
|
file = File.open(file, 'a')
|
46
51
|
file.sync = true
|
47
|
-
SgtnClient.logger = Logger.new(file)
|
52
|
+
SgtnClient.logger = Logger.new(file, LOGFILE_SHIFT_AGE)
|
48
53
|
|
49
54
|
# Set log level for sandbox mode
|
50
55
|
env = SgtnClient::Config.default_environment
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
1
4
|
require 'erb'
|
2
5
|
require 'yaml'
|
3
6
|
|
@@ -38,14 +41,8 @@ module SgtnClient
|
|
38
41
|
env = SgtnClient::Config.default_environment
|
39
42
|
product_name = SgtnClient::Config.configurations[env]["product_name"]
|
40
43
|
version = SgtnClient::Config.configurations[env]["version"].to_s
|
41
|
-
|
42
|
-
if default_l == nil
|
43
|
-
default_l = 'en'
|
44
|
-
end
|
45
|
-
lc = locale == default_l ? SgtnClient::Config.configurations.default: locale
|
46
|
-
SgtnClient.logger.debug "[CacheUtil]get cache key: #{lc}"
|
47
|
-
return product_name + "_" + version + "_" + component + "_" + lc
|
44
|
+
product_name + "_" + version + "_" + component + "_" + locale
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
51
|
-
end
|
48
|
+
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Copyright 2022 VMware, Inc.
|
2
|
+
# SPDX-License-Identifier: EPL-2.0
|
3
|
+
|
1
4
|
module SgtnClient
|
2
5
|
|
3
6
|
DEFAULT_LOCALES = ['en', 'de', 'es', 'fr', 'ko', 'ja', 'zh-Hans', 'zh-Hant']
|
@@ -10,6 +13,13 @@ module SgtnClient
|
|
10
13
|
}
|
11
14
|
|
12
15
|
class LocaleUtil
|
16
|
+
def self.get_best_locale(locale)
|
17
|
+
fallback(process_locale(locale))
|
18
|
+
end
|
19
|
+
def self.process_locale(locale=nil)
|
20
|
+
locale ||= SgtnClient::Config.configurations.default
|
21
|
+
locale.to_s
|
22
|
+
end
|
13
23
|
def self.fallback(locale)
|
14
24
|
found = SgtnClient::DEFAULT_LOCALES.select {|e| e == locale}
|
15
25
|
if !found.empty?
|
@@ -27,5 +37,10 @@ module SgtnClient
|
|
27
37
|
end
|
28
38
|
return locale
|
29
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
|
30
45
|
end
|
31
|
-
end
|
46
|
+
end
|
data/lib/singleton-ruby.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
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-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|