Module: LcpRuby::I18nPayloadHelper
- Defined in:
- app/helpers/lcp_ruby/i18n_payload_helper.rb
Overview
Emits ‘window.LcpI18n` translation payload as an inline <script> tag, resolved under the current `I18n.locale` at request time. The compiled i18n.js.erb bundle contains only locale-independent helpers (LcpI18n.t, LcpI18n.format) so runtime locale switching works without re-compiling the asset.
Namespaces mirror en.yml 1:1 — no flat aliases. Stimulus controllers look up ‘LcpI18n.advanced_filter.toggle` (nested) rather than the legacy `LcpI18n.filter.toggle`.
Class Method Summary collapse
Instance Method Summary collapse
-
#lcp_i18n_payload ⇒ Object
Build the full payload hash.
- #lcp_i18n_payload_tag ⇒ Object
Class Method Details
.clear_payload_cache! ⇒ Object
192 193 194 |
# File 'app/helpers/lcp_ruby/i18n_payload_helper.rb', line 192 def clear_payload_cache! @payload_json_cache = {} end |
.payload_json_cache ⇒ Object
188 189 190 |
# File 'app/helpers/lcp_ruby/i18n_payload_helper.rb', line 188 def payload_json_cache @payload_json_cache ||= {} end |
Instance Method Details
#lcp_i18n_payload ⇒ Object
Build the full payload hash. Extracted so tests can assert shape/content without going through ‘<script>` rendering.
14 15 16 17 18 |
# File 'app/helpers/lcp_ruby/i18n_payload_helper.rb', line 14 def lcp_i18n_payload payload = core_i18n_payload payload[:dev_toolbar] = if LcpRuby::DevToolbar.enabled? payload end |
#lcp_i18n_payload_tag ⇒ Object
20 21 22 23 24 |
# File 'app/helpers/lcp_ruby/i18n_payload_helper.rb', line 20 def lcp_i18n_payload_tag javascript_tag( "window.LcpI18n = Object.assign(window.LcpI18n || {}, #{cached_lcp_i18n_payload_json});" ) end |