Ursprung
36c2695c8c
Commit
4442909633
229
src/env.d.ts
vendored
229
src/env.d.ts
vendored
@ -1,229 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2023 SteamWar.de-Serverteam
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <reference path="../.astro/types.d.ts" />
|
|
||||||
/// <reference types="astro/client" />
|
|
||||||
|
|
||||||
/// <reference path="../.astro-i18n/generated.d.ts" />
|
|
||||||
|
|
||||||
/// <reference path="..\.astro-i18n\generated.d.ts" />
|
|
||||||
|
|
||||||
// ###> astro-i18n/type-generation ###
|
|
||||||
type PrimaryLocale = "en"
|
|
||||||
type SecondaryLocale = "de"
|
|
||||||
type Locale = PrimaryLocale | SecondaryLocale
|
|
||||||
type RouteParameters = {"/dashboard":undefined;"/downloads":undefined;"/":undefined;"/login":undefined;"/[...slug]":{"slug":unknown;};"/admin":undefined;"/announcements":undefined;"/announcements/[...slug]":{"slug":unknown;};"/announcements/tags/[tag]":{"tag":unknown;};"/help":undefined;"/help/[...slug]":{"slug":unknown;};"/ranked/[...gamemode]":{"gamemode":unknown;};"/rules":undefined;"/rules/[mode]":{"mode":unknown;};"/stats/fight":undefined;}
|
|
||||||
type Route = keyof RouteParameters
|
|
||||||
type TranslationVariables = {"dashboard.page":object|undefined;"dashboard.title":{"name"?:unknown;}|undefined;"dashboard.rank":{"rank"?:unknown;}|undefined;"dashboard.permissions":object|undefined;"dashboard.buttons.logout":object|undefined;"dashboard.buttons.admin":object|undefined;"dashboard.schematic.upload":object|undefined;"dashboard.schematic.home":object|undefined;"dashboard.schematic.dir":object|undefined;"dashboard.schematic.head.type":object|undefined;"dashboard.schematic.head.name":object|undefined;"dashboard.schematic.head.owner":object|undefined;"dashboard.schematic.head.updated":object|undefined;"dashboard.schematic.head.replaceColor":object|undefined;"dashboard.schematic.head.allowReplay":object|undefined;"dashboard.schematic.info.path":{"path"?:unknown;}|undefined;"dashboard.schematic.info.replaceColor":object|undefined;"dashboard.schematic.info.allowReplay":object|undefined;"dashboard.schematic.info.type":{"type"?:unknown;}|undefined;"dashboard.schematic.info.updated":{"updated"?:unknown;}|undefined;"dashboard.schematic.info.item":{"item"?:unknown;}|undefined;"dashboard.schematic.info.members":{"members"?:unknown;}|undefined;"dashboard.schematic.info.btn.download":object|undefined;"dashboard.schematic.info.btn.close":object|undefined;"login.page":object|undefined;"login.title":object|undefined;"login.placeholder.username":object|undefined;"login.placeholder.token":object|undefined;"login.label.username":object|undefined;"login.label.token":object|undefined;"login.generateToken":object|undefined;"login.submit":object|undefined;"login.error":object|undefined;"blog.title":object|undefined;"page":object|undefined;"wg.description":object|undefined;"as.description":object|undefined;"ws.description":object|undefined;"mwg.description":object|undefined;"rules":object|undefined;"announcements":object|undefined;"ranking":object|undefined;"title":{"mode"?:unknown;}|undefined;"stats.title":object|undefined;"navbar.title":object|undefined;"navbar.logo.alt":object|undefined;"navbar.links.home.title":object|undefined;"navbar.links.home.announcements":object|undefined;"navbar.links.home.about":object|undefined;"navbar.links.home.downloads":object|undefined;"navbar.links.home.faq":object|undefined;"navbar.links.rules.title":object|undefined;"navbar.links.rules.gamemode":object|undefined;"navbar.links.rules.wg":object|undefined;"navbar.links.rules.mwg":object|undefined;"navbar.links.rules.ws":object|undefined;"navbar.links.rules.as":object|undefined;"navbar.links.rules.qg":object|undefined;"navbar.links.rules.rotating":object|undefined;"navbar.links.rules.megawg":object|undefined;"navbar.links.rules.micro":object|undefined;"navbar.links.rules.sf":object|undefined;"navbar.links.rules.general":object|undefined;"navbar.links.rules.coc":object|undefined;"navbar.links.help.title":object|undefined;"navbar.links.help.center":object|undefined;"navbar.links.help.docs":object|undefined;"navbar.links.account":object|undefined;"status.loading":object|undefined;"status.status":object|undefined;"status.online":object|undefined;"status.offline":object|undefined;"status.players":{"count"?:unknown;}|undefined;"status.version":{"version"?:unknown;}|undefined;"home.page":object|undefined;"home.title.first":object|undefined;"home.title.second":object|undefined;"home.subtitle.1":object|undefined;"home.subtitle.2":object|undefined;"home.subtitle.3":object|undefined;"home.join":object|undefined;"home.benefits.historic.title":object|undefined;"home.benefits.historic.description.1":object|undefined;"home.benefits.historic.description.2":object|undefined;"home.benefits.server.title":object|undefined;"home.benefits.server.description":object|undefined;"home.benefits.events.title":object|undefined;"home.benefits.events.description.1":object|undefined;"home.benefits.events.description.2":object|undefined;"home.benefits.read":object|undefined;"home.prefix.Admin":object|undefined;"home.prefix.Dev":object|undefined;"home.prefix.Mod":object|undefined;"home.prefix.Sup":object|undefined;"home.prefix.Arch":object|undefined;"footer.imprint":object|undefined;"footer.privacy":object|undefined;"footer.coc":object|undefined;"footer.stats":object|undefined;"footer.gamemodes":object|undefined;"footer.announcements":object|undefined;"footer.join":object|undefined;"wg.title":object|undefined;"mwg.title":object|undefined;"ws.title":object|undefined;"as.title":object|undefined;"qg.title":object|undefined;"ranking.heading":{"mode"?:unknown;}|undefined;"announcements.table.time":object|undefined;"announcements.table.blue":object|undefined;"announcements.table.red":object|undefined;"announcements.table.team":object|undefined;"announcements.table.points":object|undefined;"elo.place":object|undefined;"elo.name":object|undefined;"elo.elo":object|undefined;"elo.title":{"mode"?:unknown;}|undefined;"warning.title":object|undefined;"warning.text":object|undefined;}
|
|
||||||
type Translation = keyof TranslationVariables
|
|
||||||
type Environment = "none"|"node"|"browser"
|
|
||||||
declare module "astro-i18n" {
|
|
||||||
type GetStaticPathsProps = {paginate:Function;rss:Function}
|
|
||||||
type GetStaticPathsItem = {params:Record<string,number|string|undefined>;props?:Record<string,unknown>}
|
|
||||||
type DeepStringRecord = {[key: string]:string|DeepStringRecord}
|
|
||||||
type TranslationDirectory = {i18n?:string;pages?: string}
|
|
||||||
export type Translations = {[group: string]:{[locale: string]: DeepStringRecord}}
|
|
||||||
export type TranslationFormatters = {[formatterName: string]:(value:unknown,...args:unknown[])=>unknown}
|
|
||||||
export type TranslationLoadingRules = {groups:string[];routes: string[]}[]
|
|
||||||
export type SegmentTranslations = {[secondaryLocale: string]:{[segment: string]:string}}
|
|
||||||
export interface AstroI18nConfig {primaryLocale:string;secondaryLocales:string[];fallbackLocale:string;showPrimaryLocale:boolean;trailingSlash:"always"|"never";run:"server"|"client+server";translations:Translations;translationLoadingRules:TranslationLoadingRules;translationDirectory:TranslationDirectory;routes:SegmentTranslations;}
|
|
||||||
/** Typed astro-i18n config definition. */
|
|
||||||
export function defineAstroI18nConfig(config: Partial<AstroI18nConfig>): Partial<AstroI18nConfig>
|
|
||||||
/** The `astro-i18n` middleware. */
|
|
||||||
export function useAstroI18n(
|
|
||||||
config?: Partial<AstroI18nConfig> | string,
|
|
||||||
formatters?: TranslationFormatters,
|
|
||||||
): (...args: any[]) => any
|
|
||||||
/** Workaround function to make astroI18n work inside getStaticPaths. This is because Astro's getStaticPaths runs before everything which doesn't allows astroI18n to update its state automatically. */
|
|
||||||
function createGetStaticPaths(
|
|
||||||
callback: (
|
|
||||||
props: GetStaticPathsProps,
|
|
||||||
) => GetStaticPathsItem[] | Promise<GetStaticPathsItem[]>,
|
|
||||||
): (props: GetStaticPathsProps & {
|
|
||||||
astroI18n?: {
|
|
||||||
locale: string;
|
|
||||||
};
|
|
||||||
}) => Promise<GetStaticPathsItem[]>
|
|
||||||
/**
|
|
||||||
* @param key The translation key, for example `"my.nested.translation.key"`.
|
|
||||||
* @param properties An object containing your interpolation variables and/or your variants, for example `{ variant: 3, interpolation: "text" }`.
|
|
||||||
* @param options `route`: Overrides the current route, you will be able to access that route's translations. `locale`: Overrides the current locale, this allows you to control which language you want to translate to. `fallbackLocale`: Overrides the fallback locale.
|
|
||||||
*/
|
|
||||||
export function t<T extends Translation>(
|
|
||||||
key: T | string & {},
|
|
||||||
...args: undefined extends TranslationVariables[T]
|
|
||||||
? [
|
|
||||||
properties?: keyof TranslationVariables extends T
|
|
||||||
? Record<string, unknown>
|
|
||||||
: TranslationVariables[T],
|
|
||||||
options?: {
|
|
||||||
route?: Route | string & {}
|
|
||||||
locale?: Locale | string & {}
|
|
||||||
fallbackLocale?: Locale | string & {}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
properties: TranslationVariables[T],
|
|
||||||
options?: {
|
|
||||||
route?: Route | string & {}
|
|
||||||
locale?: Locale | string & {}
|
|
||||||
fallbackLocale?: Locale | string & {}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
): string
|
|
||||||
/**
|
|
||||||
* @param route A route in any of the configured languages, for example `"/en/my/english/route/[param]"`.
|
|
||||||
* @param parameters An object containing your route parameters, for example `{ slug: "my-blog-post-slug" }`.
|
|
||||||
* @param options `targetLocale`: Overrides the target locale. `routeLocale`: Overrides the given route locale, this is useful if astro-i18n cannot figure out the route's locale. `showPrimaryLocale`: Overrides the showPrimaryLocale parameter. `query`: Adds these query parameters at the end of the translated route.
|
|
||||||
*/
|
|
||||||
export function l<T extends Route>(
|
|
||||||
route: T | string & {},
|
|
||||||
...args: T extends keyof RouteParameters
|
|
||||||
? undefined extends RouteParameters[T]
|
|
||||||
? [
|
|
||||||
parameters?: Record<string, string>,
|
|
||||||
options?: {
|
|
||||||
targetLocale?: string,
|
|
||||||
routeLocale?: string,
|
|
||||||
showPrimaryLocale?: string,
|
|
||||||
query?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
parameters: RouteParameters[T],
|
|
||||||
options?: {
|
|
||||||
targetLocale?: string,
|
|
||||||
routeLocale?: string,
|
|
||||||
showPrimaryLocale?: string,
|
|
||||||
query?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
parameters?: Record<string, string>,
|
|
||||||
options?: {
|
|
||||||
targetLocale?: string,
|
|
||||||
routeLocale?: string,
|
|
||||||
showPrimaryLocale?: string,
|
|
||||||
query?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
]
|
|
||||||
): string
|
|
||||||
class AstroI18n {
|
|
||||||
/** The detected runtime environment. */
|
|
||||||
environment: Environment
|
|
||||||
/** The current page route. */
|
|
||||||
route: string
|
|
||||||
/** All page routes. For example: `["/", "/about", "/posts/[slug]"]` */
|
|
||||||
pages: string[]
|
|
||||||
/** The equivalent page for the current route. For example if route is equal to `"/posts/my-cool-cat"` this could return `"/posts/[slug]"`. */
|
|
||||||
page: string
|
|
||||||
/** The current page locale. */
|
|
||||||
locale: Locale
|
|
||||||
/** All configured locales. */
|
|
||||||
locales: Locale[]
|
|
||||||
/** The default/primary locale. */
|
|
||||||
primaryLocale: PrimaryLocale
|
|
||||||
/** Locales other than the default/primary one. */
|
|
||||||
secondaryLocales: SecondaryLocale[]
|
|
||||||
/** The fallback locale, when a translation is missing in a locale the fallback locale will be used to find a replacement. */
|
|
||||||
fallbackLocale: Locale
|
|
||||||
/** True when astro-i18n is initialized. */
|
|
||||||
isInitialized: boolean
|
|
||||||
/**
|
|
||||||
* @param key The translation key, for example `"my.nested.translation.key"`.
|
|
||||||
* @param properties An object containing your interpolation variables and/or your variants, for example `{ variant: 3, interpolation: "text" }`.
|
|
||||||
* @param options `route`: Overrides the current route, you will be able to access that route's translations. `locale`: Overrides the current locale, this allows you to control which language you want to translate to. `fallbackLocale`: Overrides the fallback locale.
|
|
||||||
*/
|
|
||||||
t<T extends Translation>(
|
|
||||||
key: T | string & {},
|
|
||||||
...args: undefined extends TranslationVariables[T]
|
|
||||||
? [
|
|
||||||
properties?: keyof TranslationVariables extends T
|
|
||||||
? Record<string, unknown>
|
|
||||||
: TranslationVariables[T],
|
|
||||||
options?: {
|
|
||||||
route?: Route | string & {}
|
|
||||||
locale?: Locale | string & {}
|
|
||||||
fallbackLocale?: Locale | string & {}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
properties: TranslationVariables[T],
|
|
||||||
options?: {
|
|
||||||
route?: Route | string & {}
|
|
||||||
locale?: Locale | string & {}
|
|
||||||
fallbackLocale?: Locale | string & {}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
): string
|
|
||||||
/**
|
|
||||||
* @param route A route in any of the configured languages, for example `"/en/my/english/route/[param]"`.
|
|
||||||
* @param parameters An object containing your route parameters, for example `{ slug: "my-blog-post-slug" }`.
|
|
||||||
* @param options `targetLocale`: Overrides the target locale. `routeLocale`: Overrides the given route locale, this is useful if astro-i18n cannot figure out the route's locale. `showPrimaryLocale`: Overrides the showPrimaryLocale parameter. `query`: Adds these query parameters at the end of the translated route.
|
|
||||||
*/
|
|
||||||
l<T extends Route>(
|
|
||||||
route: T | string & {},
|
|
||||||
...args: T extends keyof RouteParameters
|
|
||||||
? undefined extends RouteParameters[T]
|
|
||||||
? [
|
|
||||||
parameters?: Record<string, string>,
|
|
||||||
options?: {
|
|
||||||
targetLocale?: string,
|
|
||||||
routeLocale?: string,
|
|
||||||
showPrimaryLocale?: string,
|
|
||||||
query?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
parameters: RouteParameters[T],
|
|
||||||
options?: {
|
|
||||||
targetLocale?: string,
|
|
||||||
routeLocale?: string,
|
|
||||||
showPrimaryLocale?: string,
|
|
||||||
query?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
parameters?: Record<string, string>,
|
|
||||||
options?: {
|
|
||||||
targetLocale?: string,
|
|
||||||
routeLocale?: string,
|
|
||||||
showPrimaryLocale?: string,
|
|
||||||
query?: Record<string, unknown>
|
|
||||||
}
|
|
||||||
]
|
|
||||||
): string
|
|
||||||
/** Adds new translations at runtime. */
|
|
||||||
addTranslations(translations: Translations): this
|
|
||||||
/** Adds new translation formatters at runtime. */
|
|
||||||
addFormatters(translationFormatters: TranslationFormatters): this
|
|
||||||
/** Adds new translation loading rules at runtime. */
|
|
||||||
addTranslationLoadingRules(translationLoadingRules: TranslationLoadingRules): this
|
|
||||||
/** Adds new route segment translations at runtime. */
|
|
||||||
addRoutes(routes: SegmentTranslations): this
|
|
||||||
/** Tries to parse one of the configured locales out of the given route. If no configured locale is found it will return `null`. */
|
|
||||||
extractRouteLocale(route: string): string|null
|
|
||||||
/** Initializes astro-i18n on the server-side. */
|
|
||||||
initialize(config?: Partial<AstroI18nConfig> | string, formatters?: TranslationFormatters = {}): Promise<void>
|
|
||||||
/** Redirects the user to the given destination. */
|
|
||||||
redirect(destination: string | URL, status = 301)
|
|
||||||
}
|
|
||||||
export const astroI18n: AstroI18n
|
|
||||||
}
|
|
||||||
// ###< astro-i18n/type-generation ###
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren