export const LOCALE_COOKIE = "adc_locale"; export const locales = ["nl", "en", "yue"] as const; export type Locale = (typeof locales)[number]; type TranslationKey = | "appName" | "articles.title" | "articles.description" | "articles.count" | "articles.heading" | "articles.code" | "articles.descriptionColumn" | "articles.loading" | "articles.emptyTitle" | "articles.emptyDescription" | "articles.error" | "articles.search" | "auth.logout" | "login.title" | "login.description" | "login.demoCredentials" | "login.username" | "login.password" | "login.submit" | "login.submitting" | "login.invalidCredentials" | "login.unexpectedError" | "language.label"; const translations: Record> = { nl: { appName: "ADC BestelApp", "articles.title": "SAP Business One Artikelen", "articles.description": "Overzicht van artikelen opgehaald via de SAP Business One Service Layer.", "articles.count": "Aantal artikelen", "articles.heading": "Artikelen", "articles.code": "Artikelcode", "articles.descriptionColumn": "Omschrijving", "articles.loading": "Artikelen laden...", "articles.emptyTitle": "Geen artikelen gevonden", "articles.emptyDescription": "De Service Layer heeft geen artikelen teruggegeven.", "articles.error": "Er is een fout opgetreden bij het ophalen van de artikelen.", "articles.search": "Zoeken", "auth.logout": "Uitloggen", "login.title": "Inloggen", "login.description": "Log in om de artikelen te bekijken.", "login.demoCredentials": "Gebruikersnaam: admin, wachtwoord: admin", "login.username": "Gebruikersnaam", "login.password": "Wachtwoord", "login.submit": "Inloggen", "login.submitting": "Bezig met inloggen...", "login.invalidCredentials": "Ongeldige gebruikersnaam of wachtwoord.", "login.unexpectedError": "Er is een fout opgetreden. Probeer het opnieuw.", "language.label": "Taal", }, en: { appName: "ADC Order App", "articles.title": "SAP Business One Items", "articles.description": "Overview of items retrieved through the SAP Business One Service Layer.", "articles.count": "Number of items", "articles.heading": "Items", "articles.code": "Item code", "articles.descriptionColumn": "Description", "articles.loading": "Loading items...", "articles.emptyTitle": "No items found", "articles.emptyDescription": "The Service Layer returned no items.", "articles.error": "An error occurred while retrieving the items.", "articles.search": "Search", "auth.logout": "Log out", "login.title": "Sign in", "login.description": "Sign in to view the items.", "login.demoCredentials": "Username: admin, password: admin", "login.username": "Username", "login.password": "Password", "login.submit": "Sign in", "login.submitting": "Signing in...", "login.invalidCredentials": "Invalid username or password.", "login.unexpectedError": "An error occurred. Please try again.", "language.label": "Language", }, yue: { appName: "ADC 訂貨應用程式", "articles.title": "SAP Business One 貨品", "articles.description": "透過 SAP Business One Service Layer 取得嘅貨品一覽。", "articles.count": "貨品數量", "articles.heading": "貨品", "articles.code": "貨品編號", "articles.descriptionColumn": "描述", "articles.loading": "載入貨品中...", "articles.emptyTitle": "搵唔到貨品", "articles.emptyDescription": "Service Layer 冇返回任何貨品。", "articles.error": "取得貨品時發生錯誤。", "articles.search": "搜尋", "auth.logout": "登出", "login.title": "登入", "login.description": "登入後查看貨品。", "login.demoCredentials": "使用者名稱:admin,密碼:admin", "login.username": "使用者名稱", "login.password": "密碼", "login.submit": "登入", "login.submitting": "登入中...", "login.invalidCredentials": "使用者名稱或密碼錯誤。", "login.unexpectedError": "發生錯誤,請再試一次。", "language.label": "語言", }, }; export function getLocale(value?: string): Locale { return locales.includes(value as Locale) ? (value as Locale) : "nl"; } export function t(locale: Locale, key: TranslationKey): string { return translations[locale][key]; } export function getLanguageName(locale: Locale): string { return { nl: "Nederlands", en: "English", yue: "廣東話" }[locale]; } export type { TranslationKey };