diff --git a/lib/core/i18n/i18n.utils.ts b/lib/core/i18n/i18n.utils.ts index 1d9885ea..b67da656 100644 --- a/lib/core/i18n/i18n.utils.ts +++ b/lib/core/i18n/i18n.utils.ts @@ -44,31 +44,3 @@ export const getOrSetUserLocaleFromHeaders = async (req: IncomingMessage): Promi return preferredLocale; }; - -interface localeType { - [locale: string]: string; -} - -export const localeLabels: localeType = { - en: "English", - fr: "French", - it: "Italian", - ru: "Russian", - es: "Spanish", - de: "German", - pt: "Portuguese", - ro: "Romanian", - nl: "Dutch", - "pt-BR": "Portuguese (Brazilian)", - "es-419": "Spanish, Latin America", - ko: "Korean", -}; - -export type OptionType = { - value: string; - label: string; -}; - -export const localeOptions: OptionType[] = i18n.locales.map((locale) => { - return { value: locale, label: localeLabels[locale] }; -}); diff --git a/lib/core/i18n/weekday.ts b/lib/core/i18n/weekday.ts new file mode 100644 index 00000000..d1983491 --- /dev/null +++ b/lib/core/i18n/weekday.ts @@ -0,0 +1,8 @@ +// By default starts on Sunday (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) +export function weekdayNames(locale: string | string[], weekStart = 0, type: "short" | "long" = "long") { + return Array.from(Array(7).keys()).map((d) => nameOfDay(locale, d + weekStart, type)); +} + +export function nameOfDay(locale: string | string[], day: number, type: "short" | "long" = "long") { + return new Intl.DateTimeFormat(locale, { weekday: type }).format(new Date(1970, 0, day + 4)); +} diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx index e8f0d137..b37531f7 100644 --- a/pages/settings/profile.tsx +++ b/pages/settings/profile.tsx @@ -1,18 +1,15 @@ import { InformationCircleIcon } from "@heroicons/react/outline"; import crypto from "crypto"; import { GetServerSidePropsContext } from "next"; -import { RefObject, useEffect, useRef, useState } from "react"; -import Select from "react-select"; +import { i18n } from "next-i18next.config"; +import { ComponentProps, RefObject, useEffect, useRef, useState } from "react"; +import Select, { OptionTypeBase } from "react-select"; import TimezoneSelect from "react-timezone-select"; +import { QueryCell } from "@lib/QueryCell"; import { asStringOrNull, asStringOrUndefined } from "@lib/asStringOrNull"; import { getSession } from "@lib/auth"; -import { - getOrSetUserLocaleFromHeaders, - localeLabels, - localeOptions, - OptionType, -} from "@lib/core/i18n/i18n.utils"; +import { nameOfDay } from "@lib/core/i18n/weekday"; import { useLocale } from "@lib/hooks/useLocale"; import { isBrandingHidden } from "@lib/isBrandingHidden"; import showToast from "@lib/notification"; @@ -20,7 +17,7 @@ import prisma from "@lib/prisma"; import { trpc } from "@lib/trpc"; import { inferSSRProps } from "@lib/types/inferSSRProps"; -import { DialogClose, Dialog, DialogContent } from "@components/Dialog"; +import { Dialog, DialogClose, DialogContent } from "@components/Dialog"; import ImageUploader from "@components/ImageUploader"; import SettingsShell from "@components/SettingsShell"; import Shell from "@components/Shell"; @@ -31,6 +28,14 @@ import Button from "@components/ui/Button"; import { UsernameInput } from "@components/ui/UsernameInput"; type Props = inferSSRProps; + +const getLocaleOptions = (displayLocale: string | string[]): OptionTypeBase[] => { + return i18n.locales.map((locale) => ({ + value: locale, + label: new Intl.DisplayNames(displayLocale, { type: "language" }).of(locale), + })); +}; + function HideBrandingInput(props: { hideBrandingRef: RefObject; user: Props["user"] }) { const { t } = useLocale(); const [modelOpen, setModalOpen] = useState(false); @@ -58,12 +63,12 @@ function HideBrandingInput(props: { hideBrandingRef: RefObject /> -
-