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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +40 -1
  3. data/CHANGELOG.md +39 -0
  4. data/README.md +42 -2
  5. data/config/locales/i18n_proofreading.ar.yml +1 -1
  6. data/config/locales/i18n_proofreading.bg.yml +1 -1
  7. data/config/locales/i18n_proofreading.bn.yml +1 -1
  8. data/config/locales/i18n_proofreading.de.yml +1 -1
  9. data/config/locales/i18n_proofreading.el.yml +1 -1
  10. data/config/locales/i18n_proofreading.en.yml +1 -1
  11. data/config/locales/i18n_proofreading.es.yml +1 -1
  12. data/config/locales/i18n_proofreading.fr.yml +1 -1
  13. data/config/locales/i18n_proofreading.hi.yml +1 -1
  14. data/config/locales/i18n_proofreading.hr.yml +1 -1
  15. data/config/locales/i18n_proofreading.id.yml +1 -1
  16. data/config/locales/i18n_proofreading.it.yml +1 -1
  17. data/config/locales/i18n_proofreading.ja.yml +1 -1
  18. data/config/locales/i18n_proofreading.ko.yml +1 -1
  19. data/config/locales/i18n_proofreading.lb.yml +1 -1
  20. data/config/locales/i18n_proofreading.nl.yml +1 -1
  21. data/config/locales/i18n_proofreading.pl.yml +1 -1
  22. data/config/locales/i18n_proofreading.pt.yml +1 -1
  23. data/config/locales/i18n_proofreading.ro.yml +1 -1
  24. data/config/locales/i18n_proofreading.ru.yml +1 -1
  25. data/config/locales/i18n_proofreading.th.yml +1 -1
  26. data/config/locales/i18n_proofreading.tr.yml +1 -1
  27. data/config/locales/i18n_proofreading.uk.yml +1 -1
  28. data/config/locales/i18n_proofreading.ur.yml +1 -1
  29. data/config/locales/i18n_proofreading.vi.yml +1 -1
  30. data/config/locales/i18n_proofreading.zh-CN.yml +1 -1
  31. data/lib/generators/i18n_proofreading/install/install_generator.rb +1 -1
  32. data/lib/generators/i18n_proofreading/install/templates/initializer.rb +7 -1
  33. data/lib/i18n_proofreading/configuration.rb +5 -1
  34. data/lib/i18n_proofreading/controller_methods.rb +28 -0
  35. data/lib/i18n_proofreading/engine.rb +6 -0
  36. data/lib/i18n_proofreading/middleware.rb +4 -2
  37. data/lib/i18n_proofreading/tag_helper.rb +1 -1
  38. data/lib/i18n_proofreading/version.rb +1 -1
  39. data/lib/i18n_proofreading/widget.js +17 -13
  40. data/lib/i18n_proofreading/widget.rb +1 -1
  41. data/lib/i18n_proofreading.rb +1 -0
  42. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b064bdf9957104685057c004265c500cc66817f1e80ec826c8d384596570a864
4
- data.tar.gz: 7188a0820bee5027d18f65fc234bfc55bb96a96c4066755896759e1f75bb1680
3
+ metadata.gz: 3994f49e468a07ca647ff3d634542588ed656ce3c72474f20499acfdd7eded75
4
+ data.tar.gz: aa577d188f654f1f993248a6a17cdbc8fb16d5d407a9efe85f2f4a9be6c6511c
5
5
  SHA512:
6
- metadata.gz: 0f7c3fc2dee542a89d4a6f594d057fbbf6c02559a5bae2b04fd5cfa7a5a297bc76bb2c3bfc1705addf36bad1cd488208e76ccf17647c7613a266bd080b8a7843
7
- data.tar.gz: f9dda98042e0a0ffc27a41eceecb7c6c6693a3e7e53373dc4c7bddb6dcb1eb3116ed97c3dac587a5a4b9bb07956438a3b52731d2c0dc6a7a5dd3d5470b5fe673
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 **"Suggest edits"** pill bottom-left. Click it, then click any text; `Esc` exits.
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 **"Suggest edits"** pill in 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
- | `show_pill` | `true` | The floating "Suggest edits" pill. `:auto` shows it only on pages without a toggle link of your own |
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`.
@@ -1,6 +1,6 @@
1
1
  ar:
2
2
  i18n_proofreading:
3
- pill: "اقترح تعديلات"
3
+ pill: "تحسين الترجمة"
4
4
  start: "تحسين الترجمة"
5
5
  stop: "إيقاف الاقتراح (Esc)"
6
6
  pill_active: "إيقاف الاقتراح (Esc)"
@@ -1,6 +1,6 @@
1
1
  bg:
2
2
  i18n_proofreading:
3
- pill: "Предложи промени"
3
+ pill: "Подобряване на превода"
4
4
  pill_active: "Спиране на предложенията (Esc)"
5
5
  start: "Подобряване на превода"
6
6
  stop: "Спиране на предложенията (Esc)"
@@ -1,6 +1,6 @@
1
1
  bn:
2
2
  i18n_proofreading:
3
- pill: "সম্পাদনা প্রস্তাব করুন"
3
+ pill: "অনুবাদ উন্নত করুন"
4
4
  start: "অনুবাদ উন্নত করুন"
5
5
  stop: "প্রস্তাব দেওয়া বন্ধ করুন (Esc)"
6
6
  pill_active: "প্রস্তাব দেওয়া বন্ধ করুন (Esc)"
@@ -1,6 +1,6 @@
1
1
  de:
2
2
  i18n_proofreading:
3
- pill: "Änderungen vorschlagen"
3
+ pill: "Übersetzung verbessern"
4
4
  start: "Übersetzung verbessern"
5
5
  stop: "Vorschläge beenden (Esc)"
6
6
  pill_active: "Vorschläge beenden (Esc)"
@@ -1,6 +1,6 @@
1
1
  el:
2
2
  i18n_proofreading:
3
- pill: "Προτείνετε αλλαγές"
3
+ pill: "Βελτίωση μετάφρασης"
4
4
  pill_active: "Διακοπή προτάσεων (Esc)"
5
5
  start: "Βελτίωση μετάφρασης"
6
6
  stop: "Διακοπή προτάσεων (Esc)"
@@ -1,6 +1,6 @@
1
1
  en:
2
2
  i18n_proofreading:
3
- pill: "Suggest edits"
3
+ pill: "Improve translation"
4
4
  start: "Improve translation"
5
5
  stop: "Stop suggesting (Esc)"
6
6
  pill_active: "Stop suggesting (Esc)"
@@ -1,6 +1,6 @@
1
1
  es:
2
2
  i18n_proofreading:
3
- pill: "Sugerir cambios"
3
+ pill: "Mejorar traducción"
4
4
  start: "Mejorar traducción"
5
5
  stop: "Dejar de sugerir (Esc)"
6
6
  pill_active: "Dejar de sugerir (Esc)"
@@ -1,6 +1,6 @@
1
1
  fr:
2
2
  i18n_proofreading:
3
- pill: "Proposer des corrections"
3
+ pill: "Améliorer la traduction"
4
4
  start: "Améliorer la traduction"
5
5
  stop: "Arrêter de proposer (Esc)"
6
6
  pill_active: "Arrêter de proposer (Échap)"
@@ -1,6 +1,6 @@
1
1
  hi:
2
2
  i18n_proofreading:
3
- pill: "बदलाव सुझाएँ"
3
+ pill: "अनुवाद सुधारें"
4
4
  start: "अनुवाद सुधारें"
5
5
  stop: "सुझाव देना बंद करें (Esc)"
6
6
  pill_active: "सुझाव देना बंद करें (Esc)"
@@ -1,6 +1,6 @@
1
1
  hr:
2
2
  i18n_proofreading:
3
- pill: "Predloži izmjene"
3
+ pill: "Poboljšaj prijevod"
4
4
  pill_active: "Prestani predlagati (Esc)"
5
5
  start: "Poboljšaj prijevod"
6
6
  stop: "Prestani predlagati (Esc)"
@@ -1,6 +1,6 @@
1
1
  id:
2
2
  i18n_proofreading:
3
- pill: "Sarankan perubahan"
3
+ pill: "Perbaiki terjemahan"
4
4
  start: "Perbaiki terjemahan"
5
5
  stop: "Berhenti menyarankan (Esc)"
6
6
  pill_active: "Berhenti menyarankan (Esc)"
@@ -1,6 +1,6 @@
1
1
  it:
2
2
  i18n_proofreading:
3
- pill: "Suggerisci modifiche"
3
+ pill: "Migliora la traduzione"
4
4
  start: "Migliora la traduzione"
5
5
  stop: "Interrompi i suggerimenti (Esc)"
6
6
  pill_active: "Interrompi i suggerimenti (Esc)"
@@ -1,6 +1,6 @@
1
1
  ja:
2
2
  i18n_proofreading:
3
- pill: "修正を提案"
3
+ pill: "翻訳を改善"
4
4
  start: "翻訳を改善"
5
5
  stop: "提案を終了 (Esc)"
6
6
  pill_active: "提案を終了(Esc)"
@@ -1,6 +1,6 @@
1
1
  ko:
2
2
  i18n_proofreading:
3
- pill: "수정 제안"
3
+ pill: "번역 개선"
4
4
  start: "번역 개선"
5
5
  stop: "제안 중지 (Esc)"
6
6
  pill_active: "제안 중지 (Esc)"
@@ -1,6 +1,6 @@
1
1
  lb:
2
2
  i18n_proofreading:
3
- pill: "Ännerunge virschloen"
3
+ pill: "Iwwersetzung verbesseren"
4
4
  pill_active: "Virschléi stoppen (Esc)"
5
5
  start: "Iwwersetzung verbesseren"
6
6
  stop: "Virschléi stoppen (Esc)"
@@ -1,6 +1,6 @@
1
1
  nl:
2
2
  i18n_proofreading:
3
- pill: "Wijzigingen voorstellen"
3
+ pill: "Vertaling verbeteren"
4
4
  start: "Vertaling verbeteren"
5
5
  stop: "Stoppen met voorstellen (Esc)"
6
6
  pill_active: "Stoppen met voorstellen (Esc)"
@@ -1,6 +1,6 @@
1
1
  pl:
2
2
  i18n_proofreading:
3
- pill: "Zaproponuj zmiany"
3
+ pill: "Popraw tłumaczenie"
4
4
  start: "Popraw tłumaczenie"
5
5
  stop: "Zakończ sugerowanie (Esc)"
6
6
  pill_active: "Zakończ sugerowanie (Esc)"
@@ -1,6 +1,6 @@
1
1
  pt:
2
2
  i18n_proofreading:
3
- pill: "Sugerir edições"
3
+ pill: "Melhorar tradução"
4
4
  start: "Melhorar tradução"
5
5
  stop: "Parar de sugerir (Esc)"
6
6
  pill_active: "Parar de sugerir (Esc)"
@@ -1,6 +1,6 @@
1
1
  ro:
2
2
  i18n_proofreading:
3
- pill: "Sugerează modificări"
3
+ pill: "Îmbunătățește traducerea"
4
4
  pill_active: "Oprește sugestiile (Esc)"
5
5
  start: "Îmbunătățește traducerea"
6
6
  stop: "Oprește sugestiile (Esc)"
@@ -1,6 +1,6 @@
1
1
  ru:
2
2
  i18n_proofreading:
3
- pill: "Предложить правки"
3
+ pill: "Улучшить перевод"
4
4
  start: "Улучшить перевод"
5
5
  stop: "Остановить предложения (Esc)"
6
6
  pill_active: "Остановить предложения (Esc)"
@@ -1,6 +1,6 @@
1
1
  th:
2
2
  i18n_proofreading:
3
- pill: "แนะนำการแก้ไข"
3
+ pill: "ปรับปรุงคำแปล"
4
4
  start: "ปรับปรุงคำแปล"
5
5
  stop: "หยุดแนะนำ (Esc)"
6
6
  pill_active: "หยุดแนะนำ (Esc)"
@@ -1,6 +1,6 @@
1
1
  tr:
2
2
  i18n_proofreading:
3
- pill: "Düzenleme öner"
3
+ pill: "Çeviriyi iyileştir"
4
4
  start: "Çeviriyi iyileştir"
5
5
  stop: "Önermeyi durdur (Esc)"
6
6
  pill_active: "Önermeyi durdur (Esc)"
@@ -1,6 +1,6 @@
1
1
  uk:
2
2
  i18n_proofreading:
3
- pill: "Запропонувати зміни"
3
+ pill: "Покращити переклад"
4
4
  start: "Покращити переклад"
5
5
  stop: "Зупинити пропозиції (Esc)"
6
6
  pill_active: "Зупинити пропозиції (Esc)"
@@ -1,6 +1,6 @@
1
1
  ur:
2
2
  i18n_proofreading:
3
- pill: "ترامیم تجویز کریں"
3
+ pill: "ترجمہ بہتر بنائیں"
4
4
  start: "ترجمہ بہتر بنائیں"
5
5
  stop: "تجویز کرنا بند کریں (Esc)"
6
6
  pill_active: "تجویز کرنا بند کریں (Esc)"
@@ -1,6 +1,6 @@
1
1
  vi:
2
2
  i18n_proofreading:
3
- pill: "Đề xuất chỉnh sửa"
3
+ pill: "Cải thiện bản dịch"
4
4
  start: "Cải thiện bản dịch"
5
5
  stop: "Dừng đề xuất (Esc)"
6
6
  pill_active: "Dừng đề xuất (Esc)"
@@ -1,6 +1,6 @@
1
1
  zh-CN:
2
2
  i18n_proofreading:
3
- pill: "建议修改"
3
+ pill: "改进翻译"
4
4
  start: "改进翻译"
5
5
  stop: "停止建议 (Esc)"
6
6
  pill_active: "停止建议(Esc)"
@@ -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 “Suggest edits” pill in the bottom-left corner.\n"
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
- # Show the floating "Suggest edits" pill. Set false to hide it and toggle
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
- # ("Suggest edits", translated via the `i18n_proofreading.pill` I18n key).
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
- Marking.enabled = marking
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 && I18nProofreading.config.auto_inject && html?(headers) && !request.xhr?
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,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nProofreading
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -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 sets or
9
- * clears the i18n_proofreading cookie and reloads, so the backend only prints the
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
- var COOKIE = "i18n_proofreading";
37
- // A host's own on/off link ("?i18n_proofreading=true"). The parameter name
38
- // is server configuration, the same on every page.
39
- var TOGGLE_LINK = 'a[href*="' + (config.toggleParam || "i18n_proofreading") + '="]';
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
- if (config.active) {
143
- document.cookie = COOKIE + "=; path=/; max-age=0";
144
- } else {
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", "Suggest edits");
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, 'Suggest edits'),
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'),
@@ -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.2.0
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