singleton-ruby 0.1.3 → 0.1.4

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: c2e092b1d69a9639d976877f5ad64486ebe37a6d64bdaef84f1aa10a1424ae6e
4
- data.tar.gz: 42f5c443bf2e9a20004ba147586de5088d9fdb1a7cd56b422f0b8fff85ea82ec
3
+ metadata.gz: ffce54daa3338aaac24e5f302d46ea2b0d786def7c20dc5d737d5f8e839844d2
4
+ data.tar.gz: 934df8d9afc326b09981f12460e822db864ccb35f3e992c67b066689258343bf
5
5
  SHA512:
6
- metadata.gz: 4e269b9d4dc398a51491bcaa8c71304c360cc082cce8bc6f49ca07ddd7d72849f26341d65d1700e452eb5976197eb5a95542f09e9bf1aa595e2448becd894353
7
- data.tar.gz: d8230f6464e7c1c4f940665f55bfb0fdb577553c980b844ecd45803e77ee3ca4ffdf346c67deec784daf17d94fc2bd2cbbdf2ed8e4b9eb565f24a12d3191f788
6
+ metadata.gz: 6ec453c3a483d728b165cf734a2aaf361f4be3582579ec1853b49aa9ac3ece43fd1ffb1215b42a13bb90662ad53c16d723eb8123a747d7a5aeeb3bc22310639a
7
+ data.tar.gz: 2a073e29ebe320b9336156d80832f89f1b05300398d8ca5fb0551cc51772aa33359ee71652d0bc538d7e29e6f52b44bebc054232ec9bf06b22a7368710d61329
data/README.md CHANGED
@@ -29,7 +29,25 @@ SgtnClient::Source.loadBundles(locale)
29
29
  SgtnClient::Translation.getString(component, key, locale)
30
30
 
31
31
  ### Get a string's translation and format it with placeholders
32
- SgtnClient::Translation.getString_F(component, key, args, locale)
32
+ SgtnClient::Translation.getString_f(component, key, args, locale)
33
+
34
+ ### Get a component's translations
35
+ SgtnClient::Translation.getStrings(component, locale)
36
+
37
+
38
+ ## API with request_store
39
+
40
+ Before call below APIs(without locale and component arguments), it requires to set the locale
41
+ and component add the initial codes.
42
+
43
+ ### Get a string's translation
44
+ SgtnClient::T.s(key)
45
+
46
+ ### Get a string's translation and format it with placeholders
47
+ SgtnClient::T.s_f(key, args)
48
+
49
+ ### Get a component's translations
50
+ SgtnClient::T.c()
33
51
 
34
52
 
35
53
 
@@ -2,7 +2,7 @@ require 'erb'
2
2
  require 'yaml'
3
3
 
4
4
  module SgtnClient
5
-
5
+
6
6
  autoload :CacheUtil, "sgtn-client/util/cache-util"
7
7
 
8
8
  class Source
@@ -41,18 +41,16 @@ module SgtnClient
41
41
  env = SgtnClient::Config.default_environment
42
42
  SgtnClient::Config.configurations.default = locale
43
43
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
44
- SgtnClient.logger.debug "Loading [" + locale + "] bundles from path: " + source_bundle
44
+ SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
45
45
  Dir.children(source_bundle).each do |component|
46
46
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
47
47
  bundle = read_yml(yamlfile)
48
48
  cachekey = SgtnClient::CacheUtil.get_cachekey(component, locale)
49
49
  SgtnClient::CacheUtil.write_cache(cachekey,bundle)
50
50
  end
51
-
52
51
  end
53
52
 
54
53
  private
55
-
56
54
  def self.getBundle(component, locale)
57
55
  env = SgtnClient::Config.default_environment
58
56
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
@@ -71,7 +69,6 @@ module SgtnClient
71
69
  erb.filename = file_name
72
70
  YAML.load(erb.result)
73
71
  end
74
-
75
72
  end
76
73
 
77
74
  end
@@ -0,0 +1,22 @@
1
+ module SgtnClient
2
+ class T < Translation
3
+
4
+ def self.s(key)
5
+ locale = RequestStore.store[:locale]
6
+ component = RequestStore.store[:component]
7
+ return getString(component, key, locale)
8
+ end
9
+
10
+ def self.s_f(key, args)
11
+ locale = RequestStore.store[:locale]
12
+ component = RequestStore.store[:component]
13
+ return getString_f(component, key, args, locale)
14
+ end
15
+
16
+ def self.c()
17
+ locale = RequestStore.store[:locale]
18
+ component = RequestStore.store[:component]
19
+ return getStrings(component, locale)
20
+ end
21
+ end
22
+ end
@@ -4,6 +4,7 @@ module SgtnClient
4
4
  end
5
5
 
6
6
  autoload :Translation, "sgtn-client/api/translation"
7
+ autoload :T, "sgtn-client/api/t"
7
8
  autoload :Source, "sgtn-client/api/source"
8
9
  autoload :Config, "sgtn-client/core/config"
9
10
  autoload :Logging, "sgtn-client/core/logging"
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 1, 3].freeze
2
+ VERSION_INFO = [0, 1, 4].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'request_store'
3
+
4
+ describe SgtnClient do
5
+ describe "Locale" do
6
+
7
+ before :each do
8
+ env = SgtnClient::Config.default_environment
9
+ SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
10
+ SgtnClient::Source.loadBundles("default")
11
+ RequestStore.store[:locale] = 'zh-Hans'
12
+ RequestStore.store[:component] = 'JAVA'
13
+ end
14
+
15
+ it "GET" do
16
+ expect(SgtnClient::T.s("helloworld")).to eq '你好世界'
17
+ expect(SgtnClient::T.s_f("welcome", ["机器人", "虚拟世界"])).to eq '机器人,欢迎登录虚拟世界!'
18
+ expect(SgtnClient::T.c()["component"]).to eq 'JAVA'
19
+ end
20
+ end
21
+
22
+ 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.3
4
+ version: 0.1.4
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-25 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: request_store
43
+ requirement: !ruby/object:Gem::Requirement
44
+ 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
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: webmock
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -216,20 +230,6 @@ dependencies:
216
230
  - - "~>"
217
231
  - !ruby/object:Gem::Version
218
232
  version: '1.0'
219
- - !ruby/object:Gem::Dependency
220
- name: twitter_cldr
221
- requirement: !ruby/object:Gem::Requirement
222
- requirements:
223
- - - "~>"
224
- - !ruby/object:Gem::Version
225
- version: '6.6'
226
- type: :runtime
227
- prerelease: false
228
- version_requirements: !ruby/object:Gem::Requirement
229
- requirements:
230
- - - "~>"
231
- - !ruby/object:Gem::Version
232
- version: '6.6'
233
233
  description: Singleton Ruby client
234
234
  email: g11n-vip-project@vmware.com
235
235
  executables: []
@@ -241,6 +241,7 @@ files:
241
241
  - README.md
242
242
  - Rakefile
243
243
  - lib/sgtn-client/api/source.rb
244
+ - lib/sgtn-client/api/t.rb
244
245
  - lib/sgtn-client/api/translation.rb
245
246
  - lib/sgtn-client/core/cache.rb
246
247
  - lib/sgtn-client/core/config.rb
@@ -274,6 +275,7 @@ files:
274
275
  - spec/unit/logging_spec.rb
275
276
  - spec/unit/offclient_spec.rb
276
277
  - spec/unit/onclient_spec.rb
278
+ - spec/unit/request_spec.rb
277
279
  - spec/unit/version_spec.rb
278
280
  homepage: https://github.com/vmware/singleton
279
281
  licenses:
@@ -320,4 +322,5 @@ test_files:
320
322
  - spec/unit/logging_spec.rb
321
323
  - spec/unit/offclient_spec.rb
322
324
  - spec/unit/onclient_spec.rb
325
+ - spec/unit/request_spec.rb
323
326
  - spec/unit/version_spec.rb