wovnrb 3.0.1 → 3.3.1
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/.circleci/config.yml +21 -10
- data/.rubocop_todo.yml +9 -44
- data/Gemfile +0 -5
- data/README.en.md +21 -16
- data/README.ja.md +6 -6
- data/docker/docker-compose.yml +5 -0
- data/docker/rails/TestSite/Gemfile +1 -1
- data/docker/rails/TestSite/app/controllers/custom_response_controller.rb +16 -0
- data/docker/rails/TestSite/config/routes.rb +1 -0
- data/docker/rails/TestSite/start.sh +1 -0
- data/docker/rails/TestSite/yarn.lock +12 -12
- data/lib/wovnrb/api_translator.rb +39 -17
- data/lib/wovnrb/headers.rb +30 -39
- data/lib/wovnrb/helpers/nokogumbo_helper.rb +7 -9
- data/lib/wovnrb/lang.rb +15 -14
- data/lib/wovnrb/railtie.rb +3 -1
- data/lib/wovnrb/services/html_converter.rb +8 -8
- data/lib/wovnrb/services/wovn_logger.rb +9 -2
- data/lib/wovnrb/store.rb +16 -17
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +2 -4
- data/test/lib/api_translator_test.rb +48 -9
- data/test/lib/headers_test.rb +2 -2
- data/test/lib/lang_test.rb +5 -136
- data/test/lib/services/html_converter_test.rb +14 -14
- data/test/lib/services/wovn_logger_test.rb +5 -3
- data/test/lib/store_test.rb +22 -16
- data/test/lib/wovnrb_test.rb +16 -16
- data/wovnrb.gemspec +2 -1
- metadata +10 -10
- data/.travis.yml +0 -14
- data/lib/wovnrb/text_caches/cache_base.rb +0 -53
- data/lib/wovnrb/text_caches/memory_cache.rb +0 -51
- data/test/lib/text_caches/cache_base_test.rb +0 -31
- data/test/lib/text_caches/memory_cache_test.rb +0 -91
data/lib/wovnrb/lang.rb
CHANGED
@@ -146,46 +146,47 @@ module Wovnrb
|
|
146
146
|
if uri.host.downcase === headers.host.downcase
|
147
147
|
case pattern
|
148
148
|
when 'subdomain'
|
149
|
-
sub_d = href.match(/\/\/([
|
149
|
+
sub_d = href.match(/\/\/([^.]*)\./)[1]
|
150
150
|
sub_code = Lang.get_code(sub_d)
|
151
151
|
new_href = if sub_code && sub_code.casecmp(code_to_add).zero?
|
152
152
|
href.sub(Regexp.new(code_to_add, 'i'), code_to_add.downcase)
|
153
153
|
else
|
154
|
-
href.sub(/(\/\/)([
|
154
|
+
href.sub(/(\/\/)([^.]*)/, "\\1#{code_to_add.downcase}.\\2")
|
155
155
|
end
|
156
156
|
when 'query'
|
157
157
|
new_href = add_query_lang_code(href, code_to_add, lang_param_name)
|
158
158
|
else # path
|
159
|
-
new_href = href.sub(/([
|
159
|
+
new_href = href.sub(/([^.]*\.[^\/]*)(\/|$)/, "\\1/#{code_to_add}/")
|
160
160
|
end
|
161
161
|
end
|
162
162
|
elsif href
|
163
163
|
case pattern
|
164
164
|
when 'subdomain'
|
165
|
-
lang_url = headers.protocol
|
166
|
-
current_dir = headers.pathname.sub(/[^\/]*\.[
|
167
|
-
new_href =
|
165
|
+
lang_url = "#{headers.protocol}://#{code_to_add.downcase}.#{headers.host}"
|
166
|
+
current_dir = headers.pathname.sub(/[^\/]*\.[^.]{2,6}$/, '')
|
167
|
+
new_href = case href
|
168
|
+
when /^\.\..*$/
|
168
169
|
# ../path
|
169
|
-
lang_url
|
170
|
-
|
170
|
+
"#{lang_url}/#{href.gsub(/^\.\.\//, '')}"
|
171
|
+
when /^\..*$/
|
171
172
|
# ./path
|
172
|
-
lang_url
|
173
|
-
|
173
|
+
"#{lang_url}#{current_dir}/#{href.gsub(/^\.\//, '')}"
|
174
|
+
when /^\/.*$/
|
174
175
|
# /path
|
175
176
|
lang_url + href
|
176
177
|
else
|
177
178
|
# path
|
178
|
-
lang_url
|
179
|
+
"#{lang_url}#{current_dir}/#{href}"
|
179
180
|
end
|
180
181
|
when 'query'
|
181
182
|
new_href = add_query_lang_code(href, code_to_add, lang_param_name)
|
182
183
|
else # path
|
183
184
|
if href =~ /^\//
|
184
|
-
new_href =
|
185
|
+
new_href = "/#{code_to_add}#{href}"
|
185
186
|
else
|
186
|
-
current_dir = headers.pathname.sub(/[^\/]*\.[
|
187
|
+
current_dir = headers.pathname.sub(/[^\/]*\.[^.]{2,6}$/, '')
|
187
188
|
current_dir = '/' if current_dir == ''
|
188
|
-
new_href =
|
189
|
+
new_href = "/#{code_to_add}#{current_dir}#{href}"
|
189
190
|
end
|
190
191
|
end
|
191
192
|
end
|
data/lib/wovnrb/railtie.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Wovnrb
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
initializer 'wovnrb.configure_rails_initialization' do |app|
|
4
|
-
|
4
|
+
install_middleware = Rails.configuration.wovnrb.fetch(:install_middleware, true)
|
5
|
+
|
6
|
+
app.middleware.insert_before(0, Wovnrb::Interceptor) if install_middleware
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
@@ -41,7 +41,7 @@ module Wovnrb
|
|
41
41
|
|
42
42
|
@dom.traverse { |node| transform_node(node, marker) }
|
43
43
|
|
44
|
-
insert_snippet(true)
|
44
|
+
insert_snippet(adds_backend_error_mark: true)
|
45
45
|
insert_hreflang_tags
|
46
46
|
inject_lang_html_tag
|
47
47
|
|
@@ -79,7 +79,7 @@ module Wovnrb
|
|
79
79
|
return unless classes.present?
|
80
80
|
|
81
81
|
ignored_classes = @store.settings['ignore_class']
|
82
|
-
should_be_ignored = (ignored_classes & classes.split
|
82
|
+
should_be_ignored = (ignored_classes & classes.split).present?
|
83
83
|
|
84
84
|
put_replace_marker(node, marker) if should_be_ignored
|
85
85
|
end
|
@@ -147,25 +147,25 @@ module Wovnrb
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def widget_urls
|
150
|
-
[@store.settings['api_url']
|
150
|
+
["#{@store.settings['api_url']}/widget", 'j.wovn.io', 'j.dev-wovn.io:3000']
|
151
151
|
end
|
152
152
|
|
153
|
-
def insert_snippet(adds_backend_error_mark
|
153
|
+
def insert_snippet(adds_backend_error_mark: true)
|
154
154
|
parent_node = @dom.at_css('head') || @dom.at_css('body') || @dom.at_css('html')
|
155
155
|
return unless parent_node
|
156
156
|
|
157
157
|
insert_node = Nokogiri::XML::Node.new('script', @dom)
|
158
|
-
insert_node['src'] =
|
158
|
+
insert_node['src'] = @store.widget_url
|
159
159
|
insert_node['async'] = true
|
160
160
|
insert_node['data-wovnio'] = data_wovnio
|
161
161
|
insert_node['data-wovnio-type'] = 'fallback_snippet' if adds_backend_error_mark
|
162
162
|
# do this so that there will be a closing tag (better compatibility with browsers)
|
163
163
|
insert_node.content = ''
|
164
164
|
|
165
|
-
if
|
166
|
-
parent_node.children.first.add_previous_sibling(insert_node)
|
167
|
-
else
|
165
|
+
if parent_node.children.empty?
|
168
166
|
parent_node.add_child(insert_node)
|
167
|
+
else
|
168
|
+
parent_node.children.first.add_previous_sibling(insert_node)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -3,15 +3,22 @@ require 'logger' unless defined?(Logger)
|
|
3
3
|
|
4
4
|
module Wovnrb
|
5
5
|
class WovnLogger
|
6
|
+
attr_reader :uuid
|
7
|
+
|
6
8
|
include Singleton
|
7
9
|
|
8
10
|
class << self
|
9
11
|
def error(message)
|
10
12
|
instance.error(message)
|
11
13
|
end
|
14
|
+
|
15
|
+
def uuid
|
16
|
+
instance.uuid
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
20
|
def initialize
|
21
|
+
@uuid = SecureRandom.uuid
|
15
22
|
path = Store.instance.settings['log_path']
|
16
23
|
if path
|
17
24
|
begin
|
@@ -40,9 +47,9 @@ module Wovnrb
|
|
40
47
|
|
41
48
|
def error(message)
|
42
49
|
if @logger == $stderr
|
43
|
-
@logger.puts "Wovnrb Error: #{message}"
|
50
|
+
@logger.puts "[#{@uuid}] Wovnrb Error: #{message}"
|
44
51
|
else
|
45
|
-
@logger.error message
|
52
|
+
@logger.error "[#{@uuid}] #{message}"
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
data/lib/wovnrb/store.rb
CHANGED
@@ -25,8 +25,8 @@ module Wovnrb
|
|
25
25
|
'ignore_class' => [],
|
26
26
|
'api_url' => 'https://wovn.global.ssl.fastly.net',
|
27
27
|
'api_timeout_seconds' => 1.0,
|
28
|
-
'default_lang' => '
|
29
|
-
'supported_langs' => [
|
28
|
+
'default_lang' => 'ja',
|
29
|
+
'supported_langs' => %w[en ja],
|
30
30
|
'test_mode' => false,
|
31
31
|
'test_url' => '',
|
32
32
|
'cache_megabytes' => nil,
|
@@ -34,7 +34,9 @@ module Wovnrb
|
|
34
34
|
'use_proxy' => false, # use env['HTTP_X_FORWARDED_HOST'] instead of env['HTTP_HOST'] and env['SERVER_NAME'] when this setting is true.
|
35
35
|
'custom_lang_aliases' => {},
|
36
36
|
'translate_fragment' => true,
|
37
|
-
'
|
37
|
+
'widget_url' => 'https://j.wovn.io/1',
|
38
|
+
'wovn_dev_mode' => false,
|
39
|
+
'compress_api_requests' => true
|
38
40
|
)
|
39
41
|
end
|
40
42
|
|
@@ -141,19 +143,16 @@ module Wovnrb
|
|
141
143
|
end
|
142
144
|
@settings.delete('user_token')
|
143
145
|
|
144
|
-
|
146
|
+
case @settings['url_pattern']
|
147
|
+
when 'path'
|
145
148
|
@settings['url_pattern_reg'] = "/(?<lang>[^/.?]+)"
|
146
|
-
|
149
|
+
when 'query'
|
147
150
|
@settings['url_pattern_reg'] = "((\\?.*&)|\\?)#{@settings['lang_param_name']}=(?<lang>[^&]+)(&|$)"
|
148
|
-
|
151
|
+
when 'subdomain'
|
149
152
|
@settings['url_pattern_reg'] = "^(?<lang>[^.]+)\."
|
150
153
|
end
|
151
154
|
|
152
|
-
@settings['test_mode'] =
|
153
|
-
false
|
154
|
-
else
|
155
|
-
true
|
156
|
-
end
|
155
|
+
@settings['test_mode'] = !(@settings['test_mode'] != true || @settings['test_mode'] != 'on')
|
157
156
|
|
158
157
|
if @settings['wovn_dev_mode']
|
159
158
|
if @settings['api_url'] == self.class.default_settings['api_url']
|
@@ -183,12 +182,12 @@ module Wovnrb
|
|
183
182
|
@settings['supported_langs'] || []
|
184
183
|
end
|
185
184
|
|
186
|
-
def
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
185
|
+
def compress_api_requests?
|
186
|
+
@settings['compress_api_requests']
|
187
|
+
end
|
188
|
+
|
189
|
+
def widget_url
|
190
|
+
@settings['widget_url'] || 'https://j.wovn.io/1'
|
192
191
|
end
|
193
192
|
|
194
193
|
def dev_mode?
|
data/lib/wovnrb/version.rb
CHANGED
data/lib/wovnrb.rb
CHANGED
@@ -9,7 +9,6 @@ require 'nokogumbo'
|
|
9
9
|
require 'active_support'
|
10
10
|
require 'json'
|
11
11
|
require 'wovnrb/helpers/nokogumbo_helper'
|
12
|
-
require 'wovnrb/text_caches/cache_base'
|
13
12
|
require 'wovnrb/railtie' if defined?(Rails)
|
14
13
|
require 'wovnrb/version'
|
15
14
|
|
@@ -18,9 +17,8 @@ module Wovnrb
|
|
18
17
|
def initialize(app, opts = {})
|
19
18
|
@app = app
|
20
19
|
@store = Store.instance
|
21
|
-
opts = opts.
|
20
|
+
opts = opts.transform_keys(&:to_s)
|
22
21
|
@store.update_settings(opts)
|
23
|
-
CacheBase.set_single(@store.settings)
|
24
22
|
end
|
25
23
|
|
26
24
|
def call(env)
|
@@ -82,7 +80,7 @@ module Wovnrb
|
|
82
80
|
|
83
81
|
if needs_api?(html_body, headers)
|
84
82
|
converted_html, marker = html_converter.build_api_compatible_html
|
85
|
-
translated_content = ApiTranslator.new(@store, headers).translate(converted_html)
|
83
|
+
translated_content = ApiTranslator.new(@store, headers, WovnLogger.uuid).translate(converted_html)
|
86
84
|
translated_body.push(marker.revert(translated_content))
|
87
85
|
else
|
88
86
|
string_body = html_converter.build if html_body.html?
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
module Wovnrb
|
4
|
+
REQUEST_UUID = 'ABCD'.freeze
|
5
|
+
|
4
6
|
class ApiTranslatorTest < WovnMiniTest
|
5
7
|
def test_translate
|
6
8
|
assert_translation('test.html', 'test_translated.html', true)
|
@@ -24,6 +26,38 @@ module Wovnrb
|
|
24
26
|
assert_translation('test.html', 'test_translated.html', true, encoding: 'text/json')
|
25
27
|
end
|
26
28
|
|
29
|
+
def test_translate_without_api_compression_sends_json
|
30
|
+
Wovnrb::Store.instance.update_settings('compress_api_requests' => false)
|
31
|
+
sut, _store, _headers = create_sut
|
32
|
+
html_body = 'foo'
|
33
|
+
|
34
|
+
stub_request(:post, %r{http://wovn\.global\.ssl\.fastly\.net/v0/translation\?cache_key=.*})
|
35
|
+
.to_return(status: 200, body: { 'body' => 'translated_body' }.to_json)
|
36
|
+
|
37
|
+
sut.translate(html_body)
|
38
|
+
|
39
|
+
assert_requested :post, %r{http://wovn\.global\.ssl\.fastly\.net/v0/translation\?cache_key=.*},
|
40
|
+
headers: {
|
41
|
+
'Accept' => '*/*',
|
42
|
+
'Accept-Encoding' => 'gzip',
|
43
|
+
'Content-Type' => 'application/json',
|
44
|
+
'User-Agent' => 'Ruby',
|
45
|
+
'X-Request-Id' => REQUEST_UUID
|
46
|
+
},
|
47
|
+
body: {
|
48
|
+
'url' => 'http://wovn.io/test',
|
49
|
+
'token' => '123456',
|
50
|
+
'lang_code' => 'fr',
|
51
|
+
'url_pattern' => 'subdomain',
|
52
|
+
'lang_param_name' => 'lang',
|
53
|
+
'product' => 'WOVN.rb',
|
54
|
+
'version' => VERSION,
|
55
|
+
'body' => 'foo',
|
56
|
+
'custom_lang_aliases' => { 'ja' => 'Japanese' }.to_json
|
57
|
+
}.to_json,
|
58
|
+
times: 1
|
59
|
+
end
|
60
|
+
|
27
61
|
private
|
28
62
|
|
29
63
|
def assert_translation(original_html_fixture, translated_html_fixture, success_expected, response = { encoding: 'gzip', status_code: 200 })
|
@@ -39,6 +73,15 @@ module Wovnrb
|
|
39
73
|
end
|
40
74
|
|
41
75
|
def translate(original_html, translated_html, response)
|
76
|
+
api_translator, store, headers = create_sut
|
77
|
+
translation_request_stub = stub_translation_api_request(store, headers, original_html, translated_html, response)
|
78
|
+
|
79
|
+
actual_translated_html = api_translator.translate(original_html)
|
80
|
+
assert_requested(translation_request_stub, times: 1) if translation_request_stub
|
81
|
+
actual_translated_html
|
82
|
+
end
|
83
|
+
|
84
|
+
def create_sut
|
42
85
|
settings = {
|
43
86
|
'project_token' => '123456',
|
44
87
|
'custom_lang_aliases' => { 'ja' => 'Japanese' },
|
@@ -53,12 +96,9 @@ module Wovnrb
|
|
53
96
|
Wovnrb.get_env('url' => 'http://fr.wovn.io/test'),
|
54
97
|
Wovnrb.get_settings(settings)
|
55
98
|
)
|
56
|
-
api_translator = ApiTranslator.new(store, headers)
|
57
|
-
translation_request_stub = stub_translation_api_request(store, headers, original_html, translated_html, response)
|
99
|
+
api_translator = ApiTranslator.new(store, headers, REQUEST_UUID)
|
58
100
|
|
59
|
-
|
60
|
-
assert_requested(translation_request_stub, times: 1) if translation_request_stub
|
61
|
-
actual_translated_html
|
101
|
+
[api_translator, store, headers]
|
62
102
|
end
|
63
103
|
|
64
104
|
def stub_translation_api_request(store, headers, original_html, translated_html, response)
|
@@ -85,11 +125,10 @@ module Wovnrb
|
|
85
125
|
compress(stub_response_json)
|
86
126
|
end
|
87
127
|
response_headers = { 'Content-Encoding' => response[:encoding] || 'gzip' }
|
88
|
-
|
89
|
-
|
90
|
-
|
128
|
+
stub_request(:post, api_url)
|
129
|
+
.with(body: compressed_data, headers: headers)
|
130
|
+
.to_return(status: response[:status_code] || 200, body: stub_response, headers: response_headers)
|
91
131
|
|
92
|
-
stub
|
93
132
|
end
|
94
133
|
end
|
95
134
|
|
data/test/lib/headers_test.rb
CHANGED
@@ -170,7 +170,7 @@ module Wovnrb
|
|
170
170
|
Wovnrb.get_env('url' => 'http://wovn.io/contact', 'HTTP_X_FORWARDED_HOST' => 'wovn.io'),
|
171
171
|
Store.instance.settings
|
172
172
|
)
|
173
|
-
assert_equal('http://wovn.io/contact?wovn=
|
173
|
+
assert_equal('http://wovn.io/contact?wovn=en', sut.redirect_location('en'))
|
174
174
|
end
|
175
175
|
|
176
176
|
def test_redirect_location_with_lang_param_name
|
@@ -179,7 +179,7 @@ module Wovnrb
|
|
179
179
|
Wovnrb.get_env('url' => 'http://wovn.io/contact', 'HTTP_X_FORWARDED_HOST' => 'wovn.io'),
|
180
180
|
Store.instance.settings
|
181
181
|
)
|
182
|
-
assert_equal('http://wovn.io/contact?lang=
|
182
|
+
assert_equal('http://wovn.io/contact?lang=en', sut.redirect_location('en'))
|
183
183
|
end
|
184
184
|
|
185
185
|
#########################
|
data/test/lib/lang_test.rb
CHANGED
@@ -21,9 +21,10 @@ module Wovnrb
|
|
21
21
|
|
22
22
|
def test_iso_639_1_normalization
|
23
23
|
Wovnrb::Lang::LANG.each do |_, l|
|
24
|
-
|
24
|
+
case l[:code]
|
25
|
+
when 'zh-CHS'
|
25
26
|
assert_equal('zh-Hans', Lang.iso_639_1_normalization('zh-CHS'))
|
26
|
-
|
27
|
+
when 'zh-CHT'
|
27
28
|
assert_equal('zh-Hant', Lang.iso_639_1_normalization('zh-CHT'))
|
28
29
|
else
|
29
30
|
assert_equal(l[:code], Lang.iso_639_1_normalization(l[:code]))
|
@@ -89,7 +90,7 @@ module Wovnrb
|
|
89
90
|
assert_equal('http://zh-cht.wovn.io/topics/31', lang.add_lang_code('http://wovn.io/topics/31', 'subdomain', h))
|
90
91
|
end
|
91
92
|
|
92
|
-
def
|
93
|
+
def test_add_lang_code_trad_chinese2
|
93
94
|
lang = Lang.new('zh-cht')
|
94
95
|
h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://zh-cht.wovn.io'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
95
96
|
assert_equal('http://zh-cht.wovn.io/topics/31', lang.add_lang_code('/topics/31', 'subdomain', h))
|
@@ -107,7 +108,7 @@ module Wovnrb
|
|
107
108
|
assert_equal('//zh-cht.google.com', lang.add_lang_code('//google.com', 'subdomain', h))
|
108
109
|
end
|
109
110
|
|
110
|
-
def
|
111
|
+
def test_add_lang_code_no_protocol2
|
111
112
|
lang = Lang.new('zh-cht')
|
112
113
|
h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'https://zh-cht.wovn.io'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
113
114
|
assert_equal('//google.com', lang.add_lang_code('//google.com', 'subdomain', h))
|
@@ -311,138 +312,6 @@ module Wovnrb
|
|
311
312
|
assert_equal('/fr/index.html', lang.add_lang_code('index.html', 'path', headers))
|
312
313
|
end
|
313
314
|
|
314
|
-
def generate_body(param = '')
|
315
|
-
body = case param
|
316
|
-
when 'ignore_parent'
|
317
|
-
"<html><body><h1>Mr. Belvedere Fan Club</h1>
|
318
|
-
<div wovn-ignore><p>Hello</p></div>
|
319
|
-
</body></html>"
|
320
|
-
when 'ignore_everything'
|
321
|
-
"<html><body wovn-ignore><h1>Mr. Belvedere Fan Club</h1>
|
322
|
-
<div><p>Hello</p></div>
|
323
|
-
</body></html>"
|
324
|
-
when 'ignore_parent_translated_in_japanese'
|
325
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://ignore-page.com/\"></head><body><h1><!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
326
|
-
<div wovn-ignore=\"\"><p>Hello</p></div>
|
327
|
-
</body></html>
|
328
|
-
"
|
329
|
-
when 'translated_in_japanese'
|
330
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://page.com/\"></head><body><h1><!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
331
|
-
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
332
|
-
</body></html>
|
333
|
-
"
|
334
|
-
when 'ignore_everything_translated'
|
335
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://ignore-page.com/\"></head><body wovn-ignore=\"\"><h1>Mr. Belvedere Fan Club</h1>
|
336
|
-
<div><p>Hello</p></div>
|
337
|
-
</body></html>
|
338
|
-
"
|
339
|
-
when 'empty'
|
340
|
-
'<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore><p>Hello</p></div></body></html>'
|
341
|
-
when 'empty_single_quote'
|
342
|
-
"<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=''><p>Hello</p></div></body></html>"
|
343
|
-
when 'empty_double_quote'
|
344
|
-
'<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=''><p>Hello</p></div></body></html>'
|
345
|
-
when 'value_single_quote'
|
346
|
-
"<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore='value'><p>Hello</p></div></body></html>"
|
347
|
-
when 'value_double_quote'
|
348
|
-
'<html><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore="value"><p>Hello</p></div></body></html>'
|
349
|
-
when 'empty_translated'
|
350
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://ignore-page.com/\"></head><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=\"\"><p>Hello</p></div></body></html>\n"
|
351
|
-
when 'empty_single_quote_translated'
|
352
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://ignore-page.com/\"></head><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=\"\"><p>Hello</p></div></body></html>\n"
|
353
|
-
when 'empty_double_quote_translated'
|
354
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://ignore-page.com/\"></head><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=\"\"><p>Hello</p></div></body></html>\n"
|
355
|
-
when 'value_single_quote_translated'
|
356
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://ignore-page.com/\"></head><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=\"value\"><p>Hello</p></div></body></html>\n"
|
357
|
-
when 'value_double_quote_translated'
|
358
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://ignore-page.com/\"></head><body><h1>Mr.BelvedereFanClub</h1><div wovn-ignore=\"value\"><p>Hello</p></div></body></html>\n"
|
359
|
-
when 'meta_img_alt_tags_translated'
|
360
|
-
"<html lang=\"ja\"><head><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"description\" content=\"こんにちは\">\n<meta name=\"title\" content=\"こんにちは\">\n<meta property=\"og:title\" content=\"こんにちは\">\n<meta property=\"og:description\" content=\"こんにちは\">\n<meta property=\"twitter:title\" content=\"こんにちは\">\n<meta property=\"twitter:description\" content=\"こんにちは\"><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://page.com/\"></head>\n<body><h1><!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>\n<div><p><!--wovn-src:Hello-->こんにちは</p></div>\n<!--wovn-src:Hello--><img src=\"http://example.com/photo.png\" alt=\"こんにちは\">\n</body></html>\n"
|
361
|
-
when 'meta_img_alt_tags'
|
362
|
-
"<html><head><meta name =\"description\" content=\"Hello\">\n<meta name=\"title\" content=\"Hello\">\n<meta property=\"og:title\" content=\"Hello\">\n<meta property=\"og:description\" content=\"Hello\">\n<meta property=\"twitter:title\" content=\"Hello\">\n<meta property=\"twitter:description\" content=\"Hello\"></head>
|
363
|
-
<body><h1>Mr. Belvedere Fan Club</h1>
|
364
|
-
<div><p>Hello</p></div>
|
365
|
-
<img src=\"http://example.com/photo.png\" alt=\"Hello\">
|
366
|
-
</body></html>"
|
367
|
-
when 'a_href_javascript'
|
368
|
-
"<html><body><h1>Mr. Belvedere Fan Club</h1>
|
369
|
-
<div><p><a href=\"javascript:void(0)\">Hello</a></p></div>
|
370
|
-
</body></html>"
|
371
|
-
when 'a_href_javascript_translated'
|
372
|
-
"<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\"><link rel=\"alternate\" hreflang=\"en\" href=\"http://page.com/\"></head><body><h1><!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
373
|
-
<div><p><a href=\"javascript:void(0)\"><!--wovn-src:Hello-->こんにちは</a></p></div>
|
374
|
-
</body></html>
|
375
|
-
"
|
376
|
-
when 'unified_values'
|
377
|
-
<<-HTML
|
378
|
-
<html><body>
|
379
|
-
<div>
|
380
|
-
a <span>b</span> c
|
381
|
-
</div>
|
382
|
-
<div>
|
383
|
-
a<span>b</span>
|
384
|
-
</div>
|
385
|
-
<div>
|
386
|
-
<span> b </span>c
|
387
|
-
</div>
|
388
|
-
</body></html>
|
389
|
-
HTML
|
390
|
-
|
391
|
-
when 'unified_values_ja'
|
392
|
-
<<-HTML
|
393
|
-
<html lang=\"ja\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"en\" href=\"http://page.com/\"></head><body>
|
394
|
-
<div><!--wovn-src:
|
395
|
-
a -->\u3042<span><!--wovn-src:b-->\u3044</span><!--wovn-src: c
|
396
|
-
-->\u3046</div>
|
397
|
-
<div><!--wovn-src:
|
398
|
-
a-->\u200B<span><!--wovn-src:b-->\u3044</span><!--wovn-src:-->\u3046
|
399
|
-
</div>
|
400
|
-
<div>
|
401
|
-
<!--wovn-src:-->\u3042<span><!--wovn-src: b -->\u3044</span><!--wovn-src:c
|
402
|
-
-->\u200B</div>
|
403
|
-
|
404
|
-
</body></html>
|
405
|
-
HTML
|
406
|
-
|
407
|
-
else # "" case
|
408
|
-
"<html><body><h1>Mr. Belvedere Fan Club</h1>
|
409
|
-
<div><p>Hello</p></div>
|
410
|
-
</body></html>"
|
411
|
-
end
|
412
|
-
|
413
|
-
body
|
414
|
-
end
|
415
|
-
|
416
|
-
def generate_dom(param = '')
|
417
|
-
Wovnrb.to_dom(generate_body(param))
|
418
|
-
end
|
419
|
-
|
420
|
-
def generate_values
|
421
|
-
values = {}
|
422
|
-
values['text_vals'] = {
|
423
|
-
'Hello' => { 'ja' => [{ 'data' => 'こんにちは' }] },
|
424
|
-
'Mr. Belvedere Fan Club' => { 'ja' => [{ 'data' => 'ベルベデアさんファンクラブ' }] }
|
425
|
-
}
|
426
|
-
values
|
427
|
-
end
|
428
|
-
|
429
|
-
def generate_unified_values
|
430
|
-
{
|
431
|
-
'html_text_vals' => {
|
432
|
-
'a<span>b</span>c' =>
|
433
|
-
{ 'ja' =>
|
434
|
-
[{ 'data' => 'あ<span>い</span>う' }] },
|
435
|
-
'a<span>b</span>' =>
|
436
|
-
{ 'ja' =>
|
437
|
-
[{ 'data' => '<span>い</span>う' }] },
|
438
|
-
'<span>b</span>c' =>
|
439
|
-
{ 'ja' =>
|
440
|
-
[{ 'data' => 'あ<span>い</span>' }] }
|
441
|
-
|
442
|
-
}
|
443
|
-
}
|
444
|
-
end
|
445
|
-
|
446
315
|
def test_get_code_from_custom_lang
|
447
316
|
store = Store.instance
|
448
317
|
store.settings['custom_lang_aliases'] = { 'ja' => 'staging-ja' }
|