wovnrb 0.2.07.1 → 0.2.08

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b65bd099a98b9832deb8a8ad6c0a76b2442727ec
4
- data.tar.gz: 2d65eb16175398584a2bebe3f80732d74d7cc3ec
3
+ metadata.gz: e03644873d29f35ebef11aa8713151b2a9d06ce3
4
+ data.tar.gz: b0b05d53c20087c7a693ec8b96d3c376c0ff7789
5
5
  SHA512:
6
- metadata.gz: 629628750b2196824f4e2be03e0f299f94989d115fc1042a43adc146f22d627d3dbabc78435f39e25d473cef2c72ac6449766ca2779e51c54082e4b12fa681c4
7
- data.tar.gz: fa5f22df24ad7726ab9a056718a0ac037ae95482142de2dc6e834a59d55d369398b584125bcb938b6c3a7d3d09d2ceff839e73f1ec6f68294bf4925ff43c8255
6
+ metadata.gz: 8a0faf6a9080d11261c51334f2e90f9b1e21117c28f5e4dc1c25edeecfc9ea78cd69bdb74c07f347d078c545e4ef3460b1e28060ed6da47c34f737b1d85c1af5
7
+ data.tar.gz: 5635239e563ed0397fa408c5a436aa0930cc84fefce5bab336089c263ec333d36bef0536005597ff4e82f06a3b97698d304b6abd5a89110ee6f5c287f077886d
@@ -205,7 +205,7 @@ module Wovnrb
205
205
 
206
206
  def out(headers)
207
207
  r = Regexp.new("//" + @host)
208
- if lang_code != @settings['default_lang'] && headers.has_key?("Location") && headers["Location"] =~ r
208
+ if headers.has_key?("Location") && headers["Location"] =~ r
209
209
  case @settings['url_pattern']
210
210
  when 'query'
211
211
  if headers["Location"] =~ /\?/
data/lib/wovnrb/lang.rb CHANGED
@@ -33,6 +33,16 @@ module Wovnrb
33
33
  'vi' => {name: 'Tiếng Việt', code: 'vi', en: 'Vietnamese'},
34
34
  }
35
35
 
36
+ # Provides the ISO639-1 code for a given lang code.
37
+ # Source: https://support.google.com/webmasters/answer/189077?hl=en
38
+ #
39
+ # @param lang_code [String] lang_code Code of the language.
40
+ #
41
+ # @return [String] The ISO639-1 code of the language.
42
+ def self.iso_639_1_normalization(lang_code)
43
+ return lang_code.sub(/zh-CHT/i, 'zh-Hant').sub(/zh-CHS/i, 'zh-Hans')
44
+ end
45
+
36
46
  def self.get_code(lang_name)
37
47
  return nil if lang_name.nil?
38
48
  return lang_name if LANG[lang_name]
@@ -137,7 +147,7 @@ module Wovnrb
137
147
  published_langs.each do |l|
138
148
  insert_node = Nokogiri::XML::Node.new('link', dom)
139
149
  insert_node['rel'] = 'alternate'
140
- insert_node['hreflang'] = l
150
+ insert_node['hreflang'] = Lang::iso_639_1_normalization(l)
141
151
  insert_node['href'] = headers.redirect_location(l)
142
152
  parent_node.add_child(insert_node)
143
153
  end
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = "0.2.07.1"
2
+ VERSION = "0.2.08"
3
3
  end
@@ -150,60 +150,6 @@ class HeadersTest < Minitest::Test
150
150
  assert_equal('http://wovn.io/test', env['HTTP_REFERER'])
151
151
  end
152
152
 
153
- def test_out_original_lang_with_subdomain_url_pattern
154
- h = Wovnrb::Headers.new(
155
- Wovnrb.get_env(
156
- 'SERVER_NAME' => 'wovn.io',
157
- 'REQUEST_URI' => '/test',
158
- 'HTTP_REFERER' => 'http://wovn.io/test',
159
- ),
160
- Wovnrb.get_settings(
161
- 'url_pattern' => 'subdomain',
162
- 'url_pattern_reg' => '^(?<lang>[^.]+).',
163
- ),
164
- )
165
- headers = h.request_out(h.lang_code)
166
- assert_equal('http://wovn.io/test', headers['HTTP_REFERER'])
167
- headers['Location'] = headers['HTTP_REFERER']
168
- assert_equal('http://wovn.io/test', h.out(headers)['Location'])
169
- end
170
-
171
- def test_out_original_lang_with_path_url_pattern
172
- h = Wovnrb::Headers.new(
173
- Wovnrb.get_env(
174
- 'SERVER_NAME' => 'wovn.io',
175
- 'REQUEST_URI' => '/test',
176
- 'HTTP_REFERER' => 'http://wovn.io/test',
177
- ),
178
- Wovnrb.get_settings(
179
- 'url_pattern' => 'path',
180
- 'url_pattern_reg' => '/(?<lang>[^/.?]+)',
181
- ),
182
- )
183
- headers = h.request_out(h.lang_code)
184
- assert_equal('http://wovn.io/test', headers['HTTP_REFERER'])
185
- headers['Location'] = headers['HTTP_REFERER']
186
- assert_equal('http://wovn.io/test', h.out(headers)['Location'])
187
- end
188
-
189
- def test_out_original_lang_with_query_url_pattern
190
- h = Wovnrb::Headers.new(
191
- Wovnrb.get_env(
192
- 'SERVER_NAME' => 'wovn.io',
193
- 'REQUEST_URI' => '/test',
194
- 'HTTP_REFERER' => 'http://wovn.io/test',
195
- ),
196
- Wovnrb.get_settings(
197
- 'url_pattern' => 'query',
198
- 'url_pattern_reg' => '((\\?.*&)|\\?)wovn=(?<lang>[^&]+)(&|$)',
199
- ),
200
- )
201
- headers = h.request_out(h.lang_code)
202
- assert_equal('http://wovn.io/test', headers['HTTP_REFERER'])
203
- headers['Location'] = headers['HTTP_REFERER']
204
- assert_equal('http://wovn.io/test', h.out(headers)['Location'])
205
- end
206
-
207
153
  #########################
208
154
  # GET SETTINGS
209
155
  #########################
@@ -22,6 +22,37 @@ module Wovnrb
22
22
  end
23
23
  end
24
24
 
25
+ def test_iso_639_1_normalization
26
+ assert_equal('ar', Lang::iso_639_1_normalization('ar'));
27
+ assert_equal('bg', Lang::iso_639_1_normalization('bg'));
28
+ assert_equal('zh-Hans', Lang::iso_639_1_normalization('zh-CHS'));
29
+ assert_equal('zh-Hant', Lang::iso_639_1_normalization('zh-CHT'));
30
+ assert_equal('da', Lang::iso_639_1_normalization('da'));
31
+ assert_equal('nl', Lang::iso_639_1_normalization('nl'));
32
+ assert_equal('en', Lang::iso_639_1_normalization('en'));
33
+ assert_equal('fi', Lang::iso_639_1_normalization('fi'));
34
+ assert_equal('fr', Lang::iso_639_1_normalization('fr'));
35
+ assert_equal('de', Lang::iso_639_1_normalization('de'));
36
+ assert_equal('el', Lang::iso_639_1_normalization('el'));
37
+ assert_equal('he', Lang::iso_639_1_normalization('he'));
38
+ assert_equal('id', Lang::iso_639_1_normalization('id'));
39
+ assert_equal('it', Lang::iso_639_1_normalization('it'));
40
+ assert_equal('ja', Lang::iso_639_1_normalization('ja'));
41
+ assert_equal('ko', Lang::iso_639_1_normalization('ko'));
42
+ assert_equal('ms', Lang::iso_639_1_normalization('ms'));
43
+ assert_equal('no', Lang::iso_639_1_normalization('no'));
44
+ assert_equal('pl', Lang::iso_639_1_normalization('pl'));
45
+ assert_equal('pt', Lang::iso_639_1_normalization('pt'));
46
+ assert_equal('ru', Lang::iso_639_1_normalization('ru'));
47
+ assert_equal('es', Lang::iso_639_1_normalization('es'));
48
+ assert_equal('sv', Lang::iso_639_1_normalization('sv'));
49
+ assert_equal('th', Lang::iso_639_1_normalization('th'));
50
+ assert_equal('hi', Lang::iso_639_1_normalization('hi'));
51
+ assert_equal('tr', Lang::iso_639_1_normalization('tr'));
52
+ assert_equal('uk', Lang::iso_639_1_normalization('uk'));
53
+ assert_equal('vi', Lang::iso_639_1_normalization('vi'));
54
+ end
55
+
25
56
  def test_get_code_with_valid_code
26
57
  assert_equal('ms', Wovnrb::Lang.get_code('ms'))
27
58
  end
@@ -372,6 +403,32 @@ module Wovnrb
372
403
  return values
373
404
  end
374
405
 
406
+ def test_switch_dom_lang_for_simplified_chinese
407
+ lang = Lang.new('ja')
408
+ h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
409
+ dom = generate_dom
410
+ values = generate_values
411
+ values['text_vals']['Simplified Chinese'] = {'zh-CHS' => [{data: 'test'}]}
412
+ url = h.url
413
+
414
+ swapped_body = lang.switch_dom_lang(dom, Store.instance, values, url, h)
415
+ assert(/hreflang="zh-Hans"/ =~ swapped_body)
416
+ assert(!(/hreflang="zh-CHS"/ =~ swapped_body))
417
+ end
418
+
419
+ def test_switch_dom_lang_for_traditional_chinese
420
+ lang = Lang.new('ja')
421
+ h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
422
+ dom = generate_dom
423
+ values = generate_values
424
+ values['text_vals']['Traditional Chinese'] = {'zh-CHT' => [{data: 'test'}]}
425
+ url = h.url
426
+
427
+ swapped_body = lang.switch_dom_lang(dom, Store.instance, values, url, h)
428
+ assert(/hreflang="zh-Hant"/ =~ swapped_body)
429
+ assert(!(/hreflang="zh-CHT"/ =~ swapped_body))
430
+ end
431
+
375
432
  def test_switch_lang
376
433
  lang = Lang.new('ja')
377
434
  h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
data/wovnrb.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  #spec.extensions = spec.files.grep(%r{/extconf\.rb$})
27
27
 
28
28
  spec.add_dependency "nokogumbo", "1.3.0"
29
- spec.add_dependency "activesupport"
29
+ spec.add_dependency "activesupport", "4.2.6"
30
30
  spec.add_dependency "lz4-ruby"
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.7"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wovnrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.07.1
4
+ version: 0.2.08
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-15 00:00:00.000000000 Z
12
+ date: 2016-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogumbo
@@ -29,16 +29,16 @@ dependencies:
29
29
  name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 4.2.6
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 4.2.6
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: lz4-ruby
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -364,7 +364,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
364
364
  version: '0'
365
365
  requirements: []
366
366
  rubyforge_project:
367
- rubygems_version: 2.2.0
367
+ rubygems_version: 2.6.3
368
368
  signing_key:
369
369
  specification_version: 4
370
370
  summary: Gem for WOVN.io