Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Niloofar Sadeghi / Fix broken terms and condition link for "zh-tw" and "zh-cn" language #2657

Merged
6 commits merged into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 11 additions & 6 deletions src/common/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions src/components/localization/localized-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 &&
Expand Down