i18n_proofreading 1.1.1 → 1.2.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +4 -4
  3. data/CHANGELOG.md +55 -1
  4. data/README.md +14 -5
  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 +3 -2
  33. data/lib/i18n_proofreading/configuration.rb +4 -2
  34. data/lib/i18n_proofreading/marking.rb +8 -0
  35. data/lib/i18n_proofreading/version.rb +1 -1
  36. data/lib/i18n_proofreading/widget.js +38 -18
  37. data/lib/i18n_proofreading/widget.rb +11 -2
  38. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a73bed80d485e35617f3ea214165c0ffcfc296721ac896f09d389cbf3a1b6e8
4
- data.tar.gz: 4cc2e32bf3420c01ea3af58c33582ffaa37c9fd26cf6e7425db1b554c4652c84
3
+ metadata.gz: 44c336fff23d26e91d584879766e3f0bce2cf6d9d73af485fdae275452f7682c
4
+ data.tar.gz: 92a38f638af73db3ce29ee5b822aafbb7bc8cc6fd925f2393c34ad542bab94f6
5
5
  SHA512:
6
- metadata.gz: 1c884b9b47f7e5712ab618fc663f5160ed7d7eabd571b295818efe445f11111f2bbb81e7110336594c7885d79c032479241623a33bb81d170309165ccb522f40
7
- data.tar.gz: 7c939c1e63d708c6772dcd4e703816967942b1ca2400a05027cbd8fa200ec1c446de390daf2bca70cf5313eccaa4615dc132464ffbe395a3a8cfb19d84ba04f0
6
+ metadata.gz: b47ef1083e05980617e51f1a5bfec96e065969f53d0e92ba29b3f4e962ac310e560683f37a263be1a032e1853bd28d16883acdc5fb4b0cb1e7962f15272c1abf
7
+ data.tar.gz: 592a870c92d94cf50a885d5494d6fc78a3bb217dc877f36b1a89fa469a9eef6695872aca405f86b686f57adf38f248497256756e5869d7a2e1d61b7dbba51a55
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
 
@@ -83,7 +83,7 @@ The pill is one way; a link is another, and the choice is remembered in a cookie
83
83
  ?i18n_proofreading=false # off
84
84
  ```
85
85
 
86
- `config.show_pill = false` hides the pill, `config.pill_label` overrides its text (nil = the localized `i18n_proofreading.pill` key), and `config.toggle_param` renames the parameter.
86
+ `config.show_pill = false` hides the pill, `config.show_pill = :auto` hides it only on pages that carry a toggle link (use it when the menu holding your link is not on every layout), `config.pill_label` overrides its text (nil = the localized `i18n_proofreading.pill` key), and `config.toggle_param` renames the parameter.
87
87
 
88
88
  ### Do not
89
89
 
@@ -108,7 +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
- | `show_pill`, `pill_label` | `true`, localized | Hide the pill and use `?i18n_proofreading=true` instead |
111
+ | `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
112
  | `toggle_param` | `"i18n_proofreading"` | Rename the query parameter |
113
113
  | `rate_limit` | `{ to: 30, within: 60 }` | Rails 7.2+; ignored on 7.1. `nil` disables |
114
114
  | `mount_path` | `"/i18n_proofreading"` | Keep in sync with the `mount` line |
@@ -121,7 +121,7 @@ The tool's own UI ships in 26 languages, RTL mirrored, and follows system light/
121
121
  | Symptom | Cause |
122
122
  | --- | --- |
123
123
  | `NameError` for one of your own helpers in the dashboard | `isolate_namespace` scopes `helper` to the engine. Use `config.base_controller_class` so the dashboard inherits your helpers, rather than `admin_layout` alone. |
124
- | No pill, no outlines | The environment is not in `enabled_environments` (this is the usual one), or `config.enabled` returned false, or `show_pill = false` |
124
+ | No pill, no outlines | The environment is not in `enabled_environments` (this is the usual one), or `config.enabled` returned false, or `show_pill = false` (or `:auto` on a page with a toggle link) |
125
125
  | Pill appears but no strings are outlined | The I18n backend patch is only prepended in an enabled environment at boot — check you are actually in development/staging, and restart after changing the setting |
126
126
  | `/i18n_proofreading` returns a 403 | `authorize_admin` still at its development-only default |
127
127
  | Suggestions rejected with an invalid-token error | The layout is missing `csrf_meta_tags` |
data/CHANGELOG.md CHANGED
@@ -2,7 +2,61 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [1.1.1] - 2026-10-30
5
+ ## [1.2.1] - 2026-10-30
6
+
7
+ ### Fixed
8
+
9
+ - **Esc and the pill now leave suggest mode on apps that harden their
10
+ cookies.** The widget used to switch the mode by writing the
11
+ `i18n_proofreading` cookie from JavaScript and reloading. An app that adds
12
+ `HttpOnly` to every cookie (SecureHeaders does in production) makes that
13
+ cookie unwritable from a script, so the delete was silently dropped and the
14
+ page reloaded still in suggest mode. The widget now visits the page with the
15
+ toggle parameter, the same server-side switch a host link uses.
16
+ - Costs: turning the mode on or off is now a redirect (one extra request)
17
+ instead of a reload. A page reached by a form POST is left with a GET to the
18
+ same URL, where a reload used to re-submit the form.
19
+
20
+ ### Changed
21
+
22
+ - **The pill reads "Improve translation"** (the `start` label, already
23
+ translated in every bundled language) instead of "Suggest edits", which did
24
+ not say what the tool is for. A host that overrides
25
+ `i18n_proofreading.pill` in its own locale files, or sets `pill_label`,
26
+ keeps its own text.
27
+
28
+ ## [1.2.0] - 2026-10-30
29
+
30
+ ### Fixed
31
+
32
+ - **Suggest mode no longer renders elements a page does not have.** A blank
33
+ translation (an empty value, or a `default: ""` for a missing key) used to get
34
+ a marker, which made it present: a view gating markup on `t(...).presence`
35
+ rendered it in suggest mode only. Bullet Train resolves every form field's
36
+ help and placeholder that way, so each field grew an empty help paragraph.
37
+ Blank results are now left unmarked.
38
+ - **No more stray `⟦⟧` on the page.** Rails' `t` helper resolves a String
39
+ `default:` for a missing key with `I18n.translate(nil, ...)`; the backend
40
+ marked that keyless result with an empty `⟦⟧`, which the widget could not
41
+ strip, so it showed beside the text and in placeholders. Keyless fallbacks
42
+ are now left unmarked, and the widget strips any empty marker that still
43
+ reaches the page.
44
+ - **Hovering a host toggle link no longer toggles suggest mode.** The link is a
45
+ GET that flips the mode, and Turbo 8 prefetches a link when the pointer rests
46
+ on it, so a hover alone turned suggest mode on or off. The widget now cancels
47
+ Turbo's prefetch (`turbo:before-prefetch`) for any link carrying the toggle
48
+ parameter. Other prefetchers (Speculation Rules) are not covered.
49
+ - Costs: a `default:` fallback for a missing key is no longer clickable in
50
+ suggest mode. It had no key to attribute a suggestion to, so it could not be
51
+ submitted usefully anyway. Blank strings are no longer clickable either; they
52
+ rendered nothing to click.
53
+
54
+ ### Added
55
+
56
+ - **`config.show_pill = :auto`** shows the pill only on pages without a toggle
57
+ link of the host's own, decided by the widget on every render. For a host
58
+ whose menu item is not on every layout: pages with the menu get only the menu
59
+ item, the rest keep the pill. The default stays `true`.
6
60
 
7
61
  ### Fixed
8
62
 
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.
@@ -87,7 +87,9 @@ works from any app that bundles it.
87
87
 
88
88
  1. In an enabled environment, the I18n backend appends a hidden `⟦some.key⟧`
89
89
  marker to each translated string — only while a reviewer has the tool on
