From 6c5a5226b8d64b0ec57e4866ef52ae02f3db2b69 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sun, 19 Sep 2021 23:59:53 +0200 Subject: [PATCH] Preserve locale during Runner::Connections --- lib/runner/connection.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/runner/connection.rb b/lib/runner/connection.rb index 7ff5a82d..659d769f 100644 --- a/lib/runner/connection.rb +++ b/lib/runner/connection.rb @@ -12,16 +12,20 @@ class Runner::Connection attr_writer :status attr_reader :error - def initialize(url, strategy, event_loop) + def initialize(url, strategy, event_loop, locale = I18n.locale) @socket = Faye::WebSocket::Client.new(url, [], ping: 5) @strategy = strategy @status = :established @event_loop = event_loop + @locale = locale # For every event type of Faye WebSockets, the corresponding # RunnerConnection method starting with `on_` is called. %i[open message error close].each do |event_type| - @socket.on(event_type) {|event| __send__(:"on_#{event_type}", event) } + @socket.on(event_type) do |event| + # The initial locale when establishing the connection is used for all callbacks + I18n.with_locale(@locale) { __send__(:"on_#{event_type}", event) } + end end # This registers empty default callbacks.