From 30116daaf7d46b640a420f8032f8485537bea1a6 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 17 Oct 2023 17:49:17 +0200 Subject: [PATCH] Fixes #36839 - Optimize apipie translate methods --- config/initializers/apipie.rb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/config/initializers/apipie.rb b/config/initializers/apipie.rb index b089ddbefca2..dc1241c8dbf2 100644 --- a/config/initializers/apipie.rb +++ b/config/initializers/apipie.rb @@ -19,13 +19,7 @@ config.default_locale = FastGettext.default_locale config.locale = ->(loc) { loc ? FastGettext.set_locale(loc) : FastGettext.locale } - config.translate = lambda do |str, loc| - old_loc = FastGettext.locale - FastGettext.set_locale(loc) - trans = _(str) if str - FastGettext.set_locale(old_loc) - trans - end + config.translate = ->(stc, loc) { str ? FastGettext.with_locale(loc) { _(str) } : nil } config.help_layout = 'apipie_dsl/apipie_dsls/help.html.erb' end @@ -66,14 +60,9 @@ } config.translate = lambda do |str, loc| - old_loc = FastGettext.locale - FastGettext.set_locale(loc) if str - trans = _(str) - trans = trans % Hash[substitutions.map { |k, v| [k, v.respond_to?(:call) ? v.call : v] }] + FastGettext.with_locale(loc) { _(str) % substitutions.transform_values { |v| v.respond_to?(:call) ? v.call : v } } end - FastGettext.set_locale(old_loc) - trans end end end