wovnrb 3.7.2 → 3.9.0
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/Gemfile +28 -0
- data/README.en.md +44 -15
- data/README.ja.md +51 -20
- data/README.md +1 -1
- data/docker/rails/TestSite/yarn.lock +207 -180
- data/lib/wovnrb/api_translator.rb +5 -0
- data/lib/wovnrb/custom_domain/custom_domain_lang.rb +31 -0
- data/lib/wovnrb/custom_domain/custom_domain_lang_url_handler.rb +27 -0
- data/lib/wovnrb/custom_domain/custom_domain_langs.rb +40 -0
- data/lib/wovnrb/headers.rb +62 -51
- data/lib/wovnrb/lang.rb +2 -2
- data/lib/wovnrb/services/html_converter.rb +17 -3
- data/lib/wovnrb/services/html_replace_marker.rb +4 -0
- data/lib/wovnrb/store.rb +10 -1
- data/lib/wovnrb/url_language_switcher.rb +44 -4
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +7 -2
- data/test/lib/custom_domain/custom_domain_lang_test.rb +85 -0
- data/test/lib/custom_domain/custom_domain_lang_url_handler_test.rb +75 -0
- data/test/lib/custom_domain/custom_domain_langs_test.rb +82 -0
- data/test/lib/headers_test.rb +209 -48
- data/test/lib/services/html_converter_test.rb +70 -0
- data/test/lib/url_language_switcher_test.rb +148 -0
- data/test/lib/wovnrb_test.rb +1 -0
- data/wovnrb.gemspec +0 -27
- metadata +9 -311
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0283acd73cab4171aefb1bb183832a0536a2c88fd4c62ac3fef0befee06a2a2
|
|
4
|
+
data.tar.gz: b8eebae5190864b55c02f53c30e166ec955ce08c19fd7866185a7ec50df54c3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1b6e6f940f60e059d0b2527108660f43e17d82ca6b57ec7a4f2ec127062482494bc684e7c01bd86453d776dbe53159f19f2984a59a373e3b95920bfd1c78ee0
|
|
7
|
+
data.tar.gz: 9851f866c7df91b312f99790b165407432e6d77f6fa95774cee4016ef3ec35f7e7e0d291396dd20c48a420aaa6771d8196e53641eef53fc3abdd24cb96aa80f8
|
data/Gemfile
CHANGED
|
@@ -1,2 +1,30 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
|
3
|
+
|
|
4
|
+
# All gems below are development dependencies
|
|
5
|
+
gem 'bundler', '>= 1.7'
|
|
6
|
+
gem 'guard'
|
|
7
|
+
gem 'guard-rspec'
|
|
8
|
+
gem 'listen', '~> 3.0.6'
|
|
9
|
+
gem 'minitest'
|
|
10
|
+
gem 'mocha'
|
|
11
|
+
gem 'pry'
|
|
12
|
+
gem 'pry-nav'
|
|
13
|
+
gem 'pry-remote'
|
|
14
|
+
gem 'rake', '~> 10.0'
|
|
15
|
+
gem 'rb-readline'
|
|
16
|
+
gem 'shoulda-context'
|
|
17
|
+
gem 'terminal-notifier'
|
|
18
|
+
gem 'test-unit'
|
|
19
|
+
gem 'test-unit-notify'
|
|
20
|
+
|
|
21
|
+
gem 'rake-compiler'
|
|
22
|
+
gem 'rubocop'
|
|
23
|
+
gem 'rubocop-performance'
|
|
24
|
+
gem 'timecop'
|
|
25
|
+
|
|
26
|
+
# NOTE; it need to use webmock 2.3.2 for avoiding error when we use ruby 2.4.x.
|
|
27
|
+
# https://github.com/bblimke/webmock/issues/683
|
|
28
|
+
gem 'public_suffix', '~> 1.4.6'
|
|
29
|
+
gem 'simplecov'
|
|
30
|
+
gem 'webmock', '>= 2.3.2'
|
data/README.en.md
CHANGED
|
@@ -90,6 +90,7 @@ compress_api_requests | | true
|
|
|
90
90
|
api_timeout_seconds | | 1.0
|
|
91
91
|
api_timeout_search_engine_bots | | 5.0
|
|
92
92
|
translate_canonical_tag | | true
|
|
93
|
+
custom_domain_langs | | {}
|
|
93
94
|
|
|
94
95
|
### 2.1. project_token
|
|
95
96
|
|
|
@@ -123,19 +124,20 @@ Japanese, then you should use the following setting:
|
|
|
123
124
|
|
|
124
125
|
### 2.4. url_pattern
|
|
125
126
|
|
|
126
|
-
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
|
|
127
|
+
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 4 types that can be set.
|
|
127
128
|
|
|
128
|
-
parameters
|
|
129
|
-
|
|
130
|
-
'path'
|
|
131
|
-
'subdomain'
|
|
132
|
-
'query'
|
|
129
|
+
parameters | Translated page's URL | Notes
|
|
130
|
+
--------------- | -------------------------------- | -------
|
|
131
|
+
'path' | https://wovn.io/ja/contact | Default Value. If no settings have been set, url_pattern defaults to this value.
|
|
132
|
+
'subdomain' | https://ja.wovn.io/contact | DNS settings must be set.
|
|
133
|
+
'query' | https://wovn.io/contact?wovn=ja | The least amount of changes to the application required to complete setup.
|
|
134
|
+
'custom_domain' | Depends on `custom_domain_langs` | See [Section 2.15.](#215-custom_domain_langs).
|
|
133
135
|
|
|
134
136
|
※ The following is an example of a URL that has been translated by the library using the above URLs.
|
|
135
137
|
|
|
136
138
|
https://wovn.io/contact
|
|
137
139
|
|
|
138
|
-
### 2.5 lang_param_name
|
|
140
|
+
### 2.5. lang_param_name
|
|
139
141
|
This parameter is only valid for when `url_pattern` is set to `'query'`.
|
|
140
142
|
|
|
141
143
|
It allows you to set the query parameter name for declaring the language of the
|
|
@@ -169,7 +171,7 @@ This option allows to disable translating partial HTML content. By default,
|
|
|
169
171
|
partial HTML content is translated but no widget snippet is added. Set
|
|
170
172
|
`translate_fragment` to `false` to prevent translating partial HTML content.
|
|
171
173
|
|
|
172
|
-
### 2.9 ignore_paths
|
|
174
|
+
### 2.9. ignore_paths
|
|
173
175
|
|
|
174
176
|
This parameter tells WOVN.rb to not localize content withing given directories.
|
|
175
177
|
|
|
@@ -180,7 +182,7 @@ For instance, if you want to not localize the admin directory of your website, y
|
|
|
180
182
|
'ignore_paths' => ['/admin/']
|
|
181
183
|
```
|
|
182
184
|
|
|
183
|
-
### 2.10 install_middleware
|
|
185
|
+
### 2.10. install_middleware
|
|
184
186
|
|
|
185
187
|
When using WOVN.rb in a Rails environment, this parameter controls whether the WOVN.rb middleware will be automatically installed or not.
|
|
186
188
|
|
|
@@ -201,20 +203,47 @@ WOVN.rb needs to be added after any compression middleware.
|
|
|
201
203
|
}
|
|
202
204
|
```
|
|
203
205
|
|
|
204
|
-
### 2.11 compress_api_requests
|
|
206
|
+
### 2.11. compress_api_requests
|
|
205
207
|
|
|
206
208
|
By default, requests to the translation API will be sent with gzip compression. Set to false to disable compression.
|
|
207
209
|
|
|
208
|
-
### 2.12 api_timeout_seconds
|
|
209
|
-
Configures the amount of time in seconds wovnrb will wait for the translation API for a response before the
|
|
210
|
+
### 2.12. api_timeout_seconds
|
|
211
|
+
Configures the amount of time in seconds wovnrb will wait for the translation API for a response before the
|
|
210
212
|
request is considered timed-out. This setting defaults to `1.0`.
|
|
211
213
|
|
|
212
|
-
### 2.13 api_timeout_search_engine_bots
|
|
214
|
+
### 2.13. api_timeout_search_engine_bots
|
|
213
215
|
Similar to `api_timeout_seconds`, this timeout setting is applied when handling requests made by search engine bots.
|
|
214
216
|
Currently, bots from Google, Yahoo, Bing, Yandex, DuckDuckGo and Baidu are supported. This setting
|
|
215
217
|
defaults to `5.0`.
|
|
216
218
|
|
|
217
|
-
### 2.14 translate_canonical_tag
|
|
219
|
+
### 2.14. translate_canonical_tag
|
|
218
220
|
Configures if wovnrb should automatically translate existing canonical tag in the HTML. When set to `true`, wovnrb
|
|
219
221
|
will translate the canonical URL with the current language code according to your `url_pattern` setting.
|
|
220
|
-
This setting defaults to `true`.
|
|
222
|
+
This setting defaults to `true`.
|
|
223
|
+
|
|
224
|
+
### 2.15. custom_domain_langs
|
|
225
|
+
This parameter is valid and required, when `url_pattern` is `custom_domain`.
|
|
226
|
+
Set `custom_domain_langs` for all languages declared in `supported_langs`.
|
|
227
|
+
|
|
228
|
+
```ruby
|
|
229
|
+
config.wovnrb = {
|
|
230
|
+
# ...
|
|
231
|
+
:custom_domain_langs => {
|
|
232
|
+
'en' => { 'url' => 'wovn.io/en' },
|
|
233
|
+
'ja' => { 'url' => 'ja.wovn.io' },
|
|
234
|
+
'fr' => { 'url' => 'fr.wovn.co.jp' }
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
For the example above, all request URLs that match `wovn.io/en/*` will be considered as requests in English language.
|
|
240
|
+
All request URLs other than the above that match `ja.wovn.io/*` will be considered as requests in Japanese langauge.
|
|
241
|
+
And, request URLs that match `fr.wovn.co.jp/*` will be considered as requests in French langauge.
|
|
242
|
+
With the above example configuration, the page `http://ja.wovn.io/about.html` in Japanese language will have the URL `http://wovn.io/en/about.html` as English language.
|
|
243
|
+
|
|
244
|
+
`custom_domain_langs` setting may only be used together with the `url_pattern = custom_domain` setting.
|
|
245
|
+
|
|
246
|
+
If this setting is used, each language declared in `supported_langs` must be given a custom domain.
|
|
247
|
+
|
|
248
|
+
The path declared for your original language must match the structure of the actual web server.
|
|
249
|
+
In other words, you cannot use this setting to change the request path of your content in original language.
|
data/README.ja.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
For English users: [English](README.en.md)
|
|
4
4
|
|
|
5
|
-
WOVN.io Rubyライブラリは、翻訳を提供するためにWOVN.ioを利用したライブラリです。
|
|
5
|
+
WOVN.io Rubyライブラリは、翻訳を提供するためにWOVN.ioを利用したライブラリです。
|
|
6
6
|
WOVN.io Ruby ライブラリは Rack Middleware としてパッケージ化されています。
|
|
7
7
|
|
|
8
8
|
このドキュメントでは、WOVN.io Rubyをインストールするまでの手順や、セットアップ・設定の流れを説明しています。
|
|
@@ -11,7 +11,7 @@ WOVN.io Ruby ライブラリは Rack Middleware としてパッケージ化さ
|
|
|
11
11
|
|
|
12
12
|
### 1.1. WOVN.ioアカウントを作成
|
|
13
13
|
|
|
14
|
-
WOVN.io Ruby Libraryを利用するには、WOVN.ioのアカウントが必要です。
|
|
14
|
+
WOVN.io Ruby Libraryを利用するには、WOVN.ioのアカウントが必要です。
|
|
15
15
|
アカウントをお持ちでない方は、まずはWOVN.ioに登録してください。
|
|
16
16
|
|
|
17
17
|
### 1.2. ページ追加
|
|
@@ -20,7 +20,7 @@ WOVN.ioにログイン後、翻訳したいページを追加します。
|
|
|
20
20
|
|
|
21
21
|
### 1.3. Rubyアプリケーションの設定
|
|
22
22
|
|
|
23
|
-
WOVN.io Ruby ライブラリを使用するには、以下の行を Ruby アプリケーションの Gemfile に挿入します。
|
|
23
|
+
WOVN.io Ruby ライブラリを使用するには、以下の行を Ruby アプリケーションの Gemfile に挿入します。
|
|
24
24
|
WOVN.ioは現在、バージョン2.0.1以上をサポートしています。
|
|
25
25
|
|
|
26
26
|
```ruby
|
|
@@ -88,6 +88,7 @@ query | | []
|
|
|
88
88
|
ignore_class | | []
|
|
89
89
|
translate_fragment | | true
|
|
90
90
|
ignore_paths | | []
|
|
91
|
+
custom_domain_langs| | {}
|
|
91
92
|
|
|
92
93
|
### 2.1. project_token
|
|
93
94
|
|
|
@@ -97,7 +98,7 @@ WOVN.ioアカウントのプロジェクトトークンを設定します。こ
|
|
|
97
98
|
|
|
98
99
|
これはRubyアプリケーションのデフォルト言語を設定します。デフォルト値は英語('en')です。
|
|
99
100
|
|
|
100
|
-
リクエストされたページで、デフォルトの言語パラメータが URL に含まれている場合、リクエストは翻訳前にリダイレクトされます。
|
|
101
|
+
リクエストされたページで、デフォルトの言語パラメータが URL に含まれている場合、リクエストは翻訳前にリダイレクトされます。
|
|
101
102
|
このために `default_lang` パラメータを使用します。
|
|
102
103
|
|
|
103
104
|
`default_lang` が 'en' に設定されている時に、以下のURLへのリクエストを受信した場合。
|
|
@@ -110,7 +111,7 @@ WOVN.ioアカウントのプロジェクトトークンを設定します。こ
|
|
|
110
111
|
|
|
111
112
|
### 2.3. supported_langs
|
|
112
113
|
|
|
113
|
-
これは、ウェブサイトで使用されている言語(翻訳元を含む)をライブラリに伝えます。
|
|
114
|
+
これは、ウェブサイトで使用されている言語(翻訳元を含む)をライブラリに伝えます。
|
|
114
115
|
この設定では、SEO(検索エンジン最適化)に必要なメタデータを挿入することができます。
|
|
115
116
|
|
|
116
117
|
ウェブサイトが英語で、WOVN.ioを使って日本語にローカライズしている場合は、以下の設定にしてください。
|
|
@@ -121,32 +122,33 @@ WOVN.ioアカウントのプロジェクトトークンを設定します。こ
|
|
|
121
122
|
|
|
122
123
|
### 2.4. url_pattern
|
|
123
124
|
|
|
124
|
-
ライブラリはRubyアプリケーションの中で、翻訳されるURLを新たに追加することで動作します。
|
|
125
|
-
urlの種類は `url_pattern` パラメータで設定できます。設定できるタイプは
|
|
125
|
+
ライブラリはRubyアプリケーションの中で、翻訳されるURLを新たに追加することで動作します。
|
|
126
|
+
urlの種類は `url_pattern` パラメータで設定できます。設定できるタイプは4種類。
|
|
126
127
|
|
|
127
128
|
|
|
128
|
-
パラメータ
|
|
129
|
-
|
|
130
|
-
'path'
|
|
131
|
-
'subdomain'
|
|
132
|
-
'query'
|
|
129
|
+
パラメータ | 翻訳されたページのURL | 備考
|
|
130
|
+
--------------- | ------------------------------- | -------
|
|
131
|
+
'path' | https://wovn.io/ja/contact | デフォルト値、何も設定されていない場合、 `url_pattern` のデフォルト値はこの値になります
|
|
132
|
+
'subdomain' | https://ja.wovn.io/contact | DNSの設定が必要です
|
|
133
|
+
'query' | https://wovn.io/contact?wovn=ja | セットアップを完了するために必要なアプリケーションへの変更の最小量
|
|
134
|
+
'custom_domain' | `custom_domain_langs`に設定された値 | [2.10.項](#210-custom_domain_langs)を参照してください。
|
|
133
135
|
|
|
134
136
|
※ 上記は、以下のURLを使用してライブラリが翻訳したURLの例です。
|
|
135
137
|
|
|
136
138
|
https://wovn.io/contact
|
|
137
139
|
|
|
138
|
-
### 2.5 lang_param_name
|
|
140
|
+
### 2.5. lang_param_name
|
|
139
141
|
|
|
140
142
|
このパラメータは `url_pattern` が `query` に設定されている場合のみ有効です。
|
|
141
143
|
|
|
142
144
|
ページの言語を指定するためのクエリパラメータ名を設定することができます。
|
|
143
145
|
|
|
144
|
-
この設定のデフォルト値は `wovn` であり、翻訳された英語のページのURLが `https://my-website.com/index.php?wovn=en` という形式になります。
|
|
146
|
+
この設定のデフォルト値は `wovn` であり、翻訳された英語のページのURLが `https://my-website.com/index.php?wovn=en` という形式になります。
|
|
145
147
|
代わりに `lang` に値を設定すると、URLの例は `https://my-website.com/index.php?lang=en` という形式になります。
|
|
146
148
|
|
|
147
149
|
### 2.6. query
|
|
148
150
|
|
|
149
|
-
WOVN.ioは翻訳されたページを検索する際にクエリパラメータを無視します。
|
|
151
|
+
WOVN.ioは翻訳されたページを検索する際にクエリパラメータを無視します。
|
|
150
152
|
翻訳ページのURLにクエリパラメータを追加したい場合は、`query` パラメータを設定する必要があります。(WOVN.ioも設定する必要があります)
|
|
151
153
|
|
|
152
154
|
https://wovn.io/ja/contact?os=mac&keyboard=us
|
|
@@ -165,16 +167,45 @@ WOVN.ioは翻訳されたページを検索する際にクエリパラメータ
|
|
|
165
167
|
|
|
166
168
|
### 2.8. translate_fragment
|
|
167
169
|
|
|
168
|
-
このオプションでは、部分的なHTMLコンテンツの翻訳を無効にすることができます。
|
|
169
|
-
デフォルトでは、部分的なHTMLコンテンツは翻訳されますが、ウィジェットのスニペットは追加されません。
|
|
170
|
+
このオプションでは、部分的なHTMLコンテンツの翻訳を無効にすることができます。
|
|
171
|
+
デフォルトでは、部分的なHTMLコンテンツは翻訳されますが、ウィジェットのスニペットは追加されません。
|
|
170
172
|
`translate_fragment` を `false` に設定すると、HTMLの一部が翻訳されないようになります。
|
|
171
173
|
|
|
172
|
-
### 2.9 ignore_paths
|
|
174
|
+
### 2.9. ignore_paths
|
|
173
175
|
|
|
174
|
-
このパラメータは、WOVN.rbが指定されたディレクトリ内のコンテンツをローカライズしないように指示します。
|
|
175
|
-
指定されたディレクトリは、URLパスの先頭にのみマッチします。
|
|
176
|
+
このパラメータは、WOVN.rbが指定されたディレクトリ内のコンテンツをローカライズしないように指示します。
|
|
177
|
+
指定されたディレクトリは、URLパスの先頭にのみマッチします。
|
|
176
178
|
例えば、ウェブサイトの管理者ディレクトリをローカライズしたくない場合は、WOVN.rbの設定に次のように追加します。
|
|
177
179
|
|
|
178
180
|
```
|
|
179
181
|
'ignore_paths' => ['/admin/']
|
|
180
182
|
```
|
|
183
|
+
|
|
184
|
+
### 2.10. custom_domain_langs
|
|
185
|
+
|
|
186
|
+
このパラメータは、カスタムドメイン言語パターンの場合(`url_pattern = custom_domain` が設定されている場合)のみ有効です。
|
|
187
|
+
カスタムドメイン言語パターン使用時は必須パラメータです。
|
|
188
|
+
`supported_langs` で設定した全ての言語と元言語に、必ず `custom_domain_langs` を設定してください。
|
|
189
|
+
|
|
190
|
+
```ruby
|
|
191
|
+
config.wovnrb = {
|
|
192
|
+
# ...
|
|
193
|
+
:custom_domain_langs => {
|
|
194
|
+
'en' => { 'url' => 'wovn.io/en' },
|
|
195
|
+
'ja' => { 'url' => 'ja.wovn.io' },
|
|
196
|
+
'fr' => { 'url' => 'fr.wovn.co.jp' }
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
上記の例では、 `wovn.io/en/*` にマッチするリクエストは英語のリクエストとして扱われます。
|
|
202
|
+
それ以外の `ja.wovn.io/*` にマッチするリクエストは日本語のリクエストとして扱われます。
|
|
203
|
+
また、 `fr.wovn.co.jp/*` にマッチするリクエストはフランス語のリクエストとして扱われます。
|
|
204
|
+
例えば、`http://ja.wovn.io/about.html` の日本語ページは、`http://wovn.io/en/about.html` という英語ページのURLを持つことになります。
|
|
205
|
+
|
|
206
|
+
必ず `url_pattern = custom_domain`と`custom_domain_langs` は一緒に使用してください。
|
|
207
|
+
|
|
208
|
+
`supported_langs` で宣言された各言語に `custom_domain_langs` を与えなければなりません。
|
|
209
|
+
|
|
210
|
+
オリジナル言語のために宣言されたパスは、実際のウェブサーバーの構造と一致していなければなりません。
|
|
211
|
+
この設定を使用して、オリジナル言語のリクエストパスを変更することはできません。
|
data/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
README.ja.md
|