Files

53 lines
3.1 KiB
TypeScript

type DefaultLangCode = "de"
type SupportedLangCode = "en" | "fr"
type LangCode = DefaultLangCode | SupportedLangCode
type RouteUri = | "/bedarfsausweis" | "/velopers" | "/faq" | "/pdf/ansichtsausweis" | "/pdf/datenblatt" | "/user" | "/energieausweis-erstellen/verbrauchsausweis-wohnenerstellen" | "/energieausweis-erstellen/verbrauchsausweis-wohnen" | "/energieausweis-erstellen/verbrauchsausweis-wohnen-gewerbe" | "/" | "/kaufabschluss" | "/kundendaten" | "/login" | "/logout" | "/signup"
type RouteParams = {"/bedarfsausweis": undefined; "/velopers": undefined; "/faq": undefined; "/pdf/ansichtsausweis": undefined; "/pdf/datenblatt": undefined; "/user": undefined; "/energieausweis-erstellen/verbrauchsausweis-wohnenerstellen": undefined; "/energieausweis-erstellen/verbrauchsausweis-wohnen": undefined; "/energieausweis-erstellen/verbrauchsausweis-wohnen-gewerbe": undefined; "/": undefined; "/kaufabschluss": undefined; "/kundendaten": undefined; "/login": undefined; "/logout": undefined; "/signup": undefined; }
type TranslationPath = "header.profil" | "header.kontakt" | "header.login"
type TranslationOptions = { "header.profil": {} | undefined; "header.kontakt": {} | undefined; "header.login": {} | undefined; }
declare module "astro-i18n" {
export * from "astro-i18n/"
export function l<Uri extends RouteUri>(
route: Uri | string & {},
...args: Uri extends keyof RouteParams
? undefined extends RouteParams[Uri]
? [params?: Record<string, string>, targetLangCode?: LangCode, routeLangCode?: LangCode]
: [params: RouteParams[Uri], targetLangCode?: LangCode, routeLangCode?: LangCode]
: [params?: Record<string, string>, targetLangCode?: LangCode, routeLangCode?: LangCode]
): string
export function t<Path extends TranslationPath>(
path: Path | string & {},
...args: undefined extends TranslationOptions[Path]
? [options?: keyof TranslationOptions extends Path ? Record<string, unknown> : TranslationOptions[Path], langCode?: LangCode]
: [options: TranslationOptions[Path], langCode?: LangCode]
): string
export function extractRouteLangCode(route: string): LangCode | undefined
type Translation = string | { [translationKey: string]: string | Translation }
type Translations = { [langCode: string]: Record<string, Translation> }
type RouteTranslations = { [langCode: string]: Record<string, string> }
type InterpolationFormatter = (value: unknown, ...args: unknown[]) => string
class AstroI18n {
defaultLangCode: DefaultLangCode
supportedLangCodes: SupportedLangCode[]
showDefaultLangCode: boolean
translations: Translations
routeTranslations: RouteTranslations
get langCodes(): LangCode[]
get langCode(): LangCode
set langCode(langCode: LangCode)
get formatters(): Record<string, InterpolationFormatter>
init(Astro: { url: URL }, formatters?: Record<string, InterpolationFormatter>): void
addTranslations(translations: Translations): void
addRouteTranslations(routeTranslations: RouteTranslations): void
getFormatter(name: string): InterpolationFormatter | undefined
setFormatter(name: string, formatter: InterpolationFormatter): void
deleteFormatter(name: string): void
}
export const astroI18n: AstroI18n
}