singleton-ruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/lib/sgtn-client/api/source.rb +13 -0
- data/lib/sgtn-client/api/translation.rb +20 -2
- data/lib/version.rb +1 -1
- data/spec/unit/offclient_spec.rb +8 -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: bcc331c8950f6406499f27695bb3e7973745acd2b7a07454b5482f28ee7ba693
|
4
|
+
data.tar.gz: 9630c5e08d8e51c942da3df7dd58583499ca912e7a801b499c939c0022bca66e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38177b4b4e74294988cfcfa5a23046f3bcaa0494f3287d69cc3e7a786863e6ca5c833f621cad746f602e8071bafa55a15a3d22d63addbfe13248bd6a421ca533
|
7
|
+
data.tar.gz: e705db8c097ce7eb685fccc7258d5bbdfa725087cf84ea08cb41d1acb08fe224282de166fca611be0b54860ecf51bd291bee940b526df3a0fdcb1e1fc2e00785
|
data/README.md
CHANGED
@@ -7,5 +7,31 @@
|
|
7
7
|
## Run Unit Test
|
8
8
|
rake spec:unit
|
9
9
|
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Basic Usage:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'singleton-ruby'
|
16
|
+
|
17
|
+
include SgtnClient
|
18
|
+
|
19
|
+
SgtnClient.load(file, mode)
|
20
|
+
|
21
|
+
SgtnClient::Source.loadBundles(locale)
|
22
|
+
|
23
|
+
@Result = SgtnClient::Translation.getString(component, key, locale)
|
24
|
+
|
25
|
+
```
|
26
|
+
## API
|
27
|
+
|
28
|
+
### Get a string's translation
|
29
|
+
SgtnClient::Translation.getString(component, key, locale)
|
30
|
+
|
31
|
+
### Get a string's translation and format it with placeholders
|
32
|
+
SgtnClient::Translation.getString_F(component, key, args, locale)
|
33
|
+
|
34
|
+
|
35
|
+
|
10
36
|
|
11
37
|
|
@@ -24,6 +24,19 @@ module SgtnClient
|
|
24
24
|
return str
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.getSources(component, locale)
|
28
|
+
cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
|
29
|
+
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
30
|
+
if items.nil?
|
31
|
+
items = getBundle(component, locale)
|
32
|
+
SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
|
33
|
+
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
34
|
+
else
|
35
|
+
SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
|
36
|
+
end
|
37
|
+
return itmes
|
38
|
+
end
|
39
|
+
|
27
40
|
def self.loadBundles(locale)
|
28
41
|
env = SgtnClient::Config.default_environment
|
29
42
|
SgtnClient::Config.configurations.default = locale
|
@@ -32,8 +32,7 @@ module SgtnClient
|
|
32
32
|
else
|
33
33
|
return str
|
34
34
|
end
|
35
|
-
|
36
|
-
end
|
35
|
+
end
|
37
36
|
|
38
37
|
def self.getString_f(component, key, args, locale)
|
39
38
|
s = getString(component, key, locale)
|
@@ -43,6 +42,25 @@ module SgtnClient
|
|
43
42
|
return s % args
|
44
43
|
end
|
45
44
|
|
45
|
+
def self.getStrings(component, locale)
|
46
|
+
flocale = SgtnClient::LocaleUtil.fallback(locale)
|
47
|
+
cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
|
48
|
+
items = SgtnClient::CacheUtil.get_cache(cache_key)
|
49
|
+
if items.nil?
|
50
|
+
items = getTranslations(component, flocale)
|
51
|
+
SgtnClient::CacheUtil.write_cache(cache_key, items)
|
52
|
+
else
|
53
|
+
SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
|
54
|
+
end
|
55
|
+
|
56
|
+
default = SgtnClient::Config.configurations.default
|
57
|
+
if items.nil? || items["messages"] == nil
|
58
|
+
items = SgtnClient::Source.getSources(component, default)
|
59
|
+
end
|
60
|
+
return items
|
61
|
+
end
|
62
|
+
|
63
|
+
|
46
64
|
private
|
47
65
|
|
48
66
|
def self.getTranslations(component, locale)
|
data/lib/version.rb
CHANGED
data/spec/unit/offclient_spec.rb
CHANGED
@@ -40,6 +40,14 @@ describe SgtnClient do
|
|
40
40
|
# get from cache in 2nd time
|
41
41
|
expect(SgtnClient::Translation.getString_f("JAVA", "login", ["Robot", "VM"], "zh-Hans")).to eq 'Robot login VM!'
|
42
42
|
end
|
43
|
+
|
44
|
+
it "Component" do
|
45
|
+
jsonObj = SgtnClient::Translation.getStrings("JAVA", "zh-Hans");
|
46
|
+
expect(jsonObj["component"]).to eq 'JAVA'
|
47
|
+
# get from cache in 2nd time
|
48
|
+
jsonObj_c = SgtnClient::Translation.getStrings("JAVA", "zh-Hans");
|
49
|
+
expect(jsonObj_c["component"]).to eq 'JAVA'
|
50
|
+
end
|
43
51
|
end
|
44
52
|
|
45
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
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: 2021-08-
|
11
|
+
date: 2021-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|