From e71ffbdd9581dc637f1951c29aea645d32e7242b Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 22 Oct 2023 06:22:47 +0100 Subject: [PATCH] prettyify country codes --- src/app/ranking/country/[country]/page.tsx | 5 ++++- src/utils/utils.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/ranking/country/[country]/page.tsx b/src/app/ranking/country/[country]/page.tsx index 5f4bf88..bdf8f9a 100644 --- a/src/app/ranking/country/[country]/page.tsx +++ b/src/app/ranking/country/[country]/page.tsx @@ -8,6 +8,7 @@ import { Spinner } from "@/components/Spinner"; import PlayerRanking from "@/components/player/PlayerRanking"; import { ScoresaberPlayer } from "@/schemas/scoresaber/player"; import { fetchTopPlayers } from "@/utils/scoresaber/api"; +import { normalizedRegionName } from "@/utils/utils"; import { useRouter, useSearchParams } from "next/navigation"; import { useCallback, useEffect, useState } from "react"; import ReactCountryFlag from "react-country-flag"; @@ -121,7 +122,9 @@ export default function RankingCountry({ svg className="!h-8 !w-8" /> -

You are viewing scores from {country}

+

+ You are viewing scores from {normalizedRegionName(country)} +

diff --git a/src/utils/utils.ts b/src/utils/utils.ts index a6cbada..8865076 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,3 +1,15 @@ +let regionNames = new Intl.DisplayNames(["en"], { type: "region" }); + export function isProduction() { return process.env.NODE_ENV === "production"; } + +/** + * Returns the normalized region name + * + * @param region the region to normalize + * @returns the normalized region name + */ +export function normalizedRegionName(region: string) { + return regionNames.of(region); +}