i18n_feedback 0.8.2 → 0.8.3

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -319
  3. data/lib/i18n_feedback.rb +12 -35
  4. metadata +14 -62
  5. data/CHANGELOG.md +0 -191
  6. data/MIT-LICENSE +0 -21
  7. data/Rakefile +0 -14
  8. data/app/controllers/i18n_feedback/application_controller.rb +0 -32
  9. data/app/controllers/i18n_feedback/suggestions_controller.rb +0 -92
  10. data/app/helpers/i18n_feedback/tag_helper.rb +0 -19
  11. data/app/models/i18n_feedback/application_record.rb +0 -7
  12. data/app/models/i18n_feedback/suggestion.rb +0 -27
  13. data/app/views/i18n_feedback/suggestions/index.html.erb +0 -77
  14. data/app/views/layouts/i18n_feedback/application.html.erb +0 -96
  15. data/config/locales/i18n_feedback.ar.yml +0 -16
  16. data/config/locales/i18n_feedback.bg.yml +0 -16
  17. data/config/locales/i18n_feedback.bn.yml +0 -16
  18. data/config/locales/i18n_feedback.de.yml +0 -16
  19. data/config/locales/i18n_feedback.el.yml +0 -16
  20. data/config/locales/i18n_feedback.en.yml +0 -35
  21. data/config/locales/i18n_feedback.es.yml +0 -16
  22. data/config/locales/i18n_feedback.fr.yml +0 -16
  23. data/config/locales/i18n_feedback.hi.yml +0 -16
  24. data/config/locales/i18n_feedback.hr.yml +0 -16
  25. data/config/locales/i18n_feedback.id.yml +0 -16
  26. data/config/locales/i18n_feedback.it.yml +0 -16
  27. data/config/locales/i18n_feedback.ja.yml +0 -16
  28. data/config/locales/i18n_feedback.ko.yml +0 -16
  29. data/config/locales/i18n_feedback.lb.yml +0 -16
  30. data/config/locales/i18n_feedback.nl.yml +0 -16
  31. data/config/locales/i18n_feedback.pl.yml +0 -16
  32. data/config/locales/i18n_feedback.pt.yml +0 -16
  33. data/config/locales/i18n_feedback.ro.yml +0 -16
  34. data/config/locales/i18n_feedback.ru.yml +0 -16
  35. data/config/locales/i18n_feedback.th.yml +0 -16
  36. data/config/locales/i18n_feedback.tr.yml +0 -16
  37. data/config/locales/i18n_feedback.uk.yml +0 -16
  38. data/config/locales/i18n_feedback.ur.yml +0 -16
  39. data/config/locales/i18n_feedback.vi.yml +0 -16
  40. data/config/locales/i18n_feedback.zh-CN.yml +0 -16
  41. data/config/routes.rb +0 -13
  42. data/lib/generators/i18n_feedback/install/install_generator.rb +0 -40
  43. data/lib/generators/i18n_feedback/install/templates/create_i18n_feedback_suggestions.rb.tt +0 -22
  44. data/lib/generators/i18n_feedback/install/templates/initializer.rb +0 -56
  45. data/lib/i18n_feedback/configuration.rb +0 -91
  46. data/lib/i18n_feedback/engine.rb +0 -26
  47. data/lib/i18n_feedback/marking.rb +0 -46
  48. data/lib/i18n_feedback/middleware.rb +0 -145
  49. data/lib/i18n_feedback/version.rb +0 -5
  50. data/lib/i18n_feedback/widget.js +0 -443
  51. data/lib/i18n_feedback/widget.rb +0 -96
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- module I18nFeedback
6
- # Serves the self-contained browser widget. The JavaScript is plain ES (no
7
- # framework, no build step) and styles itself inline, so it drops into any Rails
8
- # app regardless of its CSS or JS setup. It is inlined into the page rather than
9
- # served as a separate asset to avoid any dependency on the host's asset
10
- # pipeline.
11
- module Widget
12
- # Lives under lib/ (not app/assets/), so a host that runs an asset
13
- # pipeline never ingests it: Rails auto-registers every engine's
14
- # app/assets/* directory, which would put this file in the host's asset
15
- # namespace as a bare "widget.js" and into its precompiled output.
16
- SOURCE = File.expand_path('widget.js', __dir__)
17
-
18
- # Right-to-left scripts, so the popover renders mirrored for those locales.
19
- # Matched on the language subtag, so region variants ("ar-EG") count too.
20
- RTL_LANGUAGES = %w[ar arc ckb dv fa ha he ks ku ps sd ug ur yi].freeze
21
-
22
- class << self
23
- def javascript
24
- @javascript ||= File.read(SOURCE)
25
- end
26
-
27
- # The two <script> tags to place before </body>.
28
- #
29
- # The config rides in a `type="application/json"` block: it is *data*, not
30
- # code, so the browser never executes it and Turbo never tries to re-run it
31
- # on a soft visit — which means it needs no CSP nonce and, crucially, the
32
- # widget can re-read the *current* page's config on every `turbo:load`
33
- # instead of being stuck with whatever the last full load evaluated.
34
- #
35
- # `nonce:` stamps only the widget script (the code), so it runs under a
36
- # nonce-based Content-Security-Policy; pass nil when the app has no nonce.
37
- def snippet(endpoint:, locale:, active:, nonce: nil)
38
- config = {
39
- endpoint: endpoint,
40
- locale: locale.to_s,
41
- active: active ? true : false,
42
- showPill: I18nFeedback.config.show_pill ? true : false,
43
- pillLabel: I18nFeedback.config.pill_label,
44
- toggleParam: I18nFeedback.config.toggle_param,
45
- labels: labels(locale),
46
- rtl: rtl?(locale)
47
- }
48
- # Escape "</" so a value can't close the <script> block early.
49
- json = config.to_json.gsub('</', '<\/')
50
- nonce_attr = nonce ? %( nonce="#{nonce}") : ''
51
-
52
- %(<script type="application/json" data-i18n-feedback-config>#{json}</script>) +
53
- %(<script data-i18n-feedback-widget#{nonce_attr}>#{javascript}</script>)
54
- end
55
-
56
- private
57
-
58
- # Every user-facing string in the widget, resolved through Rails I18n so the
59
- # popover matches the locale the page was rendered in. The locale is passed
60
- # explicitly (not read from I18n.locale) because auto-injection runs in
61
- # middleware *after* the controller action, by which point an
62
- # `around_action { I18n.with_locale(...) }` has reset the ambient locale
63
- # back to the default. Each lookup carries an English default, so the widget
64
- # stays fully worded even for a locale the gem ships no translation for.
65
- def labels(locale)
66
- {
67
- pill: t(locale, :pill, 'Suggest edits'),
68
- pillActive: t(locale, :pill_active, 'Stop suggesting (Esc)'),
69
- title: t(locale, :title, 'Suggest a translation fix'),
70
- currentText: t(locale, :current_text, 'Current text'),
71
- suggestedText: t(locale, :suggested_text, 'Suggested text'),
72
- comment: t(locale, :comment, 'Comment'),
73
- commentPlaceholder: t(locale, :comment_placeholder, 'Optional note for the developer'),
74
- priorTitle: t(locale, :prior_title, 'Already suggested (pending)'),
75
- cancel: t(locale, :cancel, 'Cancel'),
76
- save: t(locale, :save, 'Send suggestion'),
77
- errorBlank: t(locale, :error_blank, 'Please enter a suggestion.'),
78
- errorSave: t(locale, :error_save, 'Could not save the suggestion.')
79
- }
80
- end
81
-
82
- # Resolve under the given locale, tolerating one the app doesn't list in
83
- # available_locales (enforce_available_locales would otherwise raise) — the
84
- # English default still applies.
85
- def t(locale, key, default)
86
- I18n.t(key, scope: :i18n_feedback, locale: locale, default: default)
87
- rescue I18n::InvalidLocale
88
- default
89
- end
90
-
91
- def rtl?(locale)
92
- RTL_LANGUAGES.include?(locale.to_s.downcase.split(/[-_]/).first)
93
- end
94
- end
95
- end
96
- end