From 00d3ff36419a521a8860f4396f5f6c85b29f8906 Mon Sep 17 00:00:00 2001 From: 5andi5 <5andi5@inbox.lv> Date: Mon, 26 Jun 2023 20:56:55 +0300 Subject: [PATCH] Resolve bank UI language from I18n locale --- lib/omniauth/strategies/swedbank.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/omniauth/strategies/swedbank.rb b/lib/omniauth/strategies/swedbank.rb index 5ef5666..ff88517 100644 --- a/lib/omniauth/strategies/swedbank.rb +++ b/lib/omniauth/strategies/swedbank.rb @@ -110,6 +110,8 @@ def request_phase return fail!(:private_key_load_err, e) end + set_locale_from_query_param + form = OmniAuth::Form.new(:title => I18n.t('omniauth.swedbank.please_wait'), :url => options.site) { @@ -120,7 +122,7 @@ def request_phase 'VK_NONCE' => stamp, 'VK_RETURN' => callback_url, 'VK_MAC' => signature(priv_key), - 'VK_LANG' => 'LAT', + 'VK_LANG' => resolve_bank_ui_language, 'VK_ENCODING' => 'UTF-8' }.each do |name, val| form.html "" @@ -139,6 +141,23 @@ def request_phase private + def set_locale_from_query_param + locale = request.params['locale'] + if (locale != nil && locale.strip != '' && I18n.locale_available?(locale)) + I18n.locale = locale + end + end + + def resolve_bank_ui_language + case I18n.locale + when :ru then 'RUS' + when :en then 'ENG' + when :et then 'EST' + when :lt then 'LIT' + else 'LAT' + end + end + def escape(html_attribute_value) CGI.escapeHTML(html_attribute_value) unless html_attribute_value.nil? end