Files
web/apps/scandic-web/constants/languages.ts
Anton Gunnarsson 846fd904a6 Merged in feat/sw-2859-set-up-shared-trpc-package (pull request #2319)
feat(SW-2859): Create trpc package

* Add isEdge, safeTry and dataCache to new common package

* Add eslint and move prettier config

* Clean up tests

* Create trpc package and move initialization

* Move errors and a few procedures

* Move telemetry to common package

* Move tokenManager to common package

* Add Sentry to procedures

* Clean up procedures

* Fix self-referencing imports

* Add exports to packages and lint rule to prevent relative imports

* Add env to trpc package

* Add eslint to trpc package

* Apply lint rules

* Use direct imports from trpc package

* Add lint-staged config to trpc

* Move lang enum to common

* Restructure trpc package folder structure

* Fix lang imports


Approved-by: Linus Flood
2025-06-18 12:14:20 +00:00

116 lines
2.5 KiB
TypeScript

import { Lang } from "@scandic-hotels/common/constants/language"
import type { LowerCaseCountryCode } from "@/types/components/form/phone"
export const languages: Record<Lang, string> = {
[Lang.da]: "Dansk",
[Lang.de]: "Deutsch",
[Lang.en]: "English",
[Lang.fi]: "Suomi",
[Lang.no]: "Norsk",
[Lang.sv]: "Svenska",
}
export const localeToLang: Record<string, Lang> = {
en: Lang.en,
"en-US": Lang.en,
"en-GB": Lang.en,
"en-DE": Lang.en,
"en-DK": Lang.en,
"en-SE": Lang.en,
"en-FI": Lang.en,
sv: Lang.sv,
"se-SE": Lang.sv,
"sv-SE": Lang.sv,
"sv-FI": Lang.sv,
fi: Lang.fi,
"fi-FI": Lang.fi,
"se-FI": Lang.fi,
"smn-FI": Lang.fi,
dk: Lang.da,
da: Lang.da,
"da-DK": Lang.da,
"fo-DK": Lang.da,
de: Lang.de,
"de-DE": Lang.de,
"dsb-DE": Lang.de,
"ksh-DE": Lang.de,
"nds-DE": Lang.de,
"hsb-DE": Lang.de,
"de-CH": Lang.de,
"de-AU": Lang.de,
no: Lang.no,
nb: Lang.no,
"nb-NO": Lang.no,
"nn-NO": Lang.no,
"se-NO": Lang.no,
} as const
export enum ApiLang {
Da = "Da",
De = "De",
En = "En",
Fi = "Fi",
No = "No",
Sv = "Sv",
Unknown = "Unknown",
}
type ApiLangKey = keyof typeof ApiLang
export const langToApiLang: Record<Lang, ApiLangKey> = {
[Lang.da]: ApiLang.Da,
[Lang.de]: ApiLang.De,
[Lang.en]: ApiLang.En,
[Lang.fi]: ApiLang.Fi,
[Lang.no]: ApiLang.No,
[Lang.sv]: ApiLang.Sv,
}
export const languageSelect = [
{ label: "Danish", value: ApiLang.Da },
{ label: "German", value: ApiLang.De },
{ label: "English", value: ApiLang.En },
{ label: "Finnish", value: ApiLang.Fi },
{ label: "Norwegian", value: ApiLang.No },
{ label: "Swedish", value: ApiLang.Sv },
]
/**
* Get localized language options based on the current lang.
*/
export function getLocalizedLanguageOptions(currentLang: Lang) {
const displayNames = new Intl.DisplayNames([currentLang], {
type: "language",
})
return languageSelect.map((option) => {
const localizedName = displayNames.of(option.value)
const capitalizedName = localizedName
? localizedName.charAt(0).toUpperCase() + localizedName.slice(1)
: option.label
return {
value: option.value,
label: capitalizedName,
}
})
}
export function getDefaultCountryFromLang(lang: Lang): LowerCaseCountryCode {
const countryMap: Record<Lang, LowerCaseCountryCode> = {
sv: "se",
da: "dk",
fi: "fi",
no: "no",
de: "de",
en: "se", // Default to Sweden for English
}
return countryMap[lang] || "se"
}