command.valid? fills the error messages. So wrapping that with I18n.with_locale ensures those messages are translated according to the error_locale_resolver.
Previously tried to ensure this through a command_middleware, like:
class EnsureCommandErrorLocale
def self.call(command, &block)
I18n.with_locale(Sequent.configuration.error_locale_resolver&.call || I18n.locale) do
command.valid?
end
block.call
end
end
But the command.valid? called in Sequent::Core::CommandService#process_command will override the messages again, reverting it back to the default I18n.locale. Hence this PR.
command.valid?
fills the error messages. So wrapping that withI18n.with_locale
ensures those messages are translated according to theerror_locale_resolver
.Previously tried to ensure this through a command_middleware, like:
But the
command.valid?
called inSequent::Core::CommandService#process_command
will override the messages again, reverting it back to the defaultI18n.locale
. Hence this PR.