diff --git a/src/common/constants.ts b/src/common/constants.ts index 169c4fdc882..313d40f1b89 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -16,6 +16,15 @@ const domain_url_pair = { [staging_deriv_be_url]: deriv_be_url, } +export const domains = [ + deriv_com_url, + deriv_me_url, + deriv_be_url, + staging_deriv_be_url, + 'localhost', + 'deriv-com-git-fork', +] //deriv-com-git-fork for vercel server, localhost - for developer mode + const getDomainUrl = (): string => isBrowser() && window.location.hostname in domain_url_pair ? domain_url_pair[window.location.hostname] diff --git a/src/common/utility.js b/src/common/utility.js index 95d3be04a59..f336fa3f609 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -7,6 +7,7 @@ import { deriv_app_languages, live_chat_redirection_link, live_chat_key, + domains, } from './constants' import { isUK } from 'common/country-base' import { localize } from 'components/localization' @@ -316,12 +317,16 @@ export const addScript = (settings) => { export const isChoosenLanguage = () => ({ english: getLanguage() === 'en' }) // Function to manually replace server's locale ("zh_tw" or "zh_cn") to "zh-tw"/"zh-cn" -export const replaceLocale = (locale) => { - let checked_locale = locale - if (locale === 'zh_tw') { - checked_locale = 'zh-tw' - } else if (locale === 'zh_cn') { - checked_locale = 'zh-cn' +export const replaceLocale = (url) => { + let checked_locale = url + const excluded_paths = ['smarttrader'] + if (!excluded_paths.some((path) => url.includes(path))) { + domains.forEach((domain) => { + if (url.includes(domain) && url.includes('zh_tw')) + checked_locale = url.replace(/(zh_tw)/g, 'zh-tw') + if (url.includes(domain) && url.includes('zh_cn')) + checked_locale = url.replace(/(zh_cn)/g, 'zh-cn') + }) } return checked_locale } diff --git a/src/components/localization/localized-link.js b/src/components/localization/localized-link.js index 65a71b9a2f6..3cc0072faa9 100644 --- a/src/components/localization/localized-link.js +++ b/src/components/localization/localized-link.js @@ -7,7 +7,12 @@ import { LocationContext } from '../layout/location-context.js' import language_config from '../../../i18n-config' import { LocaleContext } from './locale-context' import { localized_link_url } from 'common/constants' -import { getLocalizedUrl, getDerivAppLocalizedURL, getThaiExcludedLocale } from 'common/utility' +import { + getLocalizedUrl, + getDerivAppLocalizedURL, + getThaiExcludedLocale, + replaceLocale, +} from 'common/utility' import { DerivStore } from 'store' export const SharedLinkStyle = css` @@ -183,7 +188,7 @@ const ExternalLink = ({ const { is_eu_country } = useContext(DerivStore) const { setModalPayload, toggleModal } = useContext(LocationContext) const { affiliate_lang } = language_config[locale] - const url = getURLFormat(type, locale, to, affiliate_lang) + const url = replaceLocale(getURLFormat(type, locale, to, affiliate_lang)) const show_modal = is_eu_country && !is_mail_link &&