mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
fix(core): language consumption from locale in payment and payout links (#7993)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -619,8 +619,25 @@ const locales = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function getTranslations(locale_str) {
|
function getLanguage(localeStr) {
|
||||||
var fallback_locale = 'en';
|
var fallback_locale = 'en';
|
||||||
var locale = locale_str.toLowerCase().replace(/-/g, "_") || fallback_locale; // defaults if locale is not present in payment details.
|
var primaryLocale = (localeStr.toLowerCase() || fallback_locale).split(',')[0].trim();
|
||||||
return locales[locale] || locales['en']; // defaults if locale is not implemented in locales.
|
|
||||||
|
// Split into language and country parts
|
||||||
|
var parts = primaryLocale.split('-');
|
||||||
|
var language = parts[0];
|
||||||
|
var country = parts.length > 1 ? parts[1] : null;
|
||||||
|
|
||||||
|
var key = `${language}_${country}`;
|
||||||
|
switch (key) {
|
||||||
|
case 'en_gb': return 'en_gb';
|
||||||
|
case 'fr_be': return 'fr_be';
|
||||||
|
default: return language;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTranslations(localeStr) {
|
||||||
|
var fallback_locale = 'en';
|
||||||
|
var language = getLanguage(localeStr);
|
||||||
|
return locales[language] || locales[fallback_locale];
|
||||||
|
}
|
||||||
@ -1,7 +1,29 @@
|
|||||||
|
use common_utils::consts::DEFAULT_LOCALE;
|
||||||
use rust_i18n::t;
|
use rust_i18n::t;
|
||||||
use tera::Context;
|
use tera::Context;
|
||||||
|
|
||||||
|
fn get_language(locale_str: &str) -> String {
|
||||||
|
let lowercase_str = locale_str.to_lowercase();
|
||||||
|
let primary_locale = lowercase_str.split(',').next().unwrap_or("").trim();
|
||||||
|
|
||||||
|
if primary_locale.is_empty() {
|
||||||
|
return DEFAULT_LOCALE.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let parts = primary_locale.split('-').collect::<Vec<&str>>();
|
||||||
|
let language = *parts.first().unwrap_or(&DEFAULT_LOCALE);
|
||||||
|
let country = parts.get(1).copied();
|
||||||
|
|
||||||
|
match (language, country) {
|
||||||
|
("en", Some("gb")) => "en_gb".to_string(),
|
||||||
|
("fr", Some("be")) => "fr_be".to_string(),
|
||||||
|
(lang, _) => lang.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert_locales_in_context_for_payout_link(context: &mut Context, locale: &str) {
|
pub fn insert_locales_in_context_for_payout_link(context: &mut Context, locale: &str) {
|
||||||
|
let language = get_language(locale);
|
||||||
|
let locale = language.as_str();
|
||||||
let i18n_payout_link_title = t!("payout_link.initiate.title", locale = locale);
|
let i18n_payout_link_title = t!("payout_link.initiate.title", locale = locale);
|
||||||
let i18n_january = t!("months.january", locale = locale);
|
let i18n_january = t!("months.january", locale = locale);
|
||||||
let i18n_february = t!("months.february", locale = locale);
|
let i18n_february = t!("months.february", locale = locale);
|
||||||
@ -38,6 +60,8 @@ pub fn insert_locales_in_context_for_payout_link(context: &mut Context, locale:
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_locales_in_context_for_payout_link_status(context: &mut Context, locale: &str) {
|
pub fn insert_locales_in_context_for_payout_link_status(context: &mut Context, locale: &str) {
|
||||||
|
let language = get_language(locale);
|
||||||
|
let locale = language.as_str();
|
||||||
let i18n_payout_link_status_title = t!("payout_link.status.title", locale = locale);
|
let i18n_payout_link_status_title = t!("payout_link.status.title", locale = locale);
|
||||||
let i18n_success_text = t!("payout_link.status.text.success", locale = locale);
|
let i18n_success_text = t!("payout_link.status.text.success", locale = locale);
|
||||||
let i18n_success_message = t!("payout_link.status.message.success", locale = locale);
|
let i18n_success_message = t!("payout_link.status.message.success", locale = locale);
|
||||||
|
|||||||
Reference in New Issue
Block a user