i18n_proofreading 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENTS.md +40 -1
- data/CHANGELOG.md +39 -0
- data/README.md +42 -2
- data/config/locales/i18n_proofreading.ar.yml +1 -1
- data/config/locales/i18n_proofreading.bg.yml +1 -1
- data/config/locales/i18n_proofreading.bn.yml +1 -1
- data/config/locales/i18n_proofreading.de.yml +1 -1
- data/config/locales/i18n_proofreading.el.yml +1 -1
- data/config/locales/i18n_proofreading.en.yml +1 -1
- data/config/locales/i18n_proofreading.es.yml +1 -1
- data/config/locales/i18n_proofreading.fr.yml +1 -1
- data/config/locales/i18n_proofreading.hi.yml +1 -1
- data/config/locales/i18n_proofreading.hr.yml +1 -1
- data/config/locales/i18n_proofreading.id.yml +1 -1
- data/config/locales/i18n_proofreading.it.yml +1 -1
- data/config/locales/i18n_proofreading.ja.yml +1 -1
- data/config/locales/i18n_proofreading.ko.yml +1 -1
- data/config/locales/i18n_proofreading.lb.yml +1 -1
- data/config/locales/i18n_proofreading.nl.yml +1 -1
- data/config/locales/i18n_proofreading.pl.yml +1 -1
- data/config/locales/i18n_proofreading.pt.yml +1 -1
- data/config/locales/i18n_proofreading.ro.yml +1 -1
- data/config/locales/i18n_proofreading.ru.yml +1 -1
- data/config/locales/i18n_proofreading.th.yml +1 -1
- data/config/locales/i18n_proofreading.tr.yml +1 -1
- data/config/locales/i18n_proofreading.uk.yml +1 -1
- data/config/locales/i18n_proofreading.ur.yml +1 -1
- data/config/locales/i18n_proofreading.vi.yml +1 -1
- data/config/locales/i18n_proofreading.zh-CN.yml +1 -1
- data/lib/generators/i18n_proofreading/install/install_generator.rb +1 -1
- data/lib/generators/i18n_proofreading/install/templates/initializer.rb +7 -1
- data/lib/i18n_proofreading/configuration.rb +5 -1
- data/lib/i18n_proofreading/controller_methods.rb +28 -0
- data/lib/i18n_proofreading/engine.rb +6 -0
- data/lib/i18n_proofreading/middleware.rb +4 -2
- data/lib/i18n_proofreading/tag_helper.rb +1 -1
- data/lib/i18n_proofreading/version.rb +1 -1
- data/lib/i18n_proofreading/widget.js +17 -13
- data/lib/i18n_proofreading/widget.rb +1 -1
- data/lib/i18n_proofreading.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3994f49e468a07ca647ff3d634542588ed656ce3c72474f20499acfdd7eded75
|
|
4
|
+
data.tar.gz: aa577d188f654f1f993248a6a17cdbc8fb16d5d407a9efe85f2f4a9be6c6511c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b7a039096395cf1de29d81ac2659f23467f54f805ba3e7f131ab17dd6e7824f2250573444e9a4a883e1a5ffa0be986c5a1b267d8636af594b63fc45013b120b
|
|
7
|
+
data.tar.gz: f98757d6e91232498d3f589cba1799d88638d7e138d7a9bcd13ab976ee5be5cd55d6fd876c603b1ae19f288bb0f516f61f5a0de6681d6f8ba5289c748d5752fb
|
data/AGENTS.md
CHANGED
|
@@ -27,7 +27,7 @@ The generator writes `config/initializers/i18n_proofreading.rb`, one migration (
|
|
|
27
27
|
|
|
28
28
|
### 2. There is no step 2 — do not edit the layout
|
|
29
29
|
|
|
30
|
-
The widget injects itself into HTML responses through a Rack middleware, so **no layout change is needed**. Boot the app in development and look for the **"
|
|
30
|
+
The widget injects itself into HTML responses through a Rack middleware, so **no layout change is needed**. Boot the app in development and look for the **"Improve translation"** pill bottom-left. Click it, then click any text; `Esc` exits.
|
|
31
31
|
|
|
32
32
|
Only if the host prefers to place it explicitly:
|
|
33
33
|
|
|
@@ -108,6 +108,7 @@ Everything is optional; a fresh install works with zero config in development. F
|
|
|
108
108
|
| `author_label` | email, else `to_s` | Receives the user |
|
|
109
109
|
| `available_locales` | `I18n.available_locales` | Callable; validates what a suggestion may target |
|
|
110
110
|
| `auto_inject` | `true` | `false` = place `i18n_proofreading_tag` yourself |
|
|
111
|
+
| `controller_scoped` | `false` | Default pages to off until `enable_i18n_proofreading` runs before rendering |
|
|
111
112
|
| `show_pill`, `pill_label` | `true`, localized | Hide the pill and use `?i18n_proofreading=true` instead; `:auto` hides it only where the page has such a link |
|
|
112
113
|
| `toggle_param` | `"i18n_proofreading"` | Rename the query parameter |
|
|
113
114
|
| `rate_limit` | `{ to: 30, within: 60 }` | Rails 7.2+; ignored on 7.1. `nil` disables |
|
|
@@ -159,3 +160,41 @@ Conventions this codebase holds to — follow them rather than the first thing t
|
|
|
159
160
|
- **`lib/i18n_proofreading/dashboard.css` is half shared.** Everything above the `GEM-SPECIFIC` banner is the design system all five gems in the family ship — the same tokens, the same `.page-head`/`.tabs`/`.filters`/`.card`/`.badge`/`button`/`.status-switch`, the same `.dashboard-shell` + `.record-row` + `.detail-panel` two-pane dashboard — identical in every repo apart from the `ip` prefix. Diff it against a sibling before changing it, and carry the change to the other four. Anything only this gem has goes below the banner. New dashboard markup reuses the shared class names rather than inventing a domain-specific one.
|
|
160
161
|
- Every user-facing change bumps `lib/i18n_proofreading/version.rb` and adds a `CHANGELOG.md` entry (Keep a Changelog format) that says what it costs, not only what it adds.
|
|
161
162
|
- Commit messages are prose that explains the tradeoff — read `git log` before writing one.
|
|
163
|
+
|
|
164
|
+
## Selecting pages from controllers
|
|
165
|
+
|
|
166
|
+
`config.enabled` runs before routing. When page eligibility depends on the
|
|
167
|
+
controller, use a `before_action` **before any translations are rendered**:
|
|
168
|
+
|
|
169
|
+
```ruby
|
|
170
|
+
class PublicController < ApplicationController
|
|
171
|
+
before_action :disable_i18n_proofreading
|
|
172
|
+
end
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
This suppresses both markers and the widget, including an explicitly placed
|
|
176
|
+
`i18n_proofreading_tag`. It does not change that page's cache headers.
|
|
177
|
+
|
|
178
|
+
For an allowlist instead, set `config.controller_scoped = true` in the initializer.
|
|
179
|
+
Pages then start with no markers or widget until an eligible controller opts in:
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
class AccountController < ApplicationController
|
|
183
|
+
before_action :authenticate_user!
|
|
184
|
+
before_action :enable_i18n_proofreading
|
|
185
|
+
end
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
The environment and `config.enabled` user gates still apply. Authentication and
|
|
189
|
+
which controllers qualify belong to your app; Devise is not required. The
|
|
190
|
+
methods can also be called from your own conditional `before_action`.
|
|
191
|
+
|
|
192
|
+
Default `controller_scoped = false` preserves existing behavior. Page selection
|
|
193
|
+
is independent of suggestion endpoint authorization, the dashboard gate and the
|
|
194
|
+
toggle-cookie redirect. It is not an authorization mechanism. Do not call these
|
|
195
|
+
methods after rendering: disabling cannot remove markers already rendered.
|
|
196
|
+
|
|
197
|
+
This API does not isolate marking to view rendering, bypass fragment caches or
|
|
198
|
+
set CDN cache policy. Hosts must still keep marked fragments out of shared
|
|
199
|
+
caches and protect responses containing reviewer-specific widgets. Existing
|
|
200
|
+
render-scoping/cache safeguards should remain when replacing an injection patch.
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [1.3.0] - 2026-11-17
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Controller methods `disable_i18n_proofreading` and `enable_i18n_proofreading`
|
|
10
|
+
select pages before rendering, suppressing both key markers and automatic or
|
|
11
|
+
manually placed widgets without overriding middleware internals. The optional
|
|
12
|
+
`controller_scoped = true` setting defaults pages to off until opted in.
|
|
13
|
+
- Existing installs retain their behavior. Environment and user gates still
|
|
14
|
+
apply; suggestion endpoints, dashboard authorization and toggle redirects are
|
|
15
|
+
unchanged. No migration or new dependency.
|
|
16
|
+
- Costs: hosts must call these methods before rendering, and still own fragment
|
|
17
|
+
and response cache safeguards. This does not narrow marking to view rendering
|
|
18
|
+
or undo markers already emitted. Excluded pages keep their cache headers.
|
|
19
|
+
- Request and real Turbo browser tests cover page transitions and gate behavior.
|
|
20
|
+
|
|
21
|
+
## [1.2.1] - 2026-10-30
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **Esc and the pill now leave suggest mode on apps that harden their
|
|
26
|
+
cookies.** The widget used to switch the mode by writing the
|
|
27
|
+
`i18n_proofreading` cookie from JavaScript and reloading. An app that adds
|
|
28
|
+
`HttpOnly` to every cookie (SecureHeaders does in production) makes that
|
|
29
|
+
cookie unwritable from a script, so the delete was silently dropped and the
|
|
30
|
+
page reloaded still in suggest mode. The widget now visits the page with the
|
|
31
|
+
toggle parameter, the same server-side switch a host link uses.
|
|
32
|
+
- Costs: turning the mode on or off is now a redirect (one extra request)
|
|
33
|
+
instead of a reload. A page reached by a form POST is left with a GET to the
|
|
34
|
+
same URL, where a reload used to re-submit the form.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- **The pill reads "Improve translation"** (the `start` label, already
|
|
39
|
+
translated in every bundled language) instead of "Suggest edits", which did
|
|
40
|
+
not say what the tool is for. A host that overrides
|
|
41
|
+
`i18n_proofreading.pill` in its own locale files, or sets `pill_label`,
|
|
42
|
+
keeps its own text.
|
|
43
|
+
|
|
5
44
|
## [1.2.0] - 2026-10-30
|
|
6
45
|
|
|
7
46
|
### Fixed
|
data/README.md
CHANGED
|
@@ -36,7 +36,7 @@ It creates three idempotent sample suggestions across pending, applied, and
|
|
|
36
36
|
rejected states. Running the task again refreshes those records instead of
|
|
37
37
|
duplicating them.
|
|
38
38
|
|
|
39
|
-
Boot the app in development and look for the **"
|
|
39
|
+
Boot the app in development and look for the **"Improve translation"** pill in the
|
|
40
40
|
bottom-left. Click it, then click any text. `Esc` exits.
|
|
41
41
|
|
|
42
42
|
No layout change needed — the widget injects itself into HTML responses.
|
|
@@ -112,7 +112,8 @@ Everything is optional — the defaults work out of the box in development. In
|
|
|
112
112
|
| `author_label` | the user's `email` | Label shown for the author |
|
|
113
113
|
| `available_locales` | `I18n.available_locales` | Which locales a suggestion may target |
|
|
114
114
|
| `auto_inject` | `true` | Inject the widget into HTML responses |
|
|
115
|
-
| `
|
|
115
|
+
| `controller_scoped` | `false` | Default pages to off until `enable_i18n_proofreading` runs before rendering |
|
|
116
|
+
| `show_pill` | `true` | The floating "Improve translation" pill. `:auto` shows it only on pages without a toggle link of your own |
|
|
116
117
|
| `pill_label` | `nil` | Fixed pill text. `nil` uses the localized default |
|
|
117
118
|
| `toggle_param` | `"i18n_proofreading"` | Query param that toggles suggest mode |
|
|
118
119
|
| `mount_path` | `"/i18n_proofreading"` | Keep in sync with `mount` in `routes.rb` |
|
|
@@ -200,6 +201,44 @@ It renders nothing unless the tool is available for the request.
|
|
|
200
201
|
|
|
201
202
|
</details>
|
|
202
203
|
|
|
204
|
+
## Selecting pages from controllers
|
|
205
|
+
|
|
206
|
+
`config.enabled` runs before routing. When page eligibility depends on the
|
|
207
|
+
controller, use a `before_action` **before any translations are rendered**:
|
|
208
|
+
|
|
209
|
+
```ruby
|
|
210
|
+
class PublicController < ApplicationController
|
|
211
|
+
before_action :disable_i18n_proofreading
|
|
212
|
+
end
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
This suppresses both markers and the widget, including an explicitly placed
|
|
216
|
+
`i18n_proofreading_tag`. It does not change that page's cache headers.
|
|
217
|
+
|
|
218
|
+
For an allowlist instead, set `config.controller_scoped = true` in the initializer.
|
|
219
|
+
Pages then start with no markers or widget until an eligible controller opts in:
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
class AccountController < ApplicationController
|
|
223
|
+
before_action :authenticate_user!
|
|
224
|
+
before_action :enable_i18n_proofreading
|
|
225
|
+
end
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The environment and `config.enabled` user gates still apply. Authentication and
|
|
229
|
+
which controllers qualify belong to your app; Devise is not required. The
|
|
230
|
+
methods can also be called from your own conditional `before_action`.
|
|
231
|
+
|
|
232
|
+
Default `controller_scoped = false` preserves existing behavior. Page selection
|
|
233
|
+
is independent of suggestion endpoint authorization, the dashboard gate and the
|
|
234
|
+
toggle-cookie redirect. It is not an authorization mechanism. Do not call these
|
|
235
|
+
methods after rendering: disabling cannot remove markers already rendered.
|
|
236
|
+
|
|
237
|
+
This API does not isolate marking to view rendering, bypass fragment caches or
|
|
238
|
+
set CDN cache policy. Hosts must still keep marked fragments out of shared
|
|
239
|
+
caches and protect responses containing reviewer-specific widgets. Existing
|
|
240
|
+
render-scoping/cache safeguards should remain when replacing an injection patch.
|
|
241
|
+
|
|
203
242
|
## Reviewing suggestions
|
|
204
243
|
|
|
205
244
|
The engine root (default `/i18n_proofreading`) is a **read-only** board:
|
|
@@ -291,6 +330,7 @@ deprecation normally ships in a preceding minor release.
|
|
|
291
330
|
- `I18nProofreading.configure` and the configuration options listed above.
|
|
292
331
|
- `mount_i18n_proofreading at:` and the mounted dashboard root.
|
|
293
332
|
- `i18n_proofreading_tag` for hosts that disable automatic injection.
|
|
333
|
+
- `enable_i18n_proofreading` and `disable_i18n_proofreading` controller callbacks.
|
|
294
334
|
- The configured toggle parameter and its `true` / `false` behavior.
|
|
295
335
|
- `I18nProofreading::Suggestion` fields documented under Reviewing
|
|
296
336
|
suggestions, `STATUSES`, prefixed status helpers/scopes, and `newest_first`.
|
|
@@ -30,7 +30,7 @@ module I18nProofreading
|
|
|
30
30
|
def post_install
|
|
31
31
|
say "\ni18n_proofreading installed. Run `rails db:migrate`, then boot in development", :green
|
|
32
32
|
say 'Optional: run `bin/rails i18n_proofreading:seed_demo` for sample suggestions.'
|
|
33
|
-
say "and look for the “
|
|
33
|
+
say "and look for the “Improve translation” pill in the bottom-left corner.\n"
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
@@ -52,7 +52,13 @@ I18nProofreading.configure do |config|
|
|
|
52
52
|
#
|
|
53
53
|
# config.auto_inject = true
|
|
54
54
|
|
|
55
|
-
#
|
|
55
|
+
# Default pages to off until a before_action calls enable_i18n_proofreading.
|
|
56
|
+
# With the default false, disable_i18n_proofreading excludes individual pages.
|
|
57
|
+
# Call before rendering; both markers and automatic/manual widgets obey it.
|
|
58
|
+
# User/environment gates and suggestion endpoint authorization are unchanged.
|
|
59
|
+
# config.controller_scoped = false
|
|
60
|
+
|
|
61
|
+
# Show the floating "Improve translation" pill. Set false to hide it and toggle
|
|
56
62
|
# suggest mode from your own link instead, e.g.
|
|
57
63
|
# `<%= link_to "Proofread", "?i18n_proofreading=true" %>`. "?i18n_proofreading=false"
|
|
58
64
|
# exits; the choice is remembered in a cookie. Set :auto to hide the pill only
|
|
@@ -61,6 +61,9 @@ module I18nProofreading
|
|
|
61
61
|
# yourself with `<%= i18n_proofreading_tag %>` in your layout.
|
|
62
62
|
attr_accessor :auto_inject
|
|
63
63
|
|
|
64
|
+
# Default pages to off until a controller calls enable_i18n_proofreading.
|
|
65
|
+
attr_accessor :controller_scoped
|
|
66
|
+
|
|
64
67
|
# Where the engine is mounted. The widget posts suggestions to
|
|
65
68
|
# "#{mount_path}/suggestions", so keep this in sync with the `mount` line in
|
|
66
69
|
# your routes.
|
|
@@ -73,7 +76,7 @@ module I18nProofreading
|
|
|
73
76
|
attr_accessor :show_pill
|
|
74
77
|
|
|
75
78
|
# Text on the floating toggle pill. Leave nil to use the localized default
|
|
76
|
-
# ("
|
|
79
|
+
# ("Improve translation", translated via the `i18n_proofreading.pill` I18n key).
|
|
77
80
|
attr_accessor :pill_label
|
|
78
81
|
|
|
79
82
|
# The query-string parameter that turns suggest mode on/off, so a host can
|
|
@@ -101,6 +104,7 @@ module I18nProofreading
|
|
|
101
104
|
@author_label = ->(user) { user.respond_to?(:email) ? user.email : user&.to_s }
|
|
102
105
|
@available_locales = -> { I18n.available_locales.map(&:to_s) }
|
|
103
106
|
@auto_inject = true
|
|
107
|
+
@controller_scoped = false
|
|
104
108
|
@mount_path = '/i18n_proofreading'
|
|
105
109
|
@show_pill = true
|
|
106
110
|
@pill_label = nil
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module I18nProofreading
|
|
4
|
+
# Call from a before_action, before any translations are rendered. Page scope
|
|
5
|
+
# never grants access: the middleware's environment/user gate remains required.
|
|
6
|
+
module ControllerMethods
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def enable_i18n_proofreading
|
|
10
|
+
request.env[PageScope::ENABLED] = true
|
|
11
|
+
Marking.enabled = request.env[PageScope::MARKING] == true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def disable_i18n_proofreading
|
|
15
|
+
request.env[PageScope::ENABLED] = false
|
|
16
|
+
Marking.enabled = false
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module PageScope
|
|
21
|
+
ENABLED = 'i18n_proofreading.page_enabled'
|
|
22
|
+
MARKING = 'i18n_proofreading.marking_allowed'
|
|
23
|
+
|
|
24
|
+
def self.enabled?(request)
|
|
25
|
+
request.env.fetch(ENABLED) { !I18nProofreading.config.controller_scoped }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -32,6 +32,12 @@ module I18nProofreading
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
initializer 'i18n_proofreading.controller_methods' do
|
|
36
|
+
ActiveSupport.on_load(:action_controller_base) do
|
|
37
|
+
include I18nProofreading::ControllerMethods
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
35
41
|
initializer 'i18n_proofreading.helper' do
|
|
36
42
|
ActiveSupport.on_load(:action_view) do
|
|
37
43
|
include I18nProofreading::TagHelper
|
|
@@ -27,11 +27,13 @@ module I18nProofreading
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
marking = available && cookie_on?(request)
|
|
30
|
-
|
|
30
|
+
env[PageScope::MARKING] = marking
|
|
31
|
+
Marking.enabled = marking && PageScope.enabled?(request)
|
|
31
32
|
|
|
32
33
|
status, headers, body = @app.call(env)
|
|
33
34
|
|
|
34
|
-
if available &&
|
|
35
|
+
if available && PageScope.enabled?(request) && I18nProofreading.config.auto_inject &&
|
|
36
|
+
html?(headers) && !request.xhr?
|
|
35
37
|
status, headers, body = inject(status, headers, body, marking, csp_nonce(env))
|
|
36
38
|
end
|
|
37
39
|
|
|
@@ -8,7 +8,7 @@ module I18nProofreading
|
|
|
8
8
|
# autoloaders, when an app/helpers constant cannot be resolved yet.
|
|
9
9
|
module TagHelper
|
|
10
10
|
def i18n_proofreading_tag
|
|
11
|
-
return ''.html_safe unless I18nProofreading.available?(request)
|
|
11
|
+
return ''.html_safe unless I18nProofreading.available?(request) && PageScope.enabled?(request)
|
|
12
12
|
|
|
13
13
|
Widget.snippet(
|
|
14
14
|
endpoint: I18nProofreading.config.suggestions_endpoint,
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* data-i18n-proofreading-config> the server injects — re-read on every render so a
|
|
6
6
|
* Turbo visit always reflects the current page's suggest state.
|
|
7
7
|
*
|
|
8
|
-
* A floating pill toggles "suggest mode", which is server state: the pill
|
|
9
|
-
*
|
|
8
|
+
* A floating pill toggles "suggest mode", which is server state: the pill visits
|
|
9
|
+
* the page with the toggle parameter, the middleware sets or clears the
|
|
10
|
+
* i18n_proofreading cookie and redirects back, so the backend only prints the
|
|
10
11
|
* "…text… ⟦some.key.path⟧" markers while proofreading. The markers are never shown
|
|
11
12
|
* to the user — on load the widget strips each ⟦key⟧ token out of the DOM and
|
|
12
13
|
* stashes the key on its element. A click on any such element opens a popover to
|
|
@@ -33,10 +34,11 @@
|
|
|
33
34
|
// must never reach the screen either.
|
|
34
35
|
var ANY_TOKEN = new RegExp(LEFT + "[^" + RIGHT + "]*" + RIGHT);
|
|
35
36
|
var TOKENS = new RegExp("\\s*" + LEFT + "[^" + RIGHT + "]*" + RIGHT, "g");
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
var
|
|
37
|
+
// The query parameter that switches suggest mode ("?i18n_proofreading=true"),
|
|
38
|
+
// and a host's own on/off link carrying it. Server configuration, the same on
|
|
39
|
+
// every page.
|
|
40
|
+
var TOGGLE_PARAM = config.toggleParam || "i18n_proofreading";
|
|
41
|
+
var TOGGLE_LINK = 'a[href*="' + TOGGLE_PARAM + '="]';
|
|
40
42
|
var MARKED_ATTRS = ["placeholder", "title", "aria-label", "value"];
|
|
41
43
|
var Z = 2147483000;
|
|
42
44
|
|
|
@@ -138,13 +140,15 @@
|
|
|
138
140
|
|
|
139
141
|
// --- suggest-mode toggle --------------------------------------------------
|
|
140
142
|
|
|
143
|
+
// Hand the switch to the middleware, the same way a host link does, rather
|
|
144
|
+
// than writing the cookie here: a host that hardens every cookie (HttpOnly,
|
|
145
|
+
// as SecureHeaders does) makes it unwritable from JavaScript, so a script-side
|
|
146
|
+
// delete was silently dropped and the reload came back still in suggest mode.
|
|
147
|
+
// The middleware sets the cookie and redirects back without the parameter.
|
|
141
148
|
function toggle() {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
document.cookie = COOKIE + "=1; path=/";
|
|
146
|
-
}
|
|
147
|
-
window.location.reload();
|
|
149
|
+
var url = new URL(window.location.href);
|
|
150
|
+
url.searchParams.set(TOGGLE_PARAM, config.active ? "false" : "true");
|
|
151
|
+
window.location.assign(url.toString());
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
// --- marker stripping -----------------------------------------------------
|
|
@@ -246,7 +250,7 @@
|
|
|
246
250
|
}
|
|
247
251
|
|
|
248
252
|
function labelText() {
|
|
249
|
-
return config.pillLabel || t("pill", "
|
|
253
|
+
return config.pillLabel || t("pill", "Improve translation");
|
|
250
254
|
}
|
|
251
255
|
|
|
252
256
|
// Resolve a server-translated label, falling back to English if the config
|
|
@@ -106,7 +106,7 @@ module I18nProofreading
|
|
|
106
106
|
# stays fully worded even for a locale the gem ships no translation for.
|
|
107
107
|
def labels(locale)
|
|
108
108
|
{
|
|
109
|
-
pill: t(locale, :pill, '
|
|
109
|
+
pill: t(locale, :pill, 'Improve translation'),
|
|
110
110
|
pillActive: t(locale, :pill_active, 'Stop suggesting (Esc)'),
|
|
111
111
|
title: t(locale, :title, 'Suggest a translation fix'),
|
|
112
112
|
currentText: t(locale, :current_text, 'Current text'),
|
data/lib/i18n_proofreading.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'i18n_proofreading/configuration'
|
|
|
5
5
|
require 'i18n_proofreading/ractor_support'
|
|
6
6
|
require 'i18n_proofreading/marking'
|
|
7
7
|
require 'i18n_proofreading/widget'
|
|
8
|
+
require 'i18n_proofreading/controller_methods'
|
|
8
9
|
require 'i18n_proofreading/tag_helper'
|
|
9
10
|
require 'i18n_proofreading/middleware'
|
|
10
11
|
require 'i18n_proofreading/seeds'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: i18n_proofreading
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yaroslav Shmarov
|
|
@@ -103,6 +103,7 @@ files:
|
|
|
103
103
|
- lib/generators/i18n_proofreading/migration_helpers.rb
|
|
104
104
|
- lib/i18n_proofreading.rb
|
|
105
105
|
- lib/i18n_proofreading/configuration.rb
|
|
106
|
+
- lib/i18n_proofreading/controller_methods.rb
|
|
106
107
|
- lib/i18n_proofreading/dashboard.css
|
|
107
108
|
- lib/i18n_proofreading/engine.rb
|
|
108
109
|
- lib/i18n_proofreading/marking.rb
|