🌐 Streamline supported languages (#1728)

This commit is contained in:
Luke Vella 2025-05-25 11:33:24 +01:00 committed by GitHub
parent c5724f0118
commit 061989d241
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 64 deletions

View file

@ -21,21 +21,17 @@ import { usePreferences } from "@/contexts/preferences";
import { useTranslation } from "@/i18n/client";
import { getBrowserTimeZone, normalizeTimeZone } from "@/utils/date-time-utils";
import type { SupportedLocale } from "@rallly/languages";
import { useRequiredContext } from "../components/use-required-context";
const dayjsLocales: Record<
string,
SupportedLocale,
{
weekStart: number;
timeFormat: TimeFormat;
import: () => Promise<ILocale>;
}
> = {
eu: {
weekStart: 1,
timeFormat: "hours24",
import: () => import("dayjs/locale/eu"),
},
en: {
weekStart: 1,
timeFormat: "hours12",
@ -51,11 +47,6 @@ const dayjsLocales: Record<
timeFormat: "hours24",
import: () => import("dayjs/locale/es"),
},
ca: {
weekStart: 1,
timeFormat: "hours24",
import: () => import("dayjs/locale/ca"),
},
da: {
weekStart: 1,
timeFormat: "hours24",
@ -76,11 +67,6 @@ const dayjsLocales: Record<
timeFormat: "hours24",
import: () => import("dayjs/locale/fr"),
},
hr: {
weekStart: 1,
timeFormat: "hours24",
import: () => import("dayjs/locale/hr"),
},
it: {
weekStart: 1,
timeFormat: "hours24",
@ -91,11 +77,6 @@ const dayjsLocales: Record<
timeFormat: "hours24",
import: () => import("dayjs/locale/sv"),
},
sk: {
weekStart: 1,
timeFormat: "hours24",
import: () => import("dayjs/locale/sk"),
},
cs: {
weekStart: 1,
timeFormat: "hours24",
@ -141,21 +122,6 @@ const dayjsLocales: Record<
timeFormat: "hours24",
import: () => import("dayjs/locale/zh"),
},
"zh-Hant": {
weekStart: 0,
timeFormat: "hours24",
import: () => import("dayjs/locale/zh-tw"),
},
vi: {
weekStart: 1,
timeFormat: "hours24",
import: () => import("dayjs/locale/vi"),
},
tr: {
weekStart: 1,
timeFormat: "hours24",
import: () => import("dayjs/locale/tr"),
},
};
dayjs.extend(localizedFormat);
@ -195,7 +161,7 @@ export const useDayjs = () => {
export const DayjsProvider: React.FunctionComponent<{
children?: React.ReactNode;
config?: {
locale?: string;
locale?: SupportedLocale;
timeZone?: string;
localeOverrides?: {
weekStart?: number;
@ -281,7 +247,7 @@ export const ConnectedDayjsProvider = ({
return (
<DayjsProvider
config={{
locale: i18n.language,
locale: i18n.language as SupportedLocale,
timeZone: preferences.timeZone ?? undefined,
localeOverrides: {
weekStart: preferences.weekStart ?? undefined,

View file

@ -1,4 +1,6 @@
import languages from "./languages.json";
import { languages } from "./languages";
export type SupportedLocale = keyof typeof languages;
export const supportedLngs = Object.keys(languages);

View file

@ -1,25 +0,0 @@
{
"eu": "Basque",
"ca": "Català",
"cs": "Česky",
"da": "Dansk",
"de": "Deutsch",
"en": "English",
"en-GB": "English (UK)",
"es": "Español",
"fr": "Français",
"hr": "Hrvatski",
"it": "Italiano",
"hu": "Magyar",
"nl": "Nederlands",
"no": "Norsk",
"pl": "Polski",
"pt-BR": "Português - Brasil",
"ru": "Русский",
"sk": "Slovenčina",
"fi": "Suomi",
"sv": "Svenska",
"tr": "Türkçe",
"zh": "简体中文",
"zh-Hant": "繁體中文"
}

View file

@ -0,0 +1,20 @@
export const languages = {
cs: "Česky",
da: "Dansk",
de: "Deutsch",
en: "English",
"en-GB": "English (UK)",
es: "Español",
fr: "Français",
it: "Italiano",
hu: "Magyar",
nl: "Nederlands",
no: "Norsk",
pl: "Polski",
pt: "Português",
"pt-BR": "Português - Brasil",
ru: "Русский",
fi: "Suomi",
sv: "Svenska",
zh: "简体中文",
};