wovnrb 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +50 -31
- data/lib/wovnrb/api_translator.rb +2 -0
- data/lib/wovnrb/store.rb +14 -0
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/api_translator_test.rb +18 -3
- data/test/lib/store_test.rb +36 -0
- data/wovnrb.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2914e87079803ec545cf0d8af1e225752cd1574b
|
4
|
+
data.tar.gz: 503907d34e84bd4bdf89c344ebb8f3716a9ae353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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 => '
|
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 => '
|
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
|
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.
|
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
|
-
|
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
|
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.
|
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
|
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
|
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.
|
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
|
145
|
+
This sets "Ignore class" which prevents WOVN from translating HTML elements that have a class contained in this array.
|
127
146
|
|
128
|
-
### 2.
|
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
|
-
|
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)
|
data/lib/wovnrb/version.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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:
|
89
|
+
.to_return(status: response[:status_code] || 200, body: stub_response, headers: response_headers)
|
75
90
|
|
76
91
|
stub
|
77
92
|
end
|
data/test/lib/store_test.rb
CHANGED
@@ -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', '
|
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.
|
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:
|
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.
|
451
|
+
rubygems_version: 2.2.0
|
452
452
|
signing_key:
|
453
453
|
specification_version: 4
|
454
454
|
summary: Gem for WOVN.io
|