wovnrb 2.2.0 → 2.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21db13334fd0ceefeba7a6d0f23a13c035d8ca2e97796f2c5342659369b4a5d9
4
- data.tar.gz: 6453345eb832513563decad6050d3b44d2f100c203c8e0f3f9cbbd8d6cc833b5
3
+ metadata.gz: a1667b83e9b8a2a2a79d1c152c71fac66ecc1acfe98b53f062e6929dda1d267c
4
+ data.tar.gz: 6fe79d1445f3e87ebd65e9d5beca3c173da6e3ae25e92de97c9b85bed95c8547
5
5
  SHA512:
6
- metadata.gz: a43841cb1cd9a2fcda906663b8c8a5d46e751e37d202591f42d7eea17603df6523e8eca82538c49b7db20e9d3b1d8fd51d5e64e482ee71422384f109f699eef3
7
- data.tar.gz: 6e87c0aa31e2b6853d295e600ba6fef63beb3cc5d0154a872e19a51cdc3a6d7828b1bc7ea21346dfee72c888576885256d11c84e1085608e2a5c55e693312359
6
+ metadata.gz: 560317e910fdf2966f10919126b8e7ec255ce07a9325bcd24c610eda52bb2686347e76e7123e9ffe0c22d7373220aab5e270b3d63a324dda1acec6c5a1c0d9cb
7
+ data.tar.gz: dbcb9693c55eb8a5b7e77d1b98e53d1bd8ae15989d498e585505a2b04137bf068ab20f4efedf4205c1c412d2882e33774875ffa14294635e2e0f1772efbda08a
data/.rubocop_todo.yml CHANGED
@@ -29,7 +29,7 @@ Layout/ExtraSpacing:
29
29
  # Cop supports --auto-correct.
30
30
  # Configuration parameters: EnforcedStyle, IndentationWidth.
31
31
  # SupportedStyles: special_inside_parentheses, consistent, align_braces
32
- Layout/IndentFirstHashElement:
32
+ Layout/FirstHashElementIndentation:
33
33
  Exclude:
34
34
  - 'lib/wovnrb/text_caches/cache_base.rb'
35
35
 
@@ -37,7 +37,7 @@ Layout/IndentFirstHashElement:
37
37
  # Cop supports --auto-correct.
38
38
  # Configuration parameters: EnforcedStyle.
39
39
  # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
40
- Layout/IndentHeredoc:
40
+ Layout/HeredocIndentation:
41
41
  Exclude:
42
42
  - 'test/lib/lang_test.rb'
43
43
  - 'test/lib/wovnrb_test.rb'
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
@@ -32,14 +32,21 @@ module Wovnrb
32
32
 
33
33
  @env = env
34
34
  headers = Headers.new(env, @store.settings)
35
+ default_lang = @store.settings['default_lang']
35
36
  return @app.call(env) if @store.settings['test_mode'] && @store.settings['test_url'] != headers.url
36
37
 
37
38
  # redirect if the path is set to the default language (for SEO purposes)
38
- if headers.path_lang == @store.settings['default_lang']
39
- redirect_headers = headers.redirect(@store.settings['default_lang'])
39
+ if headers.path_lang == default_lang
40
+ redirect_headers = headers.redirect(default_lang)
40
41
  return [307, redirect_headers, ['']]
41
42
  end
42
43
 
44
+ # if path containing language code is ignored, do nothing
45
+ if headers.lang_code != default_lang && ignore_path?(headers.unmasked_pathname_without_trailing_slash)
46
+ status, res_headers, body = @app.call(env)
47
+
48
+ return output(headers, status, res_headers, body)
49
+ end
43
50
  # pass to application
44
51
  status, res_headers, body = @app.call(headers.request_out)
45
52
 
@@ -51,7 +58,7 @@ module Wovnrb
51
58
  return output(headers, status, res_headers, body) if request.params['wovn_disable'] == true
52
59
 
53
60
  @store.settings.update_dynamic_settings!(request.params)
54
- return output(headers, status, res_headers, body) if @store.settings['ignore_globs'].any? { |g| g.match?(headers.pathname) }
61
+ return output(headers, status, res_headers, body) if ignore_path?(headers.pathname)
55
62
 
56
63
  body = switch_lang(headers, body) unless status.to_s =~ /^1|302/
57
64
 
@@ -102,7 +109,11 @@ module Wovnrb
102
109
  end
103
110
 
104
111
  def wovn_ignored?(html_body)
105
- !html_body.xpath('//html[@wovn-ignore]').empty?
112
+ !html_body.xpath('//html[@wovn-ignore or @data-wovn-ignore]').empty?
113
+ end
114
+
115
+ def ignore_path?(path)
116
+ @store.settings['ignore_globs'].ignore?(path)
106
117
  end
107
118
 
108
119
  # Checks if a given HTML body is an Accelerated Mobile Page (AMP).
@@ -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.
@@ -30,7 +29,7 @@ module Wovnrb
30
29
  end
31
30
  # REQUEST_URI is expected to not contain the server name
32
31
  # heroku contains http://...
33
- @env['REQUEST_URI'] = @env['REQUEST_URI'].sub(/^.*:\/\/[^\/]+/, '') if @env['REQUEST_URI'] =~ /:\/\//
32
+ @env['REQUEST_URI'] = @env['REQUEST_URI'].sub(/^https?:\/\/[^\/]+/, '') if @env['REQUEST_URI'] =~ /^https?:\/\//
34
33
  @unmasked_pathname = @env['REQUEST_URI'].split('?')[0]
35
34
  @unmasked_pathname += '/' unless @unmasked_pathname =~ /\/$/ || @unmasked_pathname =~ /\/[^\/.]+\.[^\/.]+$/
36
35
  @unmasked_url = "#{@protocol}://#{@unmasked_host}#{@unmasked_pathname}"
@@ -39,7 +38,6 @@ module Wovnrb
39
38
  else
40
39
  @env['HTTP_HOST']
41
40
  end
42
- @env['wovnrb.target_lang'] = lang_code
43
41
  @host = settings['url_pattern'] == 'subdomain' ? remove_lang(@host, lang_code) : @host
44
42
  @pathname, @query = @env['REQUEST_URI'].split('?')
45
43
  @pathname = settings['url_pattern'] == 'path' ? remove_lang(@pathname, lang_code) : @pathname
@@ -63,7 +61,10 @@ module Wovnrb
63
61
  @query = remove_lang(@query, lang_code)
64
62
  @pathname_with_trailing_slash_if_present = @pathname
65
63
  @pathname = @pathname.gsub(/\/$/, '')
66
- @redis_url = "#{@host}#{@pathname}#{@query}"
64
+ end
65
+
66
+ def unmasked_pathname_without_trailing_slash
67
+ @unmasked_pathname.chomp('/')
67
68
  end
68
69
 
69
70
  # Get the language code of the current request
@@ -95,27 +96,7 @@ module Wovnrb
95
96
  @path_lang
96
97
  end
97
98
 
98
- def browser_lang
99
- if @browser_lang.nil?
100
- match = (@env['HTTP_COOKIE'] || '').match(/wovn_selected_lang\s*=\s*(?<lang>[^;\s]+)/)
101
- if match && match[:lang] && Lang.get_lang(match[:lang])
102
- @browser_lang = match[:lang]
103
- else
104
- # IS THIS RIGHT?
105
- @browser_lang = ''
106
- accept_langs = (@env['HTTP_ACCEPT_LANGUAGE'] || '').split(/[,;]/)
107
- accept_langs.each do |l|
108
- if Lang.get_lang(l)
109
- @browser_lang = l
110
- break
111
- end
112
- end
113
- end
114
- end
115
- @browser_lang
116
- end
117
-
118
- def redirect(lang = browser_lang)
99
+ def redirect(lang)
119
100
  redirect_headers = {}
120
101
  redirect_headers['location'] = redirect_location(lang)
121
102
  redirect_headers['content-length'] = '0'
@@ -150,6 +131,7 @@ module Wovnrb
150
131
  end
151
132
 
152
133
  def request_out(_def_lang = @settings['default_lang'])
134
+ @env['wovnrb.target_lang'] = lang_code
153
135
  case @settings['url_pattern']
154
136
  when 'query'
155
137
  @env['REQUEST_URI'] = remove_lang(@env['REQUEST_URI']) if @env.key?('REQUEST_URI')
@@ -189,13 +171,13 @@ module Wovnrb
189
171
  case @settings['url_pattern']
190
172
  when 'query'
191
173
  lang_param_name = @settings['lang_param_name']
192
- return uri.sub(/(^|\?|&)#{lang_param_name}=#{lang_code}(&|$)/, '\1').gsub(/(\?|&)$/, '')
174
+ uri.sub(/(^|\?|&)#{lang_param_name}=#{lang_code}(&|$)/, '\1').gsub(/(\?|&)$/, '')
193
175
  when 'subdomain'
194
176
  rp = Regexp.new('(^|(//))' + lang_code + '\.', 'i')
195
- return uri.sub(rp, '\1')
177
+ uri.sub(rp, '\1')
196
178
  # when 'path'
197
179
  else
198
- return uri.sub(/\/#{lang_code}(\/|$)/, '/')
180
+ uri.sub(/\/#{lang_code}(\/|$)/, '/')
199
181
  end
200
182
  end
201
183
 
@@ -203,19 +185,21 @@ module Wovnrb
203
185
  r = Regexp.new('//' + @host)
204
186
  lang_code = Store.instance.settings['custom_lang_aliases'][self.lang_code] || self.lang_code
205
187
  if lang_code != @settings['default_lang'] && headers.key?('Location') && headers['Location'] =~ r
206
- case @settings['url_pattern']
207
- when 'query'
208
- headers['Location'] += if headers['Location'] =~ /\?/
209
- '&'
210
- else
211
- '?'
212
- end
213
- headers['Location'] += "#{@settings['lang_param_name']}=#{lang_code}"
214
- when 'subdomain'
215
- headers['Location'] = headers['Location'].sub(/\/\/([^.]+)/, '//' + lang_code + '.\1')
216
- # when 'path'
217
- else
218
- headers['Location'] = headers['Location'].sub(/(\/\/[^\/]+)/, '\1/' + lang_code)
188
+ unless @settings['ignore_globs'].ignore?(headers['Location'])
189
+ case @settings['url_pattern']
190
+ when 'query'
191
+ headers['Location'] += if headers['Location'] =~ /\?/
192
+ '&'
193
+ else
194
+ '?'
195
+ end
196
+ headers['Location'] += "#{@settings['lang_param_name']}=#{lang_code}"
197
+ when 'subdomain'
198
+ headers['Location'] = headers['Location'].sub(/\/\/([^.]+)/, '//' + lang_code + '.\1')
199
+ # when 'path'
200
+ else
201
+ headers['Location'] = headers['Location'].sub(/(\/\/[^\/]+)/, '\1/' + lang_code)
202
+ end
219
203
  end
220
204
  end
221
205
  headers