Add linting with prettier.
This commit is contained in:
parent
c5b054d5ec
commit
39fc988bce
16 changed files with 11073 additions and 11077 deletions
2
.prettierignore
Normal file
2
.prettierignore
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
dist
|
||||||
|
node_modules
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { defineConfig } from 'astro/config';
|
import { defineConfig } from "astro/config";
|
||||||
|
|
||||||
import node from "@astrojs/node";
|
import node from "@astrojs/node";
|
||||||
|
|
||||||
|
|
@ -8,5 +8,5 @@ export default defineConfig({
|
||||||
output: "hybrid",
|
output: "hybrid",
|
||||||
adapter: node({
|
adapter: node({
|
||||||
mode: "middleware",
|
mode: "middleware",
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
31
index.js
31
index.js
|
|
@ -1,12 +1,12 @@
|
||||||
import { createBareServer } from "@tomphttp/bare-server-node"
|
import { createBareServer } from "@tomphttp/bare-server-node";
|
||||||
import { uvPath } from "@nebula-services/ultraviolet"
|
import { uvPath } from "@nebula-services/ultraviolet";
|
||||||
import http from 'node:http';
|
import http from "node:http";
|
||||||
import path from 'node:path';
|
import path from "node:path";
|
||||||
import express from 'express';
|
import express from "express";
|
||||||
import { handler as ssrHandler } from './dist/server/entry.mjs';
|
import { handler as ssrHandler } from "./dist/server/entry.mjs";
|
||||||
import dotenv from 'dotenv';
|
import dotenv from "dotenv";
|
||||||
import compression from "compression"
|
import compression from "compression";
|
||||||
import chalk from "chalk"
|
import chalk from "chalk";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
@ -19,14 +19,15 @@ app.use(express.static(path.join(process.cwd(), "static")));
|
||||||
app.use(express.static(path.join(process.cwd(), "build")));
|
app.use(express.static(path.join(process.cwd(), "build")));
|
||||||
app.use("/uv/", express.static(uvPath));
|
app.use("/uv/", express.static(uvPath));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({
|
app.use(
|
||||||
extended: true
|
express.urlencoded({
|
||||||
|
extended: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
app.use("/", express.static('dist/client/'));
|
app.use("/", express.static("dist/client/"));
|
||||||
app.use(ssrHandler);
|
app.use(ssrHandler);
|
||||||
|
|
||||||
app.get('*', function(req, res){
|
app.get("*", function (req, res) {
|
||||||
res.status(200).sendFile("404.html", { root: path.resolve("dist/client") });
|
res.status(200).sendFile("404.html", { root: path.resolve("dist/client") });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -46,11 +47,11 @@ server.on("upgrade", (req, socket, head) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(chalk.gray("Starting Alu..."))
|
console.log(chalk.gray("Starting Alu..."));
|
||||||
server.on("listening", () => {
|
server.on("listening", () => {
|
||||||
console.log(chalk.green(`Server running at http://localhost:${PORT}/.`));
|
console.log(chalk.green(`Server running at http://localhost:${PORT}/.`));
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen({
|
server.listen({
|
||||||
port: PORT
|
port: PORT,
|
||||||
});
|
});
|
||||||
938
package-lock.json
generated
938
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -4,14 +4,16 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node .",
|
"start": "node .",
|
||||||
"build": "astro build"
|
"build": "astro build",
|
||||||
|
"lint": "prettier --write .",
|
||||||
|
"lint:check": "prettier --check ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/check": "^0.4.0",
|
"@astrojs/check": "^0.4.0",
|
||||||
"@astrojs/node": "^7.0.4",
|
"@astrojs/node": "^7.0.4",
|
||||||
"@nebula-services/ultraviolet": "^1.0.1-1.patch.5",
|
"@nebula-services/ultraviolet": "^1.0.1-1.patch.5",
|
||||||
"@tomphttp/bare-server-node": "^2.0.1",
|
"@tomphttp/bare-server-node": "^2.0.1",
|
||||||
"astro": "^4.1.1",
|
"astro": "^4.3.3",
|
||||||
"astro-i18n": "^2.2.4",
|
"astro-i18n": "^2.2.4",
|
||||||
"astro-i18next": "^1.0.0-beta.21",
|
"astro-i18next": "^1.0.0-beta.21",
|
||||||
"chalk": "^5.3.0",
|
"chalk": "^5.3.0",
|
||||||
|
|
@ -23,5 +25,8 @@
|
||||||
"i18next-browser-languagedetector": "^7.2.0",
|
"i18next-browser-languagedetector": "^7.2.0",
|
||||||
"npm": "^10.2.5",
|
"npm": "^10.2.5",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "3.2.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
prettier.config.js
Normal file
10
prettier.config.js
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
const config = {
|
||||||
|
tabWidth: 2,
|
||||||
|
semi: true,
|
||||||
|
trailingComma: "es5",
|
||||||
|
bracketSpacing: true,
|
||||||
|
bracketSameLine: true,
|
||||||
|
arrowParens: "always",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
* Ideally, this will be registered under the scope in uv.config.js so it will not need to be modified.
|
* Ideally, this will be registered under the scope in uv.config.js so it will not need to be modified.
|
||||||
* However, if a user changes the location of uv.bundle.js/uv.config.js or sw.js is not relative to them, they will need to modify this script locally.
|
* However, if a user changes the location of uv.bundle.js/uv.config.js or sw.js is not relative to them, they will need to modify this script locally.
|
||||||
*/
|
*/
|
||||||
importScripts('/uv/uv.bundle.js');
|
importScripts("/uv/uv.bundle.js");
|
||||||
importScripts('/uv.config.js');
|
importScripts("/uv.config.js");
|
||||||
importScripts(__uv$config.sw);
|
importScripts(__uv$config.sw);
|
||||||
|
|
||||||
self.addEventListener("install", (event) => {
|
self.addEventListener("install", (event) => {
|
||||||
|
|
@ -15,4 +15,4 @@ self.addEventListener("install", (event) => {
|
||||||
|
|
||||||
const sw = new UVServiceWorker();
|
const sw = new UVServiceWorker();
|
||||||
|
|
||||||
self.addEventListener('fetch', (event) => event.respondWith(sw.fetch(event)));
|
self.addEventListener("fetch", (event) => event.respondWith(sw.fetch(event)));
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
/*global Ultraviolet*/
|
/*global Ultraviolet*/
|
||||||
self.__uv$config = {
|
self.__uv$config = {
|
||||||
prefix: '/service/',
|
prefix: "/service/",
|
||||||
bare: '/bare/',
|
bare: "/bare/",
|
||||||
encodeUrl: Ultraviolet.codec.xor.encode,
|
encodeUrl: Ultraviolet.codec.xor.encode,
|
||||||
decodeUrl: Ultraviolet.codec.xor.decode,
|
decodeUrl: Ultraviolet.codec.xor.decode,
|
||||||
handler: '/uv/uv.handler.js',
|
handler: "/uv/uv.handler.js",
|
||||||
client: '/uv/uv.client.js',
|
client: "/uv/uv.client.js",
|
||||||
bundle: '/uv/uv.bundle.js',
|
bundle: "/uv/uv.bundle.js",
|
||||||
config: '/uv/uv.config.js',
|
config: "/uv/uv.config.js",
|
||||||
sw: '/uv/uv.sw.js',
|
sw: "/uv/uv.sw.js",
|
||||||
};
|
};
|
||||||
234
src/env.d.ts
vendored
234
src/env.d.ts
vendored
|
|
@ -1,205 +1,247 @@
|
||||||
/// <reference types="astro/client" />
|
/// <reference types="astro/client" />
|
||||||
|
|
||||||
// ###> astro-i18n/type-generation ###
|
// ###> astro-i18n/type-generation ###
|
||||||
type PrimaryLocale = "en"
|
type PrimaryLocale = "en";
|
||||||
type SecondaryLocale = ""
|
type SecondaryLocale = "";
|
||||||
type Locale = PrimaryLocale | SecondaryLocale
|
type Locale = PrimaryLocale | SecondaryLocale;
|
||||||
type RouteParameters = {"/games":undefined;"/":undefined;"/settings":undefined;"/404":undefined;}
|
type RouteParameters = {
|
||||||
type Route = keyof RouteParameters
|
"/games": undefined;
|
||||||
type TranslationVariables = {"nav.brand":object|undefined;"nav.games":object|undefined;"nav.settings":object|undefined;}
|
"/": undefined;
|
||||||
type Translation = keyof TranslationVariables
|
"/settings": undefined;
|
||||||
type Environment = "none"|"node"|"browser"
|
"/404": undefined;
|
||||||
|
};
|
||||||
|
type Route = keyof RouteParameters;
|
||||||
|
type TranslationVariables = {
|
||||||
|
"nav.brand": object | undefined;
|
||||||
|
"nav.games": object | undefined;
|
||||||
|
"nav.settings": object | undefined;
|
||||||
|
};
|
||||||
|
type Translation = keyof TranslationVariables;
|
||||||
|
type Environment = "none" | "node" | "browser";
|
||||||
declare module "astro-i18n" {
|
declare module "astro-i18n" {
|
||||||
type GetStaticPathsProps = {paginate:Function;rss:Function}
|
type GetStaticPathsProps = { paginate: Function; rss: Function };
|
||||||
type GetStaticPathsItem = {params:Record<string,number|string|undefined>;props?:Record<string,unknown>}
|
type GetStaticPathsItem = {
|
||||||
type DeepStringRecord = {[key: string]:string|DeepStringRecord}
|
params: Record<string, number | string | undefined>;
|
||||||
type TranslationDirectory = {i18n?:string;pages?: string}
|
props?: Record<string, unknown>;
|
||||||
export type Translations = {[group: string]:{[locale: string]: DeepStringRecord}}
|
};
|
||||||
export type TranslationFormatters = {[formatterName: string]:(value:unknown,...args:unknown[])=>unknown}
|
type DeepStringRecord = { [key: string]: string | DeepStringRecord };
|
||||||
export type TranslationLoadingRules = {groups:string[];routes: string[]}[]
|
type TranslationDirectory = { i18n?: string; pages?: string };
|
||||||
export type SegmentTranslations = {[secondaryLocale: string]:{[segment: string]:string}}
|
export type Translations = {
|
||||||
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;srcDir:string;}
|
[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;
|
||||||
|
srcDir: string;
|
||||||
|
}
|
||||||
/** Typed astro-i18n config definition. */
|
/** Typed astro-i18n config definition. */
|
||||||
export function defineAstroI18nConfig(config: Partial<AstroI18nConfig>): Partial<AstroI18nConfig>
|
export function defineAstroI18nConfig(
|
||||||
|
config: Partial<AstroI18nConfig>
|
||||||
|
): Partial<AstroI18nConfig>;
|
||||||
/** The `astro-i18n` middleware. */
|
/** The `astro-i18n` middleware. */
|
||||||
export function useAstroI18n(
|
export function useAstroI18n(
|
||||||
config?: Partial<AstroI18nConfig> | string,
|
config?: Partial<AstroI18nConfig> | string,
|
||||||
formatters?: TranslationFormatters,
|
formatters?: TranslationFormatters
|
||||||
): (...args: any[]) => any
|
): (...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. */
|
/** 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(
|
function createGetStaticPaths(
|
||||||
callback: (
|
callback: (
|
||||||
props: GetStaticPathsProps,
|
props: GetStaticPathsProps
|
||||||
) => GetStaticPathsItem[] | Promise<GetStaticPathsItem[]>,
|
) => GetStaticPathsItem[] | Promise<GetStaticPathsItem[]>
|
||||||
): (props: GetStaticPathsProps & {
|
): (
|
||||||
|
props: GetStaticPathsProps & {
|
||||||
astroI18n?: {
|
astroI18n?: {
|
||||||
locale: string;
|
locale: string;
|
||||||
};
|
};
|
||||||
}) => Promise<GetStaticPathsItem[]>
|
}
|
||||||
|
) => Promise<GetStaticPathsItem[]>;
|
||||||
/**
|
/**
|
||||||
* @param key The translation key, for example `"my.nested.translation.key"`.
|
* @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 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.
|
* @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>(
|
export function t<T extends Translation>(
|
||||||
key: T | string & {},
|
key: T | (string & {}),
|
||||||
...args: undefined extends TranslationVariables[T]
|
...args: undefined extends TranslationVariables[T]
|
||||||
? [
|
? [
|
||||||
properties?: keyof TranslationVariables extends T
|
properties?: keyof TranslationVariables extends T
|
||||||
? Record<string, unknown>
|
? Record<string, unknown>
|
||||||
: TranslationVariables[T],
|
: TranslationVariables[T],
|
||||||
options?: {
|
options?: {
|
||||||
route?: Route | string & {}
|
route?: Route | (string & {});
|
||||||
locale?: Locale | string & {}
|
locale?: Locale | (string & {});
|
||||||
fallbackLocale?: Locale | string & {}
|
fallbackLocale?: Locale | (string & {});
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
properties: TranslationVariables[T],
|
properties: TranslationVariables[T],
|
||||||
options?: {
|
options?: {
|
||||||
route?: Route | string & {}
|
route?: Route | (string & {});
|
||||||
locale?: Locale | string & {}
|
locale?: Locale | (string & {});
|
||||||
fallbackLocale?: Locale | string & {}
|
fallbackLocale?: Locale | (string & {});
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
): string
|
): string;
|
||||||
/**
|
/**
|
||||||
* @param route A route in any of the configured languages, for example `"/en/my/english/route/[param]"`.
|
* @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 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.
|
* @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>(
|
export function l<T extends Route>(
|
||||||
route: T | string & {},
|
route: T | (string & {}),
|
||||||
...args: T extends keyof RouteParameters
|
...args: T extends keyof RouteParameters
|
||||||
? undefined extends RouteParameters[T]
|
? undefined extends RouteParameters[T]
|
||||||
? [
|
? [
|
||||||
parameters?: Record<string, string>,
|
parameters?: Record<string, string>,
|
||||||
options?: {
|
options?: {
|
||||||
targetLocale?: string,
|
targetLocale?: string;
|
||||||
routeLocale?: string,
|
routeLocale?: string;
|
||||||
showPrimaryLocale?: string,
|
showPrimaryLocale?: string;
|
||||||
query?: Record<string, unknown>
|
query?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
parameters: RouteParameters[T],
|
parameters: RouteParameters[T],
|
||||||
options?: {
|
options?: {
|
||||||
targetLocale?: string,
|
targetLocale?: string;
|
||||||
routeLocale?: string,
|
routeLocale?: string;
|
||||||
showPrimaryLocale?: string,
|
showPrimaryLocale?: string;
|
||||||
query?: Record<string, unknown>
|
query?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
parameters?: Record<string, string>,
|
parameters?: Record<string, string>,
|
||||||
options?: {
|
options?: {
|
||||||
targetLocale?: string,
|
targetLocale?: string;
|
||||||
routeLocale?: string,
|
routeLocale?: string;
|
||||||
showPrimaryLocale?: string,
|
showPrimaryLocale?: string;
|
||||||
query?: Record<string, unknown>
|
query?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
): string
|
): string;
|
||||||
class AstroI18n {
|
class AstroI18n {
|
||||||
/** The detected runtime environment. */
|
/** The detected runtime environment. */
|
||||||
environment: Environment
|
environment: Environment;
|
||||||
/** The current page route. */
|
/** The current page route. */
|
||||||
route: string
|
route: string;
|
||||||
/** All page routes. For example: `["/", "/about", "/posts/[slug]"]` */
|
/** All page routes. For example: `["/", "/about", "/posts/[slug]"]` */
|
||||||
pages: string[]
|
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]"`. */
|
/** 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
|
page: string;
|
||||||
/** The current page locale. */
|
/** The current page locale. */
|
||||||
locale: Locale
|
locale: Locale;
|
||||||
/** All configured locales. */
|
/** All configured locales. */
|
||||||
locales: Locale[]
|
locales: Locale[];
|
||||||
/** The default/primary locale. */
|
/** The default/primary locale. */
|
||||||
primaryLocale: PrimaryLocale
|
primaryLocale: PrimaryLocale;
|
||||||
/** Locales other than the default/primary one. */
|
/** Locales other than the default/primary one. */
|
||||||
secondaryLocales: SecondaryLocale[]
|
secondaryLocales: SecondaryLocale[];
|
||||||
/** The fallback locale, when a translation is missing in a locale the fallback locale will be used to find a replacement. */
|
/** The fallback locale, when a translation is missing in a locale the fallback locale will be used to find a replacement. */
|
||||||
fallbackLocale: Locale
|
fallbackLocale: Locale;
|
||||||
/** True when astro-i18n is initialized. */
|
/** True when astro-i18n is initialized. */
|
||||||
isInitialized: boolean
|
isInitialized: boolean;
|
||||||
/**
|
/**
|
||||||
* @param key The translation key, for example `"my.nested.translation.key"`.
|
* @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 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.
|
* @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>(
|
t<T extends Translation>(
|
||||||
key: T | string & {},
|
key: T | (string & {}),
|
||||||
...args: undefined extends TranslationVariables[T]
|
...args: undefined extends TranslationVariables[T]
|
||||||
? [
|
? [
|
||||||
properties?: keyof TranslationVariables extends T
|
properties?: keyof TranslationVariables extends T
|
||||||
? Record<string, unknown>
|
? Record<string, unknown>
|
||||||
: TranslationVariables[T],
|
: TranslationVariables[T],
|
||||||
options?: {
|
options?: {
|
||||||
route?: Route | string & {}
|
route?: Route | (string & {});
|
||||||
locale?: Locale | string & {}
|
locale?: Locale | (string & {});
|
||||||
fallbackLocale?: Locale | string & {}
|
fallbackLocale?: Locale | (string & {});
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
properties: TranslationVariables[T],
|
properties: TranslationVariables[T],
|
||||||
options?: {
|
options?: {
|
||||||
route?: Route | string & {}
|
route?: Route | (string & {});
|
||||||
locale?: Locale | string & {}
|
locale?: Locale | (string & {});
|
||||||
fallbackLocale?: Locale | string & {}
|
fallbackLocale?: Locale | (string & {});
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
): string
|
): string;
|
||||||
/**
|
/**
|
||||||
* @param route A route in any of the configured languages, for example `"/en/my/english/route/[param]"`.
|
* @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 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.
|
* @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>(
|
l<T extends Route>(
|
||||||
route: T | string & {},
|
route: T | (string & {}),
|
||||||
...args: T extends keyof RouteParameters
|
...args: T extends keyof RouteParameters
|
||||||
? undefined extends RouteParameters[T]
|
? undefined extends RouteParameters[T]
|
||||||
? [
|
? [
|
||||||
parameters?: Record<string, string>,
|
parameters?: Record<string, string>,
|
||||||
options?: {
|
options?: {
|
||||||
targetLocale?: string,
|
targetLocale?: string;
|
||||||
routeLocale?: string,
|
routeLocale?: string;
|
||||||
showPrimaryLocale?: string,
|
showPrimaryLocale?: string;
|
||||||
query?: Record<string, unknown>
|
query?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
parameters: RouteParameters[T],
|
parameters: RouteParameters[T],
|
||||||
options?: {
|
options?: {
|
||||||
targetLocale?: string,
|
targetLocale?: string;
|
||||||
routeLocale?: string,
|
routeLocale?: string;
|
||||||
showPrimaryLocale?: string,
|
showPrimaryLocale?: string;
|
||||||
query?: Record<string, unknown>
|
query?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
parameters?: Record<string, string>,
|
parameters?: Record<string, string>,
|
||||||
options?: {
|
options?: {
|
||||||
targetLocale?: string,
|
targetLocale?: string;
|
||||||
routeLocale?: string,
|
routeLocale?: string;
|
||||||
showPrimaryLocale?: string,
|
showPrimaryLocale?: string;
|
||||||
query?: Record<string, unknown>
|
query?: Record<string, unknown>;
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
): string
|
): string;
|
||||||
/** Adds new translations at runtime. */
|
/** Adds new translations at runtime. */
|
||||||
addTranslations(translations: Translations): this
|
addTranslations(translations: Translations): this;
|
||||||
/** Adds new translation formatters at runtime. */
|
/** Adds new translation formatters at runtime. */
|
||||||
addFormatters(translationFormatters: TranslationFormatters): this
|
addFormatters(translationFormatters: TranslationFormatters): this;
|
||||||
/** Adds new translation loading rules at runtime. */
|
/** Adds new translation loading rules at runtime. */
|
||||||
addTranslationLoadingRules(translationLoadingRules: TranslationLoadingRules): this
|
addTranslationLoadingRules(
|
||||||
|
translationLoadingRules: TranslationLoadingRules
|
||||||
|
): this;
|
||||||
/** Adds new route segment translations at runtime. */
|
/** Adds new route segment translations at runtime. */
|
||||||
addRoutes(routes: SegmentTranslations): this
|
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`. */
|
/** 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
|
extractRouteLocale(route: string): string | null;
|
||||||
/** Initializes astro-i18n on the server-side. */
|
/** Initializes astro-i18n on the server-side. */
|
||||||
initialize(config?: Partial<AstroI18nConfig> | string, formatters?: TranslationFormatters = {}): Promise<void>
|
initialize(
|
||||||
|
config?: Partial<AstroI18nConfig> | string,
|
||||||
|
formatters?: TranslationFormatters = {}
|
||||||
|
): Promise<void>;
|
||||||
/** Redirects the user to the given destination. */
|
/** Redirects the user to the given destination. */
|
||||||
redirect(destination: string | URL, status = 301)
|
redirect(destination: string | URL, status = 301);
|
||||||
}
|
}
|
||||||
export const astroI18n: AstroI18n
|
export const astroI18n: AstroI18n;
|
||||||
}
|
}
|
||||||
// ###< astro-i18n/type-generation ###
|
// ###< astro-i18n/type-generation ###
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
"pages.games": "Games | Alu",
|
"pages.games": "Games | Alu",
|
||||||
"pages.settings": "Settings | Alu",
|
"pages.settings": "Settings | Alu",
|
||||||
|
|
||||||
|
|
||||||
"nav.brand": "Alu",
|
"nav.brand": "Alu",
|
||||||
"nav.games": "Games",
|
"nav.games": "Games",
|
||||||
"nav.settings": "Settings",
|
"nav.settings": "Settings",
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import en from './en.json';
|
import en from "./en.json";
|
||||||
import jp from './jp.json';
|
import jp from "./jp.json";
|
||||||
|
|
||||||
export const defaultLang = 'en';
|
export const defaultLang = "en";
|
||||||
|
|
||||||
export const ui = {
|
export const ui = {
|
||||||
en,
|
en,
|
||||||
jp
|
jp,
|
||||||
};
|
};
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import { ui, defaultLang } from './ui';
|
import { ui, defaultLang } from "./ui";
|
||||||
|
|
||||||
export function getLangFromUrl(url: URL) {
|
export function getLangFromUrl(url: URL) {
|
||||||
// comma lol
|
// comma lol
|
||||||
const [, lang] = url.pathname.split('/');
|
const [, lang] = url.pathname.split("/");
|
||||||
if (lang in ui) return lang as keyof typeof ui;
|
if (lang in ui) return lang as keyof typeof ui;
|
||||||
return defaultLang;
|
return defaultLang;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTranslations(lang: keyof typeof ui) {
|
export function useTranslations(lang: keyof typeof ui) {
|
||||||
return function t(key: keyof typeof ui[typeof defaultLang]) {
|
return function t(key: keyof (typeof ui)[typeof defaultLang]) {
|
||||||
return ui[lang][key] || ui[defaultLang][key];
|
return ui[lang][key] || ui[defaultLang][key];
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
{
|
{
|
||||||
"extends": "astro/tsconfigs/strict"
|
"extends": "astro/tsconfigs/strict",
|
||||||
|
"compilerOptions": {
|
||||||
|
"verbatimModuleSyntax": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue