Skip to content

Commit

Permalink
fix(ui-ux): de translations on landing page (#739)
Browse files Browse the repository at this point in the history
* fix(ui-ux): de translations on landing page

* fix e2e

* fix e2e

* fix comments
  • Loading branch information
chloezxyy authored Feb 21, 2024
1 parent 37d77b8 commit 09b3cf2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ viewports.forEach((viewport) => {
// No TC
it("should have expected Header title and description", () => {
cy.findByTestId("header-title").should(
"have.text",
"contain",
"Connecting old and new worlds",
);

Expand Down
2 changes: 1 addition & 1 deletion public/locales/de/page-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"masternodes": {
"title": "MASTERNODES",
"desc": "${{perc}} gesperrt"
"desc": "Über {{perc}} $ gesperrt"
}
},
"ReadyForFlexibilitySection": {
Expand Down
7 changes: 2 additions & 5 deletions src/components/commons/StatisticPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ function getLocaledStatisticValue(
end={Number(value)}
enableScrollSpy
duration={0.5}
/>
{suffix !== "" ? ` ${t(`statisticsDisplay.suffix.${suffix}`)} ` : ``}

{/* This prefix is for the $ symbol */}
{prefix ?? ""}
/>{" "}
{suffix ?? ""} {prefix ?? ""} {/* This prefix is for the $ symbol */}
</>
);

Expand Down
14 changes: 13 additions & 1 deletion src/components/index/BlockchainFeaturesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Container } from "@components/commons/Container";
import { useTranslation } from "next-i18next";
import Slider from "react-slick";
import { SectionTitle } from "@components/commons/SectionTitle";
import { useRouter } from "next/router";
import { BlockchainFeatureColumn } from "./BlockchainFeatureColumn";

export const BlockchainFeatureItems = [
Expand Down Expand Up @@ -30,6 +31,7 @@ export const BlockchainFeatureItems = [

export function BlockchainFeaturesSection(): JSX.Element {
const { t } = useTranslation("page-index");
const router = useRouter();
const separatedTitle = t("BlockchainFeatureSection.title").split(" ");
const sliderSettings = {
arrows: false,
Expand All @@ -41,6 +43,16 @@ export function BlockchainFeaturesSection(): JSX.Element {
dotsClass: "blockchain-features-dots",
};

function displayColorToLanguage(index: number): boolean {
if (router.locale === "de") {
return index === 3;
}
if (router.locale === "en-US") {
return index === 2;
}
return false;
}

return (
<section
className="lg:py-[156px] md:py-24 pt-20 pb-12"
Expand All @@ -61,7 +73,7 @@ export function BlockchainFeaturesSection(): JSX.Element {
data-testid={`section-header-${separatedTitle}`}
>
{separatedTitle.map((word, index) =>
index === 2 ? (
displayColorToLanguage(index) ? (
<span key={`${word}`}>
<br />
<span
Expand Down
32 changes: 26 additions & 6 deletions src/components/index/HomePageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ import { Container } from "@components/commons/Container";
import { useTranslation } from "next-i18next";
import { Video } from "@components/commons/Video";
import classNames from "classnames";
import { useRouter } from "next/router";

export function HomePageHeader(): JSX.Element {
const { t } = useTranslation("page-index");
const router = useRouter();

const separatedTitle = t("Header.title").split(" ");
const firstWord = separatedTitle[0];
separatedTitle.shift();

function displayColorToLanguage(index: number): boolean {
if (router.locale === "de") {
return index === 1;
}
if (router.locale === "en-US") {
return index === 0;
}
return false;
}

return (
<div className="flex flex-col items-center md:mt-0 relative z-[-1]">
Expand All @@ -23,11 +34,20 @@ export function HomePageHeader(): JSX.Element {
className="w-full text-5xl leading-[52px] lg:text-[80px] lg:leading-[84px]"
data-testid="header-title"
>
<span className="text-brand-100">
{firstWord} <br />
</span>
{separatedTitle.join(" ")}
{separatedTitle.map((word, index) =>
displayColorToLanguage(index) ? (
<span key={`${word}`}>
<span
className="text-brand-100"
key={`${word}`}
>{`${word} `}</span>
</span>
) : (
<span key={`${word}`}>{`${word} `}</span>
),
)}
</h1>

<div className="mt-5">
<div
className="w-full tracking-[0.03em] text-dark-700 font-desc lg:tracking-normal lg:text-xl "
Expand Down
8 changes: 7 additions & 1 deletion src/components/index/StatisticsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import classNames from "classnames";
import { useTranslation } from "next-i18next";
import { useWindowDimensions } from "@hooks/useWindowDimensions";
import { StatisticPanel } from "@components/commons/StatisticPanel";
import { useRouter } from "next/router";
import { useWhaleApiClient } from "../../layouts/context/WhaleContext";
import { calculatePercentage } from "../../shared/calculatePercentage";

export function StatsDisplay() {
const api = useWhaleApiClient();
const router = useRouter();

const [stats, setStats] = useState<StatsData>();
const [supply, setSupply] = useState<SupplyData>();
const { t } = useTranslation("page-index");
Expand All @@ -38,7 +41,10 @@ export function StatsDisplay() {
const { suffix, value } = useUnitSuffix(
stats ? stats.tvl.masternodes.toString() : "N/A",
);
const masternodeValue = value === "N/A" ? undefined : `${value + suffix}+`;

const formattedValue =
router.locale === "de" ? `${value} ${suffix}` : value + suffix;
const masternodeValue = value === "N/A" ? undefined : `${formattedValue}`;

const statsItems = [
{
Expand Down
19 changes: 18 additions & 1 deletion src/hooks/useUnitSuffix.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BigNumber from "bignumber.js";
import { useRouter } from "next/router";

const units = {
3: "K+",
Expand All @@ -7,15 +8,31 @@ const units = {
12: "T+",
};

const deUnits = {
3: "Tsd.",
6: "Mio.",
9: "Mrd.",
12: "Bio.",
};

interface UnitSuffix {
suffix: string;
value: string;
}

// Function to convert numbers to formatted numbers with units Eg.$161M ++ = Über xxx Mio. $
export function useUnitSuffix(value, decimalPlace = 0): UnitSuffix {
const router = useRouter();

const updatedValue = BigNumber(value);
const places = updatedValue.e !== null ? Math.floor(updatedValue.e / 3) : 0;
const suffix = `${units[places * 3] ?? ""}`;

let suffix = "";
if (router.locale === "de") {
suffix = `${deUnits[places * 3] ?? ""}`;
} else {
suffix = `${units[places * 3] ?? ""}`;
}
const unitValueWithSuffix = {
suffix,
value,
Expand Down

0 comments on commit 09b3cf2

Please sign in to comment.