Skip to content

Commit

Permalink
Fixes #36839 - Optimize apipie translate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Oct 19, 2023
1 parent 7585e55 commit 30116da
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions config/initializers/apipie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 30116da

Please sign in to comment.