wovnrb 2.2.4 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.en.md +174 -0
- data/README.ja.md +180 -0
- data/README.md +1 -0
- data/lib/wovnrb.rb +1 -1
- data/lib/wovnrb/headers.rb +0 -2
- data/lib/wovnrb/lang.rb +4 -1
- data/lib/wovnrb/railtie.rb +1 -1
- data/lib/wovnrb/services/html_converter.rb +4 -9
- data/lib/wovnrb/store.rb +1 -1
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/headers_test.rb +7 -25
- data/test/lib/lang_test.rb +1 -1
- data/test/lib/services/html_converter_test.rb +31 -15
- data/test/lib/store_test.rb +1 -0
- metadata +8 -7
- data/README.md +0 -182
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1667b83e9b8a2a2a79d1c152c71fac66ecc1acfe98b53f062e6929dda1d267c
|
4
|
+
data.tar.gz: 6fe79d1445f3e87ebd65e9d5beca3c173da6e3ae25e92de97c9b85bed95c8547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 560317e910fdf2966f10919126b8e7ec255ce07a9325bcd24c610eda52bb2686347e76e7123e9ffe0c22d7373220aab5e270b3d63a324dda1acec6c5a1c0d9cb
|
7
|
+
data.tar.gz: dbcb9693c55eb8a5b7e77d1b98e53d1bd8ae15989d498e585505a2b04137bf068ab20f4efedf4205c1c412d2882e33774875ffa14294635e2e0f1772efbda08a
|
data/README.en.md
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# WOVN.io Ruby Library
|
2
|
+
|
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
|
+
|
5
|
+
This document explains the process of installing WOVN.io Ruby, as well as set up and configuration process.
|
6
|
+
|
7
|
+
## 1. Install
|
8
|
+
|
9
|
+
### 1.1. Creating a WOVN.io account.
|
10
|
+
|
11
|
+
In order to use the WOVN.io Ruby Library, you need a WOVN.io account. If you do not have an account, please first sign up for one at WOVN.io.
|
12
|
+
|
13
|
+
### 1.2. Adding a Page
|
14
|
+
|
15
|
+
After logging into WOVN.io, add a page that you would like translated.
|
16
|
+
|
17
|
+
### 1.3. Ruby Application Settings
|
18
|
+
|
19
|
+
To use the WOVN.io Ruby Library, insert the following line into your Ruby Application's Gemfile. WOVN.io currently supports version 2.0.1 and up.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'wovnrb', '>= 2.0.1'
|
23
|
+
```
|
24
|
+
|
25
|
+
After setting the above, execute the following command to install the WOVN.io Ruby Library.
|
26
|
+
|
27
|
+
```bash
|
28
|
+
bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
After installing the library, insert the following into your Ruby Application's settings file.
|
32
|
+
|
33
|
+
* If you're using Ruby on Rails
|
34
|
+
|
35
|
+
Insert the following into either config/application.rb or config/environments/.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
...
|
39
|
+
|
40
|
+
config.wovnrb = {
|
41
|
+
:project_token => 'EnS!t3',
|
42
|
+
:default_lang => 'en',
|
43
|
+
:supported_langs => ['en'],
|
44
|
+
:url_pattern => 'path'
|
45
|
+
}
|
46
|
+
|
47
|
+
...
|
48
|
+
```
|
49
|
+
|
50
|
+
* If you're using Sinatra
|
51
|
+
|
52
|
+
Insert the following into either the Application File or config.ru.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
...
|
56
|
+
|
57
|
+
require 'wovnrb'
|
58
|
+
|
59
|
+
use Wovnrb::Interceptor, {
|
60
|
+
:project_token => 'EnS!t3',
|
61
|
+
:default_lang => 'en',
|
62
|
+
:supported_langs => ['en'],
|
63
|
+
:url_pattern => 'path'
|
64
|
+
}
|
65
|
+
|
66
|
+
...
|
67
|
+
```
|
68
|
+
|
69
|
+
After completing setup, start the Ruby Application, and make sure the WOVN.io library is working correctly.
|
70
|
+
|
71
|
+
## 2. Parameter Setting
|
72
|
+
|
73
|
+
The following is a list of the WOVN.io Ruby Library's valid parameters.
|
74
|
+
|
75
|
+
Parameter Name | Required | Default Setting
|
76
|
+
------------------ | -------- | ----------------
|
77
|
+
project_token | yes | ''
|
78
|
+
default_lang | yes | 'en'
|
79
|
+
supported_langs | yes | ['en']
|
80
|
+
url_pattern | yes | 'path'
|
81
|
+
lang_param_name | | 'wovn'
|
82
|
+
query | | []
|
83
|
+
ignore_class | | []
|
84
|
+
translate_fragment | | true
|
85
|
+
ignore_paths | | []
|
86
|
+
|
87
|
+
### 2.1. project_token
|
88
|
+
|
89
|
+
Set your WOVN.io Account's Project token. This parameter is required.
|
90
|
+
|
91
|
+
### 2.2. default_lang
|
92
|
+
|
93
|
+
This sets the Ruby application's default language. The default value is English ('en').
|
94
|
+
|
95
|
+
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.
|
96
|
+
|
97
|
+
If the default_lang is set to 'en', when receiving a request for the following URL,
|
98
|
+
|
99
|
+
https://wovn.io/en/contact
|
100
|
+
|
101
|
+
Then the library will redirect to the following URL.
|
102
|
+
|
103
|
+
https://wovn.io/contact
|
104
|
+
|
105
|
+
### 2.3. supported_langs
|
106
|
+
This tells the library which languages are being used on the website (including
|
107
|
+
the original language). This setting allows for inserting metadata necessary for
|
108
|
+
SEO (Search Engine Optimization).
|
109
|
+
|
110
|
+
If your website is in English and you are using WOVN.io to localize it in
|
111
|
+
Japanese, then you should use the following setting:
|
112
|
+
```
|
113
|
+
:supported_langs => ['en', 'ja']
|
114
|
+
```
|
115
|
+
**Note:** The order of the languages in the list does not matter.
|
116
|
+
|
117
|
+
### 2.4. url_pattern
|
118
|
+
|
119
|
+
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.
|
120
|
+
|
121
|
+
parameters | Translated page's URL | Notes
|
122
|
+
----------- | ------------------------------- | -------
|
123
|
+
'path' | https://wovn.io/ja/contact | Default Value. If no settings have been set, url_pattern defaults to this value.
|
124
|
+
'subdomain' | https://ja.wovn.io/contact | DNS settings must be set.
|
125
|
+
'query' | https://wovn.io/contact?wovn=ja | The least amount of changes to the application required to complete setup.
|
126
|
+
|
127
|
+
※ The following is an example of a URL that has been translated by the library using the above URLs.
|
128
|
+
|
129
|
+
https://wovn.io/contact
|
130
|
+
|
131
|
+
### 2.5 lang_param_name
|
132
|
+
This parameter is only valid for when `url_pattern` is set to `'query'`.
|
133
|
+
|
134
|
+
It allows you to set the query parameter name for declaring the language of the
|
135
|
+
page. The default value for this setting is `'wovn'`, such that a page URL in
|
136
|
+
translated language English has the form
|
137
|
+
`https://my-website.com/index.php?wovn=en`. If you instead set the value to
|
138
|
+
`'lang'`, then the later URL example would have the form
|
139
|
+
`https://my-website.com/index.php?lang=en`.
|
140
|
+
|
141
|
+
### 2.6. query
|
142
|
+
|
143
|
+
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)
|
144
|
+
|
145
|
+
https://wovn.io/ja/contact?os=mac&keyboard=us
|
146
|
+
|
147
|
+
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.
|
148
|
+
|
149
|
+
https://wovn.io/contact
|
150
|
+
|
151
|
+
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.
|
152
|
+
|
153
|
+
https://wovn.io/contact?os=mac
|
154
|
+
|
155
|
+
### 2.7. ignore_class
|
156
|
+
|
157
|
+
This sets "Ignore class" which prevents WOVN from translating HTML elements that have a class contained in this array.
|
158
|
+
|
159
|
+
### 2.8. translate_fragment
|
160
|
+
|
161
|
+
This option allows to disable translating partial HTML content. By default,
|
162
|
+
partial HTML content is translated but no widget snippet is added. Set
|
163
|
+
`translate_fragment` to `false` to prevent translating partial HTML content.
|
164
|
+
|
165
|
+
### 2.9 ignore_paths
|
166
|
+
|
167
|
+
This parameter tells WOVN.rb to not localize content withing given directories.
|
168
|
+
|
169
|
+
The directories given will only be matched against the beginning of the URL path.
|
170
|
+
|
171
|
+
For instance, if you want to not localize the admin directory of your website, you should add the following to you WOVN.rb configuration.
|
172
|
+
```
|
173
|
+
'ignore_paths' => ['/admin/']
|
174
|
+
```
|
data/README.ja.md
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# WOVN.io Ruby Library
|
2
|
+
|
3
|
+
For English users: [English](README.en.md)
|
4
|
+
|
5
|
+
WOVN.io Rubyライブラリは、翻訳を提供するためにWOVN.ioを利用したライブラリです。
|
6
|
+
WOVN.io Ruby ライブラリは Rack Middleware としてパッケージ化されています。
|
7
|
+
|
8
|
+
このドキュメントでは、WOVN.io Rubyをインストールするまでの手順や、セットアップ・設定の流れを説明しています。
|
9
|
+
|
10
|
+
## 1. インストール
|
11
|
+
|
12
|
+
### 1.1. WOVN.ioアカウントを作成
|
13
|
+
|
14
|
+
WOVN.io Ruby Libraryを利用するには、WOVN.ioのアカウントが必要です。
|
15
|
+
アカウントをお持ちでない方は、まずはWOVN.ioに登録してください。
|
16
|
+
|
17
|
+
### 1.2. ページ追加
|
18
|
+
|
19
|
+
WOVN.ioにログイン後、翻訳したいページを追加します。
|
20
|
+
|
21
|
+
### 1.3. Rubyアプリケーションの設定
|
22
|
+
|
23
|
+
WOVN.io Ruby ライブラリを使用するには、以下の行を Ruby アプリケーションの Gemfile に挿入します。
|
24
|
+
WOVN.ioは現在、バージョン2.0.1以上をサポートしています。
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'wovnrb', '>= 2.0.1'
|
28
|
+
```
|
29
|
+
|
30
|
+
以上の設定を行った後、以下のコマンドを実行して、WOVN.io Rubyライブラリをインストールします。
|
31
|
+
|
32
|
+
```bash
|
33
|
+
bundle install
|
34
|
+
```
|
35
|
+
|
36
|
+
ライブラリをインストールしたら、Rubyアプリケーションの設定ファイルに以下を挿入します。
|
37
|
+
|
38
|
+
* Ruby on Rails を使っている場合
|
39
|
+
|
40
|
+
`config/application.rb` または `config/environments/` に以下を挿入します。
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
...
|
44
|
+
|
45
|
+
config.wovnrb = {
|
46
|
+
:project_token => 'EnS!t3',
|
47
|
+
:default_lang => 'en',
|
48
|
+
:supported_langs => ['en'],
|
49
|
+
:url_pattern => 'path'
|
50
|
+
}
|
51
|
+
|
52
|
+
...
|
53
|
+
```
|
54
|
+
|
55
|
+
* Sinatra を使っている場合
|
56
|
+
|
57
|
+
アプリケーション・ファイルまたは `config.ru` のいずれかに以下を挿入します。
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
...
|
61
|
+
|
62
|
+
require 'wovnrb'
|
63
|
+
|
64
|
+
use Wovnrb::Interceptor, {
|
65
|
+
:project_token => 'EnS!t3',
|
66
|
+
:default_lang => 'en',
|
67
|
+
:supported_langs => ['en'],
|
68
|
+
:url_pattern => 'path'
|
69
|
+
}
|
70
|
+
|
71
|
+
...
|
72
|
+
```
|
73
|
+
|
74
|
+
セットアップが完了したら、Rubyアプリケーションを起動し、WOVN.ioライブラリが正常に動作していることを確認します。
|
75
|
+
|
76
|
+
## 2. パラメータ設定
|
77
|
+
|
78
|
+
以下に、WOVN.io Ruby ライブラリの有効なパラメータの一覧を示します。
|
79
|
+
|
80
|
+
パラメータ名 | 必須 | デフォルト設定
|
81
|
+
------------------ | -------- | ----------------
|
82
|
+
project_token | yes | ''
|
83
|
+
default_lang | yes | 'en'
|
84
|
+
supported_langs | yes | ['en']
|
85
|
+
url_pattern | yes | 'path'
|
86
|
+
lang_param_name | | 'wovn'
|
87
|
+
query | | []
|
88
|
+
ignore_class | | []
|
89
|
+
translate_fragment | | true
|
90
|
+
ignore_paths | | []
|
91
|
+
|
92
|
+
### 2.1. project_token
|
93
|
+
|
94
|
+
WOVN.ioアカウントのプロジェクトトークンを設定します。このパラメータは必須です。
|
95
|
+
|
96
|
+
### 2.2. default_lang
|
97
|
+
|
98
|
+
これはRubyアプリケーションのデフォルト言語を設定します。デフォルト値は英語('en')です。
|
99
|
+
|
100
|
+
リクエストされたページで、デフォルトの言語パラメータが URL に含まれている場合、リクエストは翻訳前にリダイレクトされます。
|
101
|
+
このために `default_lang` パラメータを使用します。
|
102
|
+
|
103
|
+
`default_lang` が 'en' に設定されている時に、以下のURLへのリクエストを受信した場合。
|
104
|
+
|
105
|
+
https://wovn.io/en/contact
|
106
|
+
|
107
|
+
ライブラリは以下のURLにリダイレクトされます。
|
108
|
+
|
109
|
+
https://wovn.io/contact
|
110
|
+
|
111
|
+
### 2.3. supported_langs
|
112
|
+
|
113
|
+
これは、ウェブサイトで使用されている言語(翻訳元を含む)をライブラリに伝えます。
|
114
|
+
この設定では、SEO(検索エンジン最適化)に必要なメタデータを挿入することができます。
|
115
|
+
|
116
|
+
ウェブサイトが英語で、WOVN.ioを使って日本語にローカライズしている場合は、以下の設定にしてください。
|
117
|
+
```
|
118
|
+
:supported_langs => ['en', 'ja']
|
119
|
+
```
|
120
|
+
**注意:** 配列の言語の順番は関係ありません。
|
121
|
+
|
122
|
+
### 2.4. url_pattern
|
123
|
+
|
124
|
+
ライブラリはRubyアプリケーションの中で、翻訳されるURLを新たに追加することで動作します。
|
125
|
+
urlの種類は `url_pattern` パラメータで設定できます。設定できるタイプは3種類。
|
126
|
+
|
127
|
+
|
128
|
+
パラメータ | 翻訳されたページのURL | 備考
|
129
|
+
----------- | ------------------------------- | -------
|
130
|
+
'path' | https://wovn.io/ja/contact | デフォルト値、何も設定されていない場合、 `url_pattern` のデフォルト値はこの値になります
|
131
|
+
'subdomain' | https://ja.wovn.io/contact | DNSの設定が必要です
|
132
|
+
'query' | https://wovn.io/contact?wovn=ja | セットアップを完了するために必要なアプリケーションへの変更の最小量
|
133
|
+
|
134
|
+
※ 上記は、以下のURLを使用してライブラリが翻訳したURLの例です。
|
135
|
+
|
136
|
+
https://wovn.io/contact
|
137
|
+
|
138
|
+
### 2.5 lang_param_name
|
139
|
+
|
140
|
+
このパラメータは `url_pattern` が `query` に設定されている場合のみ有効です。
|
141
|
+
|
142
|
+
ページの言語を指定するためのクエリパラメータ名を設定することができます。
|
143
|
+
|
144
|
+
この設定のデフォルト値は `wovn` であり、翻訳された英語のページのURLが `https://my-website.com/index.php?wovn=en` という形式になります。
|
145
|
+
代わりに `lang` に値を設定すると、URLの例は `https://my-website.com/index.php?lang=en` という形式になります。
|
146
|
+
|
147
|
+
### 2.6. query
|
148
|
+
|
149
|
+
WOVN.ioは翻訳されたページを検索する際にクエリパラメータを無視します。
|
150
|
+
翻訳ページのURLにクエリパラメータを追加したい場合は、`query` パラメータを設定する必要があります。(WOVN.ioも設定する必要があります)
|
151
|
+
|
152
|
+
https://wovn.io/ja/contact?os=mac&keyboard=us
|
153
|
+
|
154
|
+
`default_lang` が `en` でクエリが空に設定されている場合、上記のURLは以下のURLに変更され、ページの翻訳を検索するようになります。
|
155
|
+
|
156
|
+
https://wovn.io/contact
|
157
|
+
|
158
|
+
`default_lang` が `en` でクエリが `os` に設定されている場合、上記のURLは以下のURLに変更され、ページの翻訳を検索するようになります。
|
159
|
+
|
160
|
+
https://wovn.io/contact?os=mac
|
161
|
+
|
162
|
+
### 2.7. ignore_class
|
163
|
+
|
164
|
+
これは「無視するクラス」を設定し、WOVNがこの配列に含まれるクラスを持つHTML要素を変換できないようにします。
|
165
|
+
|
166
|
+
### 2.8. translate_fragment
|
167
|
+
|
168
|
+
このオプションでは、部分的なHTMLコンテンツの翻訳を無効にすることができます。
|
169
|
+
デフォルトでは、部分的なHTMLコンテンツは翻訳されますが、ウィジェットのスニペットは追加されません。
|
170
|
+
`translate_fragment` を `false` に設定すると、HTMLの一部が翻訳されないようになります。
|
171
|
+
|
172
|
+
### 2.9 ignore_paths
|
173
|
+
|
174
|
+
このパラメータは、WOVN.rbが指定されたディレクトリ内のコンテンツをローカライズしないように指示します。
|
175
|
+
指定されたディレクトリは、URLパスの先頭にのみマッチします。
|
176
|
+
例えば、ウェブサイトの管理者ディレクトリをローカライズしたくない場合は、WOVN.rbの設定に次のように追加します。
|
177
|
+
|
178
|
+
```
|
179
|
+
'ignore_paths' => ['/admin/']
|
180
|
+
```
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
./README.ja.md
|
data/lib/wovnrb.rb
CHANGED
data/lib/wovnrb/headers.rb
CHANGED
@@ -8,7 +8,6 @@ module Wovnrb
|
|
8
8
|
attr_reader :unmasked_pathname
|
9
9
|
attr_reader :pathname
|
10
10
|
attr_reader :pathname_with_trailing_slash_if_present
|
11
|
-
attr_reader :redis_url
|
12
11
|
|
13
12
|
# Generates new instance of Wovnrb::Headers.
|
14
13
|
# Its parameters are set by parsing env variable.
|
@@ -62,7 +61,6 @@ module Wovnrb
|
|
62
61
|
@query = remove_lang(@query, lang_code)
|
63
62
|
@pathname_with_trailing_slash_if_present = @pathname
|
64
63
|
@pathname = @pathname.gsub(/\/$/, '')
|
65
|
-
@redis_url = "#{@host}#{@pathname}#{@query}"
|
66
64
|
end
|
67
65
|
|
68
66
|
def unmasked_pathname_without_trailing_slash
|
data/lib/wovnrb/lang.rb
CHANGED
@@ -76,7 +76,10 @@ module Wovnrb
|
|
76
76
|
'tr' => { name: 'Türkçe', code: 'tr', en: 'Turkish' },
|
77
77
|
'uk' => { name: 'Українська', code: 'uk', en: 'Ukrainian' },
|
78
78
|
'ur' => { name: 'اردو', code: 'ur', en: 'Urdu' },
|
79
|
-
'vi' => { name: 'Tiếng Việt', code: 'vi', en: 'Vietnamese' }
|
79
|
+
'vi' => { name: 'Tiếng Việt', code: 'vi', en: 'Vietnamese' },
|
80
|
+
'km' => { name: 'ភាសាខ្មែរ', code: 'km', en: 'Khmer' },
|
81
|
+
'ta' => { name: 'தமிழ்', code: 'ta', en: 'Tamil' },
|
82
|
+
'si' => { name: 'සිංහල', code: 'si', en: 'Sinhala' }
|
80
83
|
}.freeze
|
81
84
|
|
82
85
|
# Provides the ISO639-1 code for a given lang code.
|
data/lib/wovnrb/railtie.rb
CHANGED
@@ -43,6 +43,7 @@ module Wovnrb
|
|
43
43
|
|
44
44
|
insert_snippet(true)
|
45
45
|
insert_hreflang_tags
|
46
|
+
inject_lang_html_tag
|
46
47
|
|
47
48
|
html
|
48
49
|
end
|
@@ -84,7 +85,7 @@ module Wovnrb
|
|
84
85
|
end
|
85
86
|
|
86
87
|
def strip_wovn_ignore(node, marker)
|
87
|
-
put_replace_marker(node, marker) if node && node.get_attribute('wovn-ignore')
|
88
|
+
put_replace_marker(node, marker) if node && (node.get_attribute('wovn-ignore') || node.get_attribute('data-wovn-ignore'))
|
88
89
|
end
|
89
90
|
|
90
91
|
def put_replace_marker(node, marker)
|
@@ -108,15 +109,9 @@ module Wovnrb
|
|
108
109
|
def inject_lang_html_tag
|
109
110
|
root = @dom.at_css('html')
|
110
111
|
return unless root
|
112
|
+
return if root['lang']
|
111
113
|
|
112
|
-
|
113
|
-
default_lang = @store.default_lang
|
114
|
-
|
115
|
-
if current_lang != default_lang
|
116
|
-
root['lang'] = current_lang
|
117
|
-
else
|
118
|
-
root.delete('lang')
|
119
|
-
end
|
114
|
+
root['lang'] = @store.default_lang
|
120
115
|
end
|
121
116
|
|
122
117
|
def replace_hreflangs
|
data/lib/wovnrb/store.rb
CHANGED
data/lib/wovnrb/version.rb
CHANGED
data/test/lib/headers_test.rb
CHANGED
@@ -74,24 +74,6 @@ module Wovnrb
|
|
74
74
|
assert_equal('localhost', env['SERVER_NAME'])
|
75
75
|
end
|
76
76
|
|
77
|
-
def test_initialize_without_query
|
78
|
-
env = Wovnrb.get_env
|
79
|
-
h = Wovnrb::Headers.new(env, Wovnrb.get_settings)
|
80
|
-
assert_equal('wovn.io/dashboard', h.redis_url)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_initialize_with_query
|
84
|
-
env = Wovnrb.get_env
|
85
|
-
h = Wovnrb::Headers.new(env, Wovnrb.get_settings('query' => ['param']))
|
86
|
-
assert_equal('wovn.io/dashboard?param=val', h.redis_url)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_initialize_with_not_matching_query
|
90
|
-
env = Wovnrb.get_env
|
91
|
-
h = Wovnrb::Headers.new(env, Wovnrb.get_settings('query' => ['aaa']))
|
92
|
-
assert_equal('wovn.io/dashboard', h.redis_url)
|
93
|
-
end
|
94
|
-
|
95
77
|
def test_initialize_with_proto_header
|
96
78
|
env = Wovnrb.get_env('url' => 'http://page.com', 'HTTP_X_FORWARDED_PROTO' => 'https')
|
97
79
|
h = Wovnrb::Headers.new(env, Wovnrb.get_settings('query' => ['aaa']))
|
@@ -6232,7 +6214,7 @@ module Wovnrb
|
|
6232
6214
|
h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings)
|
6233
6215
|
|
6234
6216
|
keys = Wovnrb::Lang::LANG.keys
|
6235
|
-
assert_equal(
|
6217
|
+
assert_equal(77, keys.size)
|
6236
6218
|
|
6237
6219
|
for key in keys
|
6238
6220
|
uri_without_scheme = h.remove_lang("wovn.io/#{key}", key)
|
@@ -6246,7 +6228,7 @@ module Wovnrb
|
|
6246
6228
|
def test_remove_lang_path_with_nil_lang
|
6247
6229
|
h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings)
|
6248
6230
|
keys = Wovnrb::Lang::LANG.keys
|
6249
|
-
assert_equal(
|
6231
|
+
assert_equal(77, keys.size)
|
6250
6232
|
|
6251
6233
|
uri_without_scheme = h.remove_lang('wovn.io', nil)
|
6252
6234
|
assert_equal('wovn.io', uri_without_scheme)
|
@@ -6269,7 +6251,7 @@ module Wovnrb
|
|
6269
6251
|
h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'query'))
|
6270
6252
|
|
6271
6253
|
keys = Wovnrb::Lang::LANG.keys
|
6272
|
-
assert_equal(
|
6254
|
+
assert_equal(77, keys.size)
|
6273
6255
|
|
6274
6256
|
for key in keys
|
6275
6257
|
uri_without_scheme = h.remove_lang("wovn.io/?wovn=#{key}", key)
|
@@ -6284,7 +6266,7 @@ module Wovnrb
|
|
6284
6266
|
sut = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'query', 'lang_param_name' => 'lang'))
|
6285
6267
|
|
6286
6268
|
keys = Wovnrb::Lang::LANG.keys
|
6287
|
-
assert_equal(
|
6269
|
+
assert_equal(77, keys.size)
|
6288
6270
|
|
6289
6271
|
for key in keys
|
6290
6272
|
uri_without_custom_lang_param = "wovn.io/?wovn=#{key}"
|
@@ -6302,7 +6284,7 @@ module Wovnrb
|
|
6302
6284
|
def test_remove_lang_query_with_nil_lang
|
6303
6285
|
h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'query'))
|
6304
6286
|
keys = Wovnrb::Lang::LANG.keys
|
6305
|
-
assert_equal(
|
6287
|
+
assert_equal(77, keys.size)
|
6306
6288
|
|
6307
6289
|
uri_without_scheme = h.remove_lang('wovn.io', nil)
|
6308
6290
|
assert_equal('wovn.io', uri_without_scheme)
|
@@ -6325,7 +6307,7 @@ module Wovnrb
|
|
6325
6307
|
h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'subdomain'))
|
6326
6308
|
|
6327
6309
|
keys = Wovnrb::Lang::LANG.keys
|
6328
|
-
assert_equal(
|
6310
|
+
assert_equal(77, keys.size)
|
6329
6311
|
|
6330
6312
|
for key in keys
|
6331
6313
|
uri_without_scheme = h.remove_lang("#{key.downcase}.wovn.io/", key)
|
@@ -6339,7 +6321,7 @@ module Wovnrb
|
|
6339
6321
|
def test_remove_lang_subdomain_with_nil_lang
|
6340
6322
|
h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'subdomain'))
|
6341
6323
|
keys = Wovnrb::Lang::LANG.keys
|
6342
|
-
assert_equal(
|
6324
|
+
assert_equal(77, keys.size)
|
6343
6325
|
|
6344
6326
|
uri_without_scheme = h.remove_lang('wovn.io', nil)
|
6345
6327
|
assert_equal('wovn.io', uri_without_scheme)
|
data/test/lib/lang_test.rb
CHANGED
@@ -6,7 +6,7 @@ module Wovnrb
|
|
6
6
|
converter = prepare_html_converter('<html><body><a class="test">hello</a></body></html>', supported_langs: %w[en vi])
|
7
7
|
converted_html, = converter.build_api_compatible_html
|
8
8
|
|
9
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><a class=\"test\">hello</a></body></html>"
|
9
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><a class=\"test\">hello</a></body></html>"
|
10
10
|
assert_equal(expected_html, converted_html)
|
11
11
|
end
|
12
12
|
|
@@ -19,7 +19,7 @@ module Wovnrb
|
|
19
19
|
converter = prepare_html_converter('<html><body><a class="test">hello</a></body></html>', settings)
|
20
20
|
converted_html, = converter.build_api_compatible_html
|
21
21
|
|
22
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=lang&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?lang=vi\"></head><body><a class=\"test\">hello</a></body></html>"
|
22
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=lang&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?lang=vi\"></head><body><a class=\"test\">hello</a></body></html>"
|
23
23
|
assert_equal(expected_html, converted_html)
|
24
24
|
end
|
25
25
|
|
@@ -28,7 +28,7 @@ module Wovnrb
|
|
28
28
|
converter = prepare_html_converter('<html><body><p>' + long_string + '</p></body></html>', supported_langs: %w[en vi])
|
29
29
|
converted_html, = converter.build_api_compatible_html
|
30
30
|
|
31
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><p>" + long_string + '</p></body></html>'
|
31
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><p>" + long_string + '</p></body></html>'
|
32
32
|
assert_equal(expected_html, converted_html)
|
33
33
|
end
|
34
34
|
|
@@ -36,6 +36,7 @@ module Wovnrb
|
|
36
36
|
html = [
|
37
37
|
'<html><body>',
|
38
38
|
'<p>Hello <span wovn-ignore>WOVN</span><p>',
|
39
|
+
'<p>Hello <span data-wovn-ignore>WOVN</span><p>',
|
39
40
|
'<div><span class="ignore-me">should be ignored</span></div>',
|
40
41
|
'<span>Have a nice day!</span>',
|
41
42
|
'</body></html>'
|
@@ -44,7 +45,7 @@ module Wovnrb
|
|
44
45
|
converter = prepare_html_converter(html, ignore_class: ['ignore-me'])
|
45
46
|
converted_html, = converter.build_api_compatible_html
|
46
47
|
|
47
|
-
expected_convert_html = "<html><head><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"fr\" href=\"http://my-site.com/?wovn=fr\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/?wovn=ja\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><p>Hello <span wovn-ignore=\"\"><!-- __wovn-backend-ignored-key-0 --></span></p><p></p><div><span class=\"ignore-me\"><!-- __wovn-backend-ignored-key-
|
48
|
+
expected_convert_html = "<html lang=\"en\"><head><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"fr\" href=\"http://my-site.com/?wovn=fr\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/?wovn=ja\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><p>Hello <span wovn-ignore=\"\"><!-- __wovn-backend-ignored-key-0 --></span></p><p></p><p>Hello <span data-wovn-ignore=\"\"><!-- __wovn-backend-ignored-key-1 --></span></p><p></p><div><span class=\"ignore-me\"><!-- __wovn-backend-ignored-key-2 --></span></div><span>Have a nice day!</span></body></html>"
|
48
49
|
assert_equal(expected_convert_html, converted_html)
|
49
50
|
end
|
50
51
|
|
@@ -61,7 +62,7 @@ module Wovnrb
|
|
61
62
|
converter = prepare_html_converter(html, ignore_class: [])
|
62
63
|
converted_html, = converter.build_api_compatible_html
|
63
64
|
|
64
|
-
expected_convert_html = "<html><head><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"fr\" href=\"http://my-site.com/?wovn=fr\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/?wovn=ja\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><form action=\"/test\" method=\"POST\"><!-- __wovn-backend-ignored-key-0 --></form></body></html>"
|
65
|
+
expected_convert_html = "<html lang=\"en\"><head><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"fr\" href=\"http://my-site.com/?wovn=fr\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/?wovn=ja\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><form action=\"/test\" method=\"POST\"><!-- __wovn-backend-ignored-key-0 --></form></body></html>"
|
65
66
|
assert_equal(expected_convert_html, converted_html)
|
66
67
|
end
|
67
68
|
|
@@ -79,7 +80,7 @@ module Wovnrb
|
|
79
80
|
converted_html, = converter.build_api_compatible_html
|
80
81
|
|
81
82
|
expected_convert_html = [
|
82
|
-
'<html><head>',
|
83
|
+
'<html lang="en"><head>',
|
83
84
|
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"fr\" href=\"http://my-site.com/?wovn=fr\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/?wovn=ja\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body>",
|
84
85
|
'<input id="user-id" type="hidden" value="__wovn-backend-ignored-key-0">',
|
85
86
|
'<input id="password" type="hidden" value="__wovn-backend-ignored-key-1">',
|
@@ -94,7 +95,7 @@ module Wovnrb
|
|
94
95
|
converter = prepare_html_converter('<html><body><a>hello</a></body></html>', supported_langs: %w[en vi])
|
95
96
|
translated_html = converter.build
|
96
97
|
|
97
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><a>hello</a></body></html>"
|
98
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><a>hello</a></body></html>"
|
98
99
|
assert_equal(expected_html, translated_html)
|
99
100
|
end
|
100
101
|
|
@@ -102,7 +103,7 @@ module Wovnrb
|
|
102
103
|
converter = prepare_html_converter('<html><body><a>hello</a></body></html>', supported_langs: [])
|
103
104
|
translated_html = converter.build
|
104
105
|
|
105
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script></head><body><a>hello</a></body></html>"
|
106
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script></head><body><a>hello</a></body></html>"
|
106
107
|
assert_equal(expected_html, translated_html)
|
107
108
|
end
|
108
109
|
|
@@ -110,7 +111,7 @@ module Wovnrb
|
|
110
111
|
converter = prepare_html_converter('<html><head><title>TITLE</title></head><body><a>hello</a></body></html>', supported_langs: %w[en vi])
|
111
112
|
translated_html = converter.build
|
112
113
|
|
113
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><title>TITLE</title><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><a>hello</a></body></html>"
|
114
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><title>TITLE</title><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body><a>hello</a></body></html>"
|
114
115
|
assert_equal(expected_html, translated_html)
|
115
116
|
end
|
116
117
|
|
@@ -118,7 +119,7 @@ module Wovnrb
|
|
118
119
|
converter = prepare_html_converter('<html>hello<a>world</a></html>', supported_langs: [])
|
119
120
|
translated_html = converter.build
|
120
121
|
|
121
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script></head><body>hello<a>world</a></body></html>"
|
122
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script></head><body>hello<a>world</a></body></html>"
|
122
123
|
assert_equal(expected_html, translated_html)
|
123
124
|
end
|
124
125
|
|
@@ -133,7 +134,7 @@ module Wovnrb
|
|
133
134
|
converter = HtmlConverter.new(dom, store, headers)
|
134
135
|
translated_html = converter.build
|
135
136
|
|
136
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/?wovn=ja\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body>hello<a>world</a></body></html>"
|
137
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=query&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/?wovn=ja\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/?wovn=vi\"></head><body>hello<a>world</a></body></html>"
|
137
138
|
assert_equal(expected_html, translated_html)
|
138
139
|
end
|
139
140
|
|
@@ -148,7 +149,7 @@ module Wovnrb
|
|
148
149
|
converter = HtmlConverter.new(dom, store, headers)
|
149
150
|
translated_html = converter.build
|
150
151
|
|
151
|
-
expected_html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=path&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/ja/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/vi/\"></head><body>hello<a>world</a></body></html>"
|
152
|
+
expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&backend=true&currentLang=en&defaultLang=en&urlPattern=path&langCodeAliases={}&langParamName=wovn&version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script><link rel=\"alternate\" hreflang=\"en\" href=\"http://my-site.com/\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://my-site.com/ja/\"><link rel=\"alternate\" hreflang=\"vi\" href=\"http://my-site.com/vi/\"></head><body>hello<a>world</a></body></html>"
|
152
153
|
assert_equal(expected_html, translated_html)
|
153
154
|
end
|
154
155
|
|
@@ -168,18 +169,33 @@ module Wovnrb
|
|
168
169
|
assert_equal(expected_html, converter.send(:html))
|
169
170
|
end
|
170
171
|
|
171
|
-
def
|
172
|
+
def test_inject_lang_html_tag_with_no_lang_in_html_tag
|
172
173
|
settings = default_store_settings
|
173
174
|
store = Wovnrb::Store.instance
|
174
175
|
store.update_settings(settings)
|
175
176
|
|
176
177
|
headers = Wovnrb::Headers.new(
|
177
|
-
Wovnrb.get_env('url' => 'http://my-site.com
|
178
|
+
Wovnrb.get_env('url' => 'http://my-site.com/'),
|
178
179
|
Wovnrb.get_settings(settings)
|
179
180
|
)
|
180
181
|
converter = HtmlConverter.new(get_dom('<html><body>hello</body></html>'), store, headers)
|
181
182
|
converter.send(:inject_lang_html_tag)
|
182
|
-
expected_html = '<html lang="
|
183
|
+
expected_html = '<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>hello</body></html>'
|
184
|
+
assert_equal(expected_html, converter.send(:html))
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_inject_lang_html_tag_with_lang_in_html_tag
|
188
|
+
settings = default_store_settings
|
189
|
+
store = Wovnrb::Store.instance
|
190
|
+
store.update_settings(settings)
|
191
|
+
|
192
|
+
headers = Wovnrb::Headers.new(
|
193
|
+
Wovnrb.get_env('url' => 'http://my-site.com/'),
|
194
|
+
Wovnrb.get_settings(settings)
|
195
|
+
)
|
196
|
+
converter = HtmlConverter.new(get_dom('<html lang="th"><body>hello</body></html>'), store, headers)
|
197
|
+
converter.send(:inject_lang_html_tag)
|
198
|
+
expected_html = '<html lang="th"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>hello</body></html>'
|
183
199
|
assert_equal(expected_html, converter.send(:html))
|
184
200
|
end
|
185
201
|
|
data/test/lib/store_test.rb
CHANGED
@@ -132,6 +132,7 @@ module Wovnrb
|
|
132
132
|
store.update_settings('wovn_dev_mode' => true)
|
133
133
|
|
134
134
|
assert(store.dev_mode?)
|
135
|
+
assert_equal('dev-wovn.io', store.wovn_host)
|
135
136
|
assert_equal('http://dev-wovn.io:3001/v0/', store.settings['api_url'])
|
136
137
|
assert_equal(3, store.settings['api_timeout_seconds'])
|
137
138
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wovnrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Sandford
|
8
8
|
- Antoine David
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -410,6 +410,8 @@ files:
|
|
410
410
|
- Gemfile
|
411
411
|
- LICENSE.txt
|
412
412
|
- PULL_REQUEST_TEMPLATE
|
413
|
+
- README.en.md
|
414
|
+
- README.ja.md
|
413
415
|
- README.md
|
414
416
|
- Rakefile
|
415
417
|
- lib/wovnrb.rb
|
@@ -446,7 +448,7 @@ homepage: ''
|
|
446
448
|
licenses:
|
447
449
|
- MIT
|
448
450
|
metadata: {}
|
449
|
-
post_install_message:
|
451
|
+
post_install_message:
|
450
452
|
rdoc_options: []
|
451
453
|
require_paths:
|
452
454
|
- lib
|
@@ -461,9 +463,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
461
463
|
- !ruby/object:Gem::Version
|
462
464
|
version: '0'
|
463
465
|
requirements: []
|
464
|
-
|
465
|
-
|
466
|
-
signing_key:
|
466
|
+
rubygems_version: 3.0.3
|
467
|
+
signing_key:
|
467
468
|
specification_version: 4
|
468
469
|
summary: Gem for WOVN.io
|
469
470
|
test_files:
|
data/README.md
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
# WOVN.io Ruby Library
|
2
|
-
|
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
|
-
|
5
|
-
This document explains the process of installing WOVN.io Ruby, as well as set up and configuration process.
|
6
|
-
|
7
|
-
## 1. Install
|
8
|
-
|
9
|
-
### 1.1. Creating a WOVN.io account.
|
10
|
-
|
11
|
-
In order to use the WOVN.io Ruby Library, you need a WOVN.io account. If you do not have an account, please first sign up for one at WOVN.io.
|
12
|
-
|
13
|
-
### 1.2. Adding a Page
|
14
|
-
|
15
|
-
After logging into WOVN.io, add a page that you would like translated.
|
16
|
-
|
17
|
-
### 1.3. Ruby Application Settings
|
18
|
-
|
19
|
-
To use the WOVN.io Ruby Library, insert the following line into your Ruby Application's Gemfile. WOVN.io currently supports version 2.0.1 and up.
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
gem 'wovnrb', '>= 2.0.1'
|
23
|
-
```
|
24
|
-
|
25
|
-
After setting the above, execute the following command to install the WOVN.io Ruby Library.
|
26
|
-
|
27
|
-
```bash
|
28
|
-
bundle install
|
29
|
-
```
|
30
|
-
|
31
|
-
After installing the library, insert the following into your Ruby Application's settings file.
|
32
|
-
|
33
|
-
* If you're using Ruby on Rails
|
34
|
-
|
35
|
-
Insert the following into either config/application.rb or config/environments/.
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
...
|
39
|
-
|
40
|
-
config.wovnrb = {
|
41
|
-
:project_token => 'EnS!t3',
|
42
|
-
:default_lang => 'en',
|
43
|
-
:supported_langs => ['en'],
|
44
|
-
:url_pattern => 'path'
|
45
|
-
}
|
46
|
-
|
47
|
-
...
|
48
|
-
```
|
49
|
-
|
50
|
-
* If you're using Sinatra
|
51
|
-
|
52
|
-
Insert the following into either the Application File or config.ru.
|
53
|
-
|
54
|
-
```ruby
|
55
|
-
...
|
56
|
-
|
57
|
-
require 'wovnrb'
|
58
|
-
|
59
|
-
use Wovnrb::Interceptor, {
|
60
|
-
:project_token => 'EnS!t3',
|
61
|
-
:default_lang => 'en',
|
62
|
-
:supported_langs => ['en'],
|
63
|
-
:url_pattern => 'path'
|
64
|
-
}
|
65
|
-
|
66
|
-
...
|
67
|
-
```
|
68
|
-
|
69
|
-
After completing setup, start the Ruby Application, and make sure the WOVN.io library is working correctly.
|
70
|
-
|
71
|
-
## 2. Parameter Setting
|
72
|
-
|
73
|
-
The following is a list of the WOVN.io Ruby Library's valid parameters.
|
74
|
-
|
75
|
-
Parameter Name | Required | Default Setting
|
76
|
-
------------------ | -------- | ----------------
|
77
|
-
project_token | yes | ''
|
78
|
-
default_lang | yes | 'en'
|
79
|
-
supported_langs | yes | ['en']
|
80
|
-
url_pattern | yes | 'path'
|
81
|
-
lang_param_name | | 'wovn'
|
82
|
-
query | | []
|
83
|
-
ignore_class | | []
|
84
|
-
translate_fragment | | true
|
85
|
-
ignore_paths | | []
|
86
|
-
|
87
|
-
### 2.1. project_token
|
88
|
-
|
89
|
-
Set your WOVN.io Account's Project token. This parameter is required.
|
90
|
-
|
91
|
-
### 2.2. default_lang
|
92
|
-
|
93
|
-
This sets the Ruby application's default language. The default value is English ('en').
|
94
|
-
|
95
|
-
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.
|
96
|
-
|
97
|
-
If the default_lang is set to 'en', when receiving a request for the following URL,
|
98
|
-
|
99
|
-
https://wovn.io/en/contact
|
100
|
-
|
101
|
-
Then the library will redirect to the following URL.
|
102
|
-
|
103
|
-
https://wovn.io/contact
|
104
|
-
|
105
|
-
### 2.3. supported_langs
|
106
|
-
This tells the library which languages are being used on the website (including
|
107
|
-
the original language). This setting allows for inserting metadata necessary for
|
108
|
-
SEO (Search Engine Optimization).
|
109
|
-
|
110
|
-
If your website is in English and you are using WOVN.io to localize it in
|
111
|
-
Japanese, then you should use the following setting:
|
112
|
-
```
|
113
|
-
:supported_langs => ['en', 'ja']
|
114
|
-
```
|
115
|
-
**Note:** The order of the languages in the list does not matter.
|
116
|
-
|
117
|
-
### 2.4. url_pattern
|
118
|
-
|
119
|
-
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.
|
120
|
-
|
121
|
-
parameters | Translated page's URL | Notes
|
122
|
-
----------- | ------------------------------- | -------
|
123
|
-
'path' | https://wovn.io/ja/contact | Default Value. If no settings have been set, url_pattern defaults to this value.
|
124
|
-
'subdomain' | https://ja.wovn.io/contact | DNS settings must be set.
|
125
|
-
'query' | https://wovn.io/contact?wovn=ja | The least amount of changes to the application required to complete setup.
|
126
|
-
|
127
|
-
※ The following is an example of a URL that has been translated by the library using the above URLs.
|
128
|
-
|
129
|
-
https://wovn.io/contact
|
130
|
-
|
131
|
-
### 2.5 lang_param_name
|
132
|
-
This parameter is only valid for when `url_pattern_name` is set to `'query'`.
|
133
|
-
|
134
|
-
It allows you to set the query parameter name for declaring the language of the
|
135
|
-
page. The default value for this setting is `'wovn'`, such that a page URL in
|
136
|
-
translated language English has the form
|
137
|
-
`https://my-website.com/index.php?wovn=en`. If you instead set the value to
|
138
|
-
`'lang'`, then the later URL example would have the form
|
139
|
-
`https://my-website.com/index.php?lang=en`.
|
140
|
-
|
141
|
-
### 2.6. query
|
142
|
-
|
143
|
-
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)
|
144
|
-
|
145
|
-
https://wovn.io/ja/contact?os=mac&keyboard=us
|
146
|
-
|
147
|
-
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.
|
148
|
-
|
149
|
-
https://wovn.io/contact
|
150
|
-
|
151
|
-
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.
|
152
|
-
|
153
|
-
https://wovn.io/contact?os=mac
|
154
|
-
|
155
|
-
### 2.7. ignore_class
|
156
|
-
|
157
|
-
This sets "Ignore class" which prevents WOVN from translating HTML elements that have a class contained in this array.
|
158
|
-
|
159
|
-
### 2.8. translate_fragment
|
160
|
-
|
161
|
-
This option allows to disable translating partial HTML content. By default,
|
162
|
-
partial HTML content is translated but no widget snippet is added. Set
|
163
|
-
`translate_fragment` to `false` to prevent translating partial HTML content.
|
164
|
-
|
165
|
-
### 2.9 ignore_paths
|
166
|
-
|
167
|
-
This parameter tells WOVN.rb to not localize content withing given directories.
|
168
|
-
|
169
|
-
The directories given will only be matched against the beginning of the URL path.
|
170
|
-
|
171
|
-
For instance, if you want to not localize the admin directory of your website, you should add the following to you WOVN.rb configuration.
|
172
|
-
```
|
173
|
-
'ignore_paths' => ['/admin/']
|
174
|
-
```
|
175
|
-
|
176
|
-
## 3. Contributing
|
177
|
-
|
178
|
-
1. Fork it ( https://github.com/WOVNio/wovnrb/fork )
|
179
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
180
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
181
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
182
|
-
5. Create a new Pull Request
|