Skip to content

Commit

Permalink
i18n url workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian0701 committed Sep 25, 2023
1 parent 05329c5 commit 3efb400
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/components/crypto_summary/crypto_summary.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import {useRouter} from 'next/router';
import Image from 'next/image';
import {BiLinkAlt} from 'react-icons/bi';
import {useTranslation} from 'next-i18next';
import Link from 'next/link';
import {getI18nLink} from '../../lib/common';

type TranslateFunction = (s: string) => string;
interface ICryptoSummary {
Expand Down Expand Up @@ -36,10 +38,14 @@ const CryptoSummary = ({
tradingValue,
}: ICryptoSummary) => {
const {t}: {t: TranslateFunction} = useTranslation('common');

const {locale} = useRouter();
const overallWidth = 'w-full pr-5 lg:p-0 lg:w-2/3 xl:w-3/4';
const dividerWidth = 'w-full lg:w-2/3 xl:w-3/4';

// Info: (20230925 - Julian) i18n URL workaround
const whitePaperLinkWithI18n = getI18nLink(whitePaperLink, locale ?? '') ?? whitePaperLink;
const websiteLinkWithI18n = getI18nLink(websiteLink, locale ?? '') ?? websiteLink;

return (
<>
<div className="flex-col justify-start">
Expand All @@ -66,7 +72,7 @@ const CryptoSummary = ({
{/* Links */}
<div className="mt-5 flex space-x-2">
<Link
href={whitePaperLink}
href={whitePaperLinkWithI18n}
target="_blank"
className={`flex flex-row items-center space-x-2 rounded-full bg-lightGray3 px-3 py-1 text-sm font-bold text-lightWhite transition-colors duration-300 hover:bg-lightGray1 hover:text-black`}
>
Expand All @@ -75,8 +81,7 @@ const CryptoSummary = ({
</Link>

<Link
locale={'zh-tw'}
href={websiteLink}
href={websiteLinkWithI18n}
target="_blank"
className={`flex flex-row items-center space-x-2 rounded-full bg-lightGray3 px-3 py-1 text-sm font-bold text-lightWhite transition-colors duration-300 hover:bg-lightGray1 hover:text-black`}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/market_section/market_section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const MarketSection = (props: IMarketSectionProps) => {
<div className="ml-5 py-100px">
<div className="ml-5">{displayedTickerHeader}</div>

{/* <div>{displayedTradingView}</div> */}
<div>{displayedTradingView}</div>

<div className="mt-5 lg:mt-8 lg:pl-5">
<TradeStatistics
Expand Down
28 changes: 21 additions & 7 deletions src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,10 @@ export const getEstimatedPnL = (
};

export const swapKeysAndValues = (obj: Record<string, string>): Record<string, string> => {
return Object.entries(obj).reduce(
(acc, [key, value]) => {
acc[value] = key;
return acc;
},
{} as Record<string, string>
);
return Object.entries(obj).reduce((acc, [key, value]) => {
acc[value] = key;
return acc;
}, {} as Record<string, string>);
};

export const findCodeByReason = (reason: string): ICode | undefined => {
Expand Down Expand Up @@ -744,3 +741,20 @@ export function isValidTradeURL(url: string): boolean {

return result;
}

// Info:(20230925 - Julian) i18n URL workaround
export const getI18nLink = (link: string, locale: string) => {
if (link.toLowerCase().includes('bitcoin')) {
const bitcoinText = locale === 'tw' ? 'zh_TW' : locale === 'cn' ? 'zh_CN' : 'en';
const bitcoinLink = link.includes('en')
? link.replace('en', bitcoinText)
: `${link}/${bitcoinText}`;
return bitcoinLink;
} else if (link.toLowerCase().includes('ethereum')) {
const ethereumText = locale === 'tw' ? 'zh-tw' : locale === 'cn' ? 'zh' : 'en';
const ethereumLink = link.includes('en')
? link.replace('en', ethereumText)
: `${link}/${ethereumText}`;
return ethereumLink;
}
};

0 comments on commit 3efb400

Please sign in to comment.