wovnrb 2.0.1 → 2.0.2

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
  SHA1:
3
- metadata.gz: ce9217e8e741e4c5e658511a29459a675d203311
4
- data.tar.gz: a7d6ee08c00f2e07179b7d70b0a9f21828c5b4bf
3
+ metadata.gz: 2914e87079803ec545cf0d8af1e225752cd1574b
4
+ data.tar.gz: 503907d34e84bd4bdf89c344ebb8f3716a9ae353
5
5
  SHA512:
6
- metadata.gz: bf238b6e346db998dbedc89ed1a5cb0887aa291a2fa0027c636334282fc92becdfa45bc16eba2f4344a117c21c79cc1005f64eed8608f1fa0211a27d5d15da76
7
- data.tar.gz: 1338a1cced911df557811a82b3086a1fd778475528e65640b2884717aae15664f88e3684d4a0a9d37699812d08ec58e323912b4741cb5012b211b562fac5f6cc
6
+ metadata.gz: 6752dea082bdd0f58fea2bd8c0f6ae4364b3217da3c351697f5f0a20ad19c3e667f1300d54db0bfb5efd4da657c9ae52933a1b829a64f1b060efa0707af16a53
7
+ data.tar.gz: 59e9a8316c3d53aface8c5d8614eff4f3fa0ce2c0e79dd92699b618c05ba2df3f4199bdd52692d322467899c16e81085fe5f053e9eabd9795be2b63dac3b1f91
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The WOVN.io Ruby library is a library that uses WOVN.io in order to provide translations. The WOVN.io Ruby Library is packaged as Rack Middleware.
4
4
 
5
- This document explains the the process of installing WOVN.io Ruby, as well as set up and configuration.
5
+ This document explains the process of installing WOVN.io Ruby, as well as set up and configuration process.
6
6
 
7
7
  ## 1. Install
8
8
 
@@ -12,7 +12,7 @@ In order to use the WOVN.io Ruby Library, you need a WOVN.io account. If you do
12
12
 
13
13
  ### 1.2. Adding a Page
14
14
 
15
- After logging into WOVN.io, add a page you would like translated.
15
+ After logging into WOVN.io, add a page that you would like translated.
16
16
 
17
17
  ### 1.3. Ruby Application Settings
18
18
 
@@ -38,7 +38,10 @@ Insert the following into either config/application.rb or config/environments/.
38
38
  ...
39
39
 
40
40
  config.wovnrb = {
41
- :project_token => '2Wle3'
41
+ :project_token => 'EnS!t3',
42
+ :default_lang => 'en',
43
+ :supported_langs => ['en'],
44
+ :url_pattern => 'path'
42
45
  }
43
46
 
44
47
  ...
@@ -54,7 +57,10 @@ Insert the following into either the Application File or config.ru.
54
57
  require 'wovnrb'
55
58
 
56
59
  use Wovnrb::Interceptor, {
57
- :project_token => '2Wle3'
60
+ :project_token => 'EnS!t3',
61
+ :default_lang => 'en',
62
+ :supported_langs => ['en'],
63
+ :url_pattern => 'path'
58
64
  }
59
65
 
60
66
  ...
@@ -64,14 +70,15 @@ After completing setup, start the Ruby Application, and make sure the WOVN.io li
64
70
 
65
71
  ## 2. Parameter Setting
66
72
 
67
- WOVN.io Ruby Library's valid parameters are as follows.
73
+ The following is a list of the WOVN.io Ruby Library's valid parameters.
68
74
 
69
75
  Parameter Name | Required | Default Setting
70
76
  ------------------ | -------- | ----------------
71
77
  project_token | yes | ''
78
+ default_lang | yes | 'en'
79
+ supported_langs | yes | ['en']
72
80
  url_pattern | yes | 'path'
73
81
  query | | []
74
- default_lang | yes | 'en'
75
82
  ignore_class | | []
76
83
  translate_fragment | | true
77
84
 
@@ -79,9 +86,35 @@ translate_fragment | | true
79
86
 
80
87
  Set your WOVN.io Account's Project token. This parameter is required.
81
88
 
82
- ### 2.2. url_pattern
89
+ ### 2.2. default_lang
90
+
91
+ This sets the Ruby application's default language. The default value is English ('en').
92
+
93
+ If, for a requested page, the default language parameter is included in the URL, the request is redirected before translating. The default_lang parameter is used for this purpose.
94
+
95
+ If the default_lang is set to 'en', when receiving a request for the following URL,
96
+
97
+ https://wovn.io/en/contact
98
+
99
+ Then the library will redirect to the following URL.
100
+
101
+ https://wovn.io/contact
102
+
103
+ ### 2.3. supported_langs
104
+ This tells the library which languages are being used on the website (including
105
+ the original language). This setting allows for inserting metadata necessary for
106
+ SEO (Search Engine Optimization).
107
+
108
+ If your website is in English and you are using WOVN.io to localize it in
109
+ Japanese, then you should use the following setting:
110
+ ```
111
+ :supported_langs => ['en', 'ja']
112
+ ```
113
+ **Note:** The order of the languages in the list does not matter.
83
114
 
84
- The Library works in the Ruby Application by adding new URL's to be translated. You can set the type of url with the url_pattern parameter. There are 3 types that can be set.
115
+ ### 2.4. url_pattern
116
+
117
+ The Library works in the Ruby Application by adding new URLs to be translated. You can set the type of url with the `url_pattern` parameter. There are 3 types that can be set.
85
118
 
86
119
  parameters | Translated page's URL | Notes
87
120
  ----------- | ------------------------------- | -------
@@ -89,47 +122,33 @@ parameters | Translated page's URL | Notes
89
122
  'subdomain' | https://ja.wovn.io/contact | DNS settings must be set.
90
123
  'query' | https://wovn.io/contact?wovn=ja | The least amount of changes to the application required to complete setup.
91
124
 
92
- ※ The following is an example of a URL that has been translated by the library using the above URL's.
125
+ ※ The following is an example of a URL that has been translated by the library using the above URLs.
93
126
 
94
127
  https://wovn.io/contact
95
128
 
96
- ### 2.3. query
129
+ ### 2.5. query
97
130
 
98
- WOVN.io ignores query parameters when searching translated page. If you want to add query parameter to translated page's URL, you should configure "query" parameter. (You need to configure WOVN.io too)
131
+ WOVN.io ignores query parameters when searching a translated page. If you want to add a query parameter to translated page's URL, you should configure the `query` parameter. (You need to configure WOVN.io too)
99
132
 
100
133
  https://wovn.io/ja/contact?os=mac&keyboard=us
101
134
 
102
- If the defualt_lang is 'en', and the query is set to '', the above URL will be modified into the following URL to search for the page's translation.
135
+ If the `default_lang` is 'en', and the query is set to '', the above URL will be modified into the following URL to search for the page's translation.
103
136
 
104
137
  https://wovn.io/contact
105
138
 
106
- If the default_lang is 'en', and the query is set to 'os', the above URL will be modified into the following URL to search for the page's translation.
139
+ If the `default_lang` is 'en', and the query is set to 'os', the above URL will be modified into the following URL to search for the page's translation.
107
140
 
108
141
  https://wovn.io/contact?os=mac
109
142
 
110
- ### 2.4. default_lang
111
-
112
- This sets the Ruby application's default language. The default value is English ('en').
113
-
114
- If a requested page, where the default language's parameter is included in the URL, the request is redirected before translating. The default_lang parameter is used for this purpose.
115
-
116
- If the default_lang is set to 'en', when receiving a request for the following URL,
117
-
118
- https://wovn.io/en/contact
119
-
120
- The library will redirect to the following URL.
121
-
122
- https://wovn.io/contact
123
-
124
- ### 2.5 ignore_class
143
+ ### 2.6. ignore_class
125
144
 
126
- This sets "Ignore class" which prevent WOVN translating HTML elements that have one of the array.
145
+ This sets "Ignore class" which prevents WOVN from translating HTML elements that have a class contained in this array.
127
146
 
128
- ### 2.6 translate_fragment
147
+ ### 2.7. translate_fragment
129
148
 
130
149
  This option allows to disable translating partial HTML content. By default,
131
150
  partial HTML content is translated but no widget snippet is added. Set
132
- "translate_fragment" to 'false' to stop translating partial HTML content.
151
+ `translate_fragment` to `false` to prevent translating partial HTML content.
133
152
 
134
153
  ## 3. Contributing
135
154
 
@@ -27,6 +27,8 @@ module Wovnrb
27
27
  response_body = Zlib::GzipReader.new(StringIO.new(response.body)).read
28
28
 
29
29
  JSON.parse(response_body)['body'] || body
30
+ elsif @store.dev_mode?
31
+ JSON.parse(response.body)['body'] || body
30
32
  else
31
33
  WovnLogger.error("Received invalid content (\"#{response.header['Content-Encoding']}\") from WOVNio translation API.")
32
34
  body
data/lib/wovnrb/store.rb CHANGED
@@ -153,6 +153,16 @@ module Wovnrb
153
153
  else
154
154
  true
155
155
  end
156
+
157
+ if @settings['wovn_dev_mode']
158
+ if @settings['api_url'] == self.class.default_settings['api_url']
159
+ @settings['api_url'] = 'http://dev-wovn.io:3001/v0/'
160
+ end
161
+
162
+ if @settings['api_timeout_seconds'] == self.class.default_settings['api_timeout_seconds']
163
+ @settings['api_timeout_seconds'] = 3
164
+ end
165
+ end
156
166
  end
157
167
 
158
168
  def custom_lang_aliases
@@ -180,6 +190,10 @@ module Wovnrb
180
190
  end
181
191
  end
182
192
 
193
+ def dev_mode?
194
+ @settings['wovn_dev_mode']
195
+ end
196
+
183
197
  private
184
198
 
185
199
  def stringify_keys!(hash)
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
@@ -19,6 +19,11 @@ module Wovnrb
19
19
  assert_translation('test.html', 'test_translated.html', false, encoding: 'unknown')
20
20
  end
21
21
 
22
+ def test_translate_accepts_uncompressed_response_from_api_in_dev_mode
23
+ Wovnrb::Store.instance.update_settings('wovn_dev_mode' => true)
24
+ assert_translation('test.html', 'test_translated.html', true, encoding: 'text/json')
25
+ end
26
+
22
27
  private
23
28
 
24
29
  def assert_translation(original_html_fixture, translated_html_fixture, success_expected, response = { encoding: 'gzip', status_code: 200 })
@@ -58,7 +63,12 @@ module Wovnrb
58
63
  def stub_translation_api_request(store, headers, original_html, translated_html, response)
59
64
  if response
60
65
  cache_key = generate_cache_key(store, original_html)
61
- api_url = "wovn.global.ssl.fastly.net/v0/translation?cache_key=#{cache_key}"
66
+ api_host = if store.dev_mode?
67
+ 'dev-wovn.io:3001'
68
+ else
69
+ 'wovn.global.ssl.fastly.net'
70
+ end
71
+ api_url = "http://#{api_host}/v0/translation?cache_key=#{cache_key}"
62
72
  compressed_data = compress(generate_data(original_html))
63
73
  headers = {
64
74
  'Accept' => '*/*',
@@ -67,11 +77,16 @@ module Wovnrb
67
77
  'Content-Type' => 'application/octet-stream',
68
78
  'User-Agent' => 'Ruby'
69
79
  }
70
- compressed_response = compress("{\"body\":\"#{translated_html.gsub("\n", '\n')}\"}")
80
+ stub_response_json = "{\"body\":\"#{translated_html.gsub("\n", '\n')}\"}"
81
+ stub_response = if store.dev_mode?
82
+ stub_response_json
83
+ else
84
+ compress(stub_response_json)
85
+ end
71
86
  response_headers = { 'Content-Encoding' => response[:encoding] || 'gzip' }
72
87
  stub = stub_request(:post, api_url)
73
88
  .with(body: compressed_data, headers: headers)
74
- .to_return(status: response[:status_code] || 200, body: compressed_response, headers: response_headers)
89
+ .to_return(status: response[:status_code] || 200, body: stub_response, headers: response_headers)
75
90
 
76
91
  stub
77
92
  end
@@ -104,6 +104,42 @@ module Wovnrb
104
104
  assert_equal([], s.settings['ignore_globs'])
105
105
  end
106
106
 
107
+ def test_default_dev_mode_settings
108
+ store = Wovnrb::Store.instance
109
+
110
+ store.update_settings('wovn_dev_mode' => true)
111
+
112
+ assert(store.dev_mode?)
113
+ assert_equal('http://dev-wovn.io:3001/v0/', store.settings['api_url'])
114
+ assert_equal(3, store.settings['api_timeout_seconds'])
115
+ end
116
+
117
+ def test_dev_mode_not_overriding_settings
118
+ store = Wovnrb::Store.instance
119
+
120
+ store.update_settings(
121
+ 'wovn_dev_mode' => true,
122
+ 'api_url' => 'http://my-test-api.wovn.io/v0/',
123
+ 'api_timeout_seconds' => 42
124
+ )
125
+
126
+ assert(store.dev_mode?)
127
+ assert_equal('http://my-test-api.wovn.io/v0/', store.settings['api_url'])
128
+ assert_equal(42, store.settings['api_timeout_seconds'])
129
+ end
130
+
131
+ def test_dev_mode?
132
+ store = Wovnrb::Store.instance
133
+
134
+ assert_equal(false, store.settings['wovn_dev_mode'])
135
+ assert(!store.dev_mode?)
136
+
137
+ store.update_settings('wovn_dev_mode' => true)
138
+
139
+ assert_equal(true, store.settings['wovn_dev_mode'])
140
+ assert(store.dev_mode?)
141
+ end
142
+
107
143
  def test_valid_user_token
108
144
  mock = LogMock.mock_log
109
145
  store = Wovnrb::Store.instance
data/wovnrb.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'nokogumbo', '>= 1.4.0', '< 2.0.0'
27
27
  spec.add_dependency 'rack'
28
28
 
29
- spec.add_development_dependency 'bundler', '~> 1.7'
29
+ spec.add_development_dependency 'bundler', '>= 1.7'
30
30
  spec.add_development_dependency 'guard'
31
31
  spec.add_development_dependency 'guard-rspec'
32
32
  spec.add_development_dependency 'listen', '~> 3.0.6'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wovnrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-06 00:00:00.000000000 Z
12
+ date: 2019-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -105,14 +105,14 @@ dependencies:
105
105
  name: bundler
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.7'
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '1.7'
118
118
  - !ruby/object:Gem::Dependency
@@ -448,7 +448,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
448
448
  version: '0'
449
449
  requirements: []
450
450
  rubyforge_project:
451
- rubygems_version: 2.4.5.4
451
+ rubygems_version: 2.2.0
452
452
  signing_key:
453
453
  specification_version: 4
454
454
  summary: Gem for WOVN.io