90
- (a cookie), so pages are clean by default.
90
+ (a cookie), so pages are clean by default. Blank strings and Rails'
91
+ keyless `default:` fallbacks stay unmarked, so a view's `t(...).presence`
92
+ check behaves the same in suggest mode.
91
93
  2. The widget strips every marker out of the DOM on load and remembers which
92
94
  key produced each piece of text.
93
95
  3. Clicking a string opens a popover: current text, pending suggestions, and a
@@ -110,7 +112,7 @@ Everything is optional — the defaults work out of the box in development. In
110
112
  | `author_label` | the user's `email` | Label shown for the author |
111
113
  | `available_locales` | `I18n.available_locales` | Which locales a suggestion may target |
112
114
  | `auto_inject` | `true` | Inject the widget into HTML responses |
113
- | `show_pill` | `true` | The floating "Suggest edits" pill |
115
+ | `show_pill` | `true` | The floating "Improve translation" pill. `:auto` shows it only on pages without a toggle link of your own |
114
116
  | `pill_label` | `nil` | Fixed pill text. `nil` uses the localized default |
115
117
  | `toggle_param` | `"i18n_proofreading"` | Query param that toggles suggest mode |
116
118
  | `mount_path` | `"/i18n_proofreading"` | Keep in sync with `mount` in `routes.rb` |
@@ -145,7 +147,9 @@ config.on_submit = ->(s) { SuggestionMailer.with(suggestion: s).created.deliver_
145
147
 
146
148
  Prefer a menu item over the floating pill? Drive suggest mode from any link —
147
149
  and optionally hide the pill with `config.show_pill = false` (the two can also
148
- coexist).
150
+ coexist). If the menu is not on every page, `config.show_pill = :auto` hides
151
+ the pill only where the page has a toggle link, so a layout without your menu
152
+ keeps the pill.
149
153
 
150
154
  A one-way "turn it on" link is just the toggle parameter:
151
155
 
@@ -165,7 +169,7 @@ language:
165
169
  <% end %>
166
170
  ```
167
171
 
168
- Three things worth knowing:
172
+ Four things worth knowing:
169
173
 
170
174
  - `?i18n_proofreading=true` turns it on, `false` off. State lives in the
171
175
  `i18n_proofreading` cookie; the middleware then redirects to the same URL
@@ -173,6 +177,11 @@ Three things worth knowing:
173
177
  - These links keep working **while suggest mode is active**. The widget freezes
174
178
  ordinary navigation during proofreading so a stray click can't leave the page
175
179
  mid-edit — but any link carrying the toggle parameter is exempt.
180
+ - **A hover never toggles.** The link is a GET that flips the mode, and Turbo 8
181
+ prefetches a link when the pointer rests on it; the widget cancels Turbo's
182
+ prefetch for any link carrying the toggle parameter. If the app also uses
183
+ another prefetcher (Speculation Rules, `rel="prefetch"`), exclude these links
184
+ there.
176
185
  - The `i18n_proofreading.*` scope is **exempt from key-marking**, so the tool
177
186
  never flags its own controls as editable. No plain-literal workaround needed.
178
187
 
@@ -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,10 +52,11 @@ 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
+ # Show the floating "Improve translation" pill. Set false to hide it and toggle
56
56
  # suggest mode from your own link instead, e.g.
57
57
  # `<%= link_to "Proofread", "?i18n_proofreading=true" %>`. "?i18n_proofreading=false"
58
- # exits; the choice is remembered in a cookie.
58
+ # exits; the choice is remembered in a cookie. Set :auto to hide the pill only
59
+ # on pages that carry such a link (a menu that is not on every layout).
59
60
  #
60
61
  # config.show_pill = true
61
62
  # config.toggle_param = "i18n_proofreading"
@@ -67,11 +67,13 @@ module I18nProofreading
67
67
  attr_accessor :mount_path
68
68
 
69
69
  # Show the floating toggle pill. Set false to hide it and drive suggest mode
70
- # from your own link instead (see #toggle_param).
70
+ # from your own link instead (see #toggle_param). Set :auto to hide it only
71
+ # on pages that carry such a link, for a host whose menu is not on every
72
+ # layout; the widget decides on each render.
71
73
  attr_accessor :show_pill
72
74
 
73
75
  # Text on the floating toggle pill. Leave nil to use the localized default
74
- # ("Suggest edits", translated via the `i18n_proofreading.pill` I18n key).
76
+ # ("Improve translation", translated via the `i18n_proofreading.pill` I18n key).
75
77
  attr_accessor :pill_label
76
78
 
77
79
  # The query-string parameter that turns suggest mode on/off, so a host can
@@ -32,6 +32,14 @@ module I18nProofreading
32
32
  def translate(locale, key, options = {})
33
33
  result = super
34
34
  return result unless Marking.enabled? && result.is_a?(String)
35
+ # Blank text has nothing to click, and a marker would make it present:
36
+ # hosts gate markup on `t(...).presence` (Bullet Train renders every form
37
+ # field's help and placeholder that way), so suggest mode would render
38
+ # elements the page does not have.
39
+ return result if result.blank?
40
+ # Rails' `t` helper resolves a String `default:` for a missing key with
41
+ # `I18n.translate(nil, default: ...)`: no key to attribute a suggestion to.
42
+ return result if key.to_s.empty?
35
43
 
36
44
  full = [*options[:scope], key].join('.')
37
45
  return result if full.match?(SKIP)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nProofreading
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.1'
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
@@ -29,8 +30,15 @@
29
30
  var LEFT = "⟦"; // ⟦
30
31
  var RIGHT = "⟧"; // ⟧
31
32
  var TOKEN = new RegExp(LEFT + "([^" + RIGHT + "]+)" + RIGHT);
32
- var TOKENS = new RegExp("\\s*" + LEFT + "[^" + RIGHT + "]+" + RIGHT, "g");
33
- var COOKIE = "i18n_proofreading";
33
+ // Stripping also takes an empty "⟦⟧": it names no key to attribute, but it
34
+ // must never reach the screen either.
35
+ var ANY_TOKEN = new RegExp(LEFT + "[^" + RIGHT + "]*" + RIGHT);
36
+ var TOKENS = new RegExp("\\s*" + LEFT + "[^" + RIGHT + "]*" + RIGHT, "g");
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 + '="]';
34
42
  var MARKED_ATTRS = ["placeholder", "title", "aria-label", "value"];
35
43
  var Z = 2147483000;
36
44
 
@@ -59,6 +67,11 @@
59
67
  // toggling suggest mode across a Turbo visit needs no re-registration.
60
68
  document.addEventListener("keydown", handleKeydown);
61
69
  document.addEventListener("click", handleClick, true);
70
+ // A toggle link is a GET that flips suggest mode, and Turbo 8 prefetches a
71
+ // link once the pointer rests on it: without this, a hover toggles the mode.
72
+ document.addEventListener("turbo:before-prefetch", function (event) {
73
+ if (event.target.closest && event.target.closest(TOGGLE_LINK)) event.preventDefault();
74
+ });
62
75
 
63
76
  // Everything else lives in <body>, which Turbo replaces on every visit —
64
77
  // taking the pill and the active-mode highlighting with it. Re-run the
@@ -114,19 +127,28 @@
114
127
  if (config === UNAVAILABLE) return;
115
128
 
116
129
  injectStyles();
117
- if (config.showPill !== false) buildPill();
130
+ if (showPill()) buildPill();
118
131
  if (config.active) strip();
119
132
  }
120
133
 
134
+ // "auto" leaves the pill to pages without a host toggle link: where the host
135
+ // offers its own on/off control, a second one would only cover the page.
136
+ function showPill() {
137
+ if (config.showPill === "auto") return !document.querySelector(TOGGLE_LINK);
138
+ return config.showPill !== false;
139
+ }
140
+
121
141
  // --- suggest-mode toggle --------------------------------------------------
122
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.
123
148
  function toggle() {
124
- if (config.active) {
125
- document.cookie = COOKIE + "=; path=/; max-age=0";
126
- } else {
127
- document.cookie = COOKIE + "=1; path=/";
128
- }
129
- 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());
130
152
  }
131
153
 
132
154
  // --- marker stripping -----------------------------------------------------
@@ -141,7 +163,7 @@
141
163
  acceptNode: function (node) {
142
164
  var tag = node.parentElement && node.parentElement.tagName;
143
165
  if (tag === "SCRIPT" || tag === "STYLE") return NodeFilter.FILTER_REJECT;
144
- return TOKEN.test(node.nodeValue) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
166
+ return ANY_TOKEN.test(node.nodeValue) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
145
167
  },
146
168
  });
147
169
 
@@ -150,12 +172,10 @@
150
172
 
151
173
  nodes.forEach(function (node) {
152
174
  var match = node.nodeValue.match(TOKEN);
153
- if (!match) return;
154
- var key = match[1];
155
175
  node.nodeValue = node.nodeValue.replace(TOKENS, "");
156
176
  var element = node.parentElement;
157
- if (element) {
158
- element.dataset.i18nKey = key;
177
+ if (match && element) {
178
+ element.dataset.i18nKey = match[1];
159
179
  element.dataset.i18nValue = node.nodeValue.trim();
160
180
  }
161
181
  });
@@ -177,7 +197,7 @@
177
197
  // Let a host's own suggest-mode toggle link through (e.g. "?i18n_proofreading=false"
178
198
  // in a nav menu); otherwise navigation-freezing would trap the user in suggest
179
199
  // mode with no way out but the pill.
180
- if (event.target.closest && event.target.closest('a[href*="' + config.toggleParam + '="]')) return;
200
+ if (event.target.closest && event.target.closest(TOGGLE_LINK)) return;
181
201
 
182
202
  // Freeze navigation so a stray click can't leave the page mid-proofread.
183
203
  event.preventDefault();
@@ -230,7 +250,7 @@
230
250
  }
231
251
 
232
252
  function labelText() {
233
- return config.pillLabel || t("pill", "Suggest edits");
253
+ return config.pillLabel || t("pill", "Improve translation");
234
254
  }
235
255
 
236
256
  // Resolve a server-translated label, falling back to English if the config
@@ -62,7 +62,7 @@ module I18nProofreading
62
62
  endpoint: endpoint,
63
63
  locale: locale.to_s,
64
64
  active: active ? true : false,
65
- showPill: I18nProofreading.config.show_pill ? true : false,
65
+ showPill: show_pill,
66
66
  pillLabel: I18nProofreading.config.pill_label,
67
67
  toggleParam: I18nProofreading.config.toggle_param,
68
68
  labels: labels(locale),
@@ -88,6 +88,15 @@ module I18nProofreading
88
88
 
89
89
  private
90
90
 
91
+ # true, false, or "auto": the widget then shows the pill only on a page
92
+ # without a host toggle link, decided in the browser on every render.
93
+ def show_pill
94
+ setting = I18nProofreading.config.show_pill
95
+ return 'auto' if setting.to_s == 'auto'
96
+
97
+ setting ? true : false
98
+ end
99
+
91
100
  # Every user-facing string in the widget, resolved through Rails I18n so the
92
101
  # popover matches the locale the page was rendered in. The locale is passed
93
102
  # explicitly (not read from I18n.locale) because auto-injection runs in
@@ -97,7 +106,7 @@ module I18nProofreading
97
106
  # stays fully worded even for a locale the gem ships no translation for.
98
107
  def labels(locale)
99
108
  {
100
- pill: t(locale, :pill, 'Suggest edits'),
109
+ pill: t(locale, :pill, 'Improve translation'),
101
110
  pillActive: t(locale, :pill_active, 'Stop suggesting (Esc)'),
102
111
  title: t(locale, :title, 'Suggest a translation fix'),
103
112
  currentText: t(locale, :current_text, 'Current text'),
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.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shmarov