Skip to content

Commit 7ab8a6b

Browse files
DEV: Refactor for core changes (#12)
Core's script helper methods expect to be run in the context of a controller, with access to the response property. This is especially important now that core is applying a CSP nonce to every `<script>`.
1 parent 70ae43e commit 7ab8a6b

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

lib/multilingual/locale_loader.rb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# frozen_string_literal: true
22
class ::Multilingual::LocaleLoader
3-
include ::ApplicationHelper
3+
attr_reader :controller
44

5-
attr_reader :ctx
5+
delegate :request, to: :controller
6+
delegate :helpers, to: :controller, private: true
7+
delegate :asset_path, to: :helpers
68

7-
def initialize(ctx)
8-
@ctx = ctx
9-
end
10-
11-
def request
12-
@ctx && @ctx.request ? @ctx.request : ActionDispatch::Request.new
13-
end
14-
15-
def asset_path(url)
16-
ActionController::Base.helpers.asset_path(url)
9+
def initialize(controller)
10+
@controller = controller
1711
end
1812

1913
def current_locale
@@ -25,14 +19,14 @@ def custom_locale?
2519
end
2620

2721
def preload_i18n
28-
preload_script("locales/i18n")
22+
helpers.preload_script("locales/i18n")
2923
end
3024

3125
def preload_custom_locale
32-
preload_script_url(ExtraLocalesController.url('custom-language'))
26+
helpers.preload_script_url(ExtraLocalesController.url("custom-language"))
3327
end
3428

3529
def preload_tag_translations
36-
preload_script_url(ExtraLocalesController.url('tags'))
30+
helpers.preload_script_url(ExtraLocalesController.url("tags"))
3731
end
3832
end

0 commit comments

Comments
 (0)