Add internationalization support with astro-i18next integration
- Implemented astro-i18next for multi-language support, including English, Dutch, and Italian. - Configured default locale and language fallback settings. - Defined routes for localized content in the configuration. - Updated package.json and package-lock.json to include new dependencies for i18next and related plugins.
This commit is contained in:
411
node_modules/astro-i18next/dist/cli/index.js
generated
vendored
Executable file
411
node_modules/astro-i18next/dist/cli/index.js
generated
vendored
Executable file
File diff suppressed because one or more lines are too long
9
node_modules/astro-i18next/dist/index.js
generated
vendored
Normal file
9
node_modules/astro-i18next/dist/index.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
13
node_modules/astro-i18next/dist/types/cli/generate.d.ts
generated
vendored
Normal file
13
node_modules/astro-i18next/dist/types/cli/generate.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { AstroI18nextConfig } from "../types";
|
||||
import { FileToGenerate } from "./utils";
|
||||
/**
|
||||
* Reads all files inside inputPath
|
||||
*
|
||||
* @param inputPath
|
||||
* @param locales
|
||||
* @param outputPath
|
||||
*/
|
||||
export declare const generate: (inputPath: string, defaultLocale: AstroI18nextConfig["defaultLocale"], locales: AstroI18nextConfig["locales"], showDefaultLocale?: boolean, flatRoutes?: AstroI18nextConfig["flatRoutes"], outputPath?: string) => {
|
||||
filesToGenerate: FileToGenerate[];
|
||||
timeToProcess: number;
|
||||
};
|
2
node_modules/astro-i18next/dist/types/cli/index.d.ts
generated
vendored
Normal file
2
node_modules/astro-i18next/dist/types/cli/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
export {};
|
4
node_modules/astro-i18next/dist/types/cli/middlewares.d.ts
generated
vendored
Normal file
4
node_modules/astro-i18next/dist/types/cli/middlewares.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { MiddlewareFunction } from "yargs";
|
||||
import { GenerateArgs, GlobalArgs } from "./types";
|
||||
export declare const loadConfig: MiddlewareFunction<GlobalArgs & GenerateArgs>;
|
||||
export declare const normalizePath: MiddlewareFunction<GlobalArgs & GenerateArgs>;
|
7
node_modules/astro-i18next/dist/types/cli/transformer.d.ts
generated
vendored
Normal file
7
node_modules/astro-i18next/dist/types/cli/transformer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import ts from "typescript";
|
||||
/**
|
||||
* Traverse ts' AST to inject i18next's language switch
|
||||
* @param context
|
||||
* @returns
|
||||
*/
|
||||
export declare const transformer: ts.TransformerFactory<ts.SourceFile>;
|
9
node_modules/astro-i18next/dist/types/cli/types.d.ts
generated
vendored
Normal file
9
node_modules/astro-i18next/dist/types/cli/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { AstroI18nextConfig } from "../types";
|
||||
export interface GlobalArgs {
|
||||
verbose: boolean;
|
||||
}
|
||||
export interface GenerateArgs {
|
||||
path: string;
|
||||
config: AstroI18nextConfig;
|
||||
output: string;
|
||||
}
|
40
node_modules/astro-i18next/dist/types/cli/utils.d.ts
generated
vendored
Normal file
40
node_modules/astro-i18next/dist/types/cli/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { PathsOutput } from "fdir";
|
||||
import ts from "typescript";
|
||||
import { AstroI18nextConfig } from "../types";
|
||||
export interface FileToGenerate {
|
||||
path: string;
|
||||
source: string;
|
||||
}
|
||||
export declare const doesStringIncludeFrontmatter: (source: string) => boolean;
|
||||
export declare const extractFrontmatterFromAstroSource: (source: string) => string;
|
||||
export declare const overwriteAstroFrontmatter: (source: string, frontmatter: string) => string;
|
||||
export declare const addDepthToRelativePath: (relativePath: string, depth?: number) => string;
|
||||
/**
|
||||
* file is hidden if its name or any of its parent folders start with an underscore
|
||||
*/
|
||||
export declare const isFileHidden: (filepath: string) => boolean;
|
||||
export declare const resolveRelativePathsLevel: (fileContents: string, fileDepth: number) => string;
|
||||
/**
|
||||
* parse frontmatter using typescript compiler
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
export declare const parseFrontmatter: (source: string) => ts.SourceFile;
|
||||
export declare const generateLocalizedFrontmatter: (tsNode: ts.SourceFile, locale: string) => string;
|
||||
/**
|
||||
* Crawls pages directory and returns all Astro pages
|
||||
* except for locale folders and excluded pages / directories (starting with underscore).
|
||||
* (https://docs.astro.build/en/core-concepts/routing/#excluding-pages)
|
||||
*
|
||||
* @param pagesDirectoryPath
|
||||
* @param childDirToCrawl will make the function crawl inside the given
|
||||
* `childDirToCrawl` (doesn't take paths, only dirname).
|
||||
*/
|
||||
export declare const getAstroPagesFullPaths: (pagesDirectoryPath: string, childDirToCrawl?: AstroI18nextConfig["defaultLocale"] | undefined, locales?: AstroI18nextConfig["locales"]) => PathsOutput;
|
||||
export declare const createFiles: (filesToGenerate: FileToGenerate[]) => void;
|
||||
/**
|
||||
* Resolves the right translated path based on
|
||||
* a given `astroFilePath` and a locale,
|
||||
* with the `routeTranslations` mapping.
|
||||
*/
|
||||
export declare const resolveTranslatedAstroPath: (astroFilePath: string, locale?: string | null, basePath?: string, flatRoutes?: AstroI18nextConfig["flatRoutes"]) => string;
|
11
node_modules/astro-i18next/dist/types/config.d.ts
generated
vendored
Normal file
11
node_modules/astro-i18next/dist/types/config.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { AstroI18nextConfig, AstroI18nextGlobal } from "./types";
|
||||
export declare const AstroI18next: AstroI18nextGlobal;
|
||||
export declare const setAstroI18nextConfig: (config: AstroI18nextConfig) => void;
|
||||
export declare const astroI18nextConfigBuilder: (config: AstroI18nextConfig) => AstroI18nextConfig;
|
||||
/**
|
||||
* This will create a mapping of translated routes to search them easily.
|
||||
*
|
||||
* TODO: render all routes mappings in here (even those not translated),
|
||||
* this will help simplify utility functions logic
|
||||
*/
|
||||
export declare const flattenRoutes: (routes: AstroI18nextConfig["routes"], previous?: string[], translatedPrevious?: string[], prevResult?: AstroI18nextConfig["flatRoutes"]) => AstroI18nextConfig["flatRoutes"];
|
8
node_modules/astro-i18next/dist/types/index.d.ts
generated
vendored
Normal file
8
node_modules/astro-i18next/dist/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { AstroIntegration } from "astro";
|
||||
import { AstroI18nextConfig, AstroI18nextOptions } from "./types";
|
||||
declare const _default: (options?: AstroI18nextOptions) => AstroIntegration;
|
||||
export default _default;
|
||||
export declare function initAstroI18next(config: AstroI18nextConfig): void;
|
||||
export { AstroI18next } from "./config";
|
||||
export { createReferenceStringFromHTML, detectLocaleFromPath, interpolate, localizePath, localizeUrl, } from "./utils";
|
||||
export { AstroI18nextConfig, AstroI18nextOptions } from "./types";
|
116
node_modules/astro-i18next/dist/types/types.d.ts
generated
vendored
Normal file
116
node_modules/astro-i18next/dist/types/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
import { InitOptions } from "i18next";
|
||||
export interface AstroI18nextGlobal {
|
||||
config: AstroI18nextConfig;
|
||||
}
|
||||
export interface AstroI18nextOptions {
|
||||
/**
|
||||
* Path to your astro-i18next config file
|
||||
*
|
||||
* @default 'astro-i18next.config.js'
|
||||
*/
|
||||
configPath?: string;
|
||||
}
|
||||
export interface Routes {
|
||||
[segment: string]: string | Record<string, string | Routes>;
|
||||
}
|
||||
export interface Plugins {
|
||||
[importName: string]: string | null;
|
||||
}
|
||||
export interface AstroI18nextConfig {
|
||||
/**
|
||||
* The default locale for your website.
|
||||
*
|
||||
* @default "cimode"
|
||||
*/
|
||||
defaultLocale: string;
|
||||
/**
|
||||
* The locales that are supported by your website.
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
locales: string[];
|
||||
/**
|
||||
* String or array of namespaces to load
|
||||
*
|
||||
* @default "translation"
|
||||
*/
|
||||
namespaces?: string | string[];
|
||||
/**
|
||||
* Default namespace used if not passed to the translation function
|
||||
*
|
||||
* @default "translation"
|
||||
*/
|
||||
defaultNamespace?: string;
|
||||
/**
|
||||
* Load i18next on server side only, client side only or both.
|
||||
*
|
||||
* @default ["server"]
|
||||
*/
|
||||
load?: ("server" | "client")[];
|
||||
/**
|
||||
* Set base path for i18next resources.
|
||||
*
|
||||
* @default "/locales"
|
||||
*/
|
||||
resourcesBasePath?: string;
|
||||
/**
|
||||
* i18next server side config. See https://www.i18next.com/overview/configuration-options
|
||||
*/
|
||||
i18nextServer?: InitOptions;
|
||||
/**
|
||||
* i18next client side config. See https://www.i18next.com/overview/configuration-options
|
||||
*/
|
||||
i18nextClient?: InitOptions;
|
||||
/**
|
||||
* The translations for your routes.
|
||||
*
|
||||
* @default {}
|
||||
*/
|
||||
routes?: Routes;
|
||||
/**
|
||||
* Generated mappings based on the routes
|
||||
*
|
||||
* @default {}
|
||||
*/
|
||||
readonly flatRoutes?: Record<string, string>;
|
||||
/**
|
||||
* The display behaviour for the URL locale.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
showDefaultLocale?: boolean;
|
||||
/**
|
||||
* i18next server side plugins. See https://www.i18next.com/overview/plugins-and-utils
|
||||
*
|
||||
* Include the plugins with the key being the import name and the value being the plugin name.
|
||||
*
|
||||
* Eg.:
|
||||
* ```
|
||||
* {
|
||||
* "Backend": "i18next-fs-backend",
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
i18nextServerPlugins?: Plugins;
|
||||
/**
|
||||
* i18next client side plugins. See https://www.i18next.com/overview/plugins-and-utils
|
||||
*
|
||||
* Include the plugins with the key being the import name and the value being the plugin name.
|
||||
*
|
||||
* Eg.:
|
||||
* ```
|
||||
* {
|
||||
* "{initReactI18next}": "react-i18next",
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
i18nextClientPlugins?: Plugins;
|
||||
/**
|
||||
* Set the route matching behavior of the dev server. Choose from the following options:
|
||||
*
|
||||
* 'always' - Only match URLs that include a trailing slash (ex: "/foo/")
|
||||
* 'never' - Never match URLs that include a trailing slash (ex: "/foo")
|
||||
* 'ignore' - Match URLs regardless of whether a trailing "/" exists
|
||||
*/
|
||||
trailingSlash?: "always" | "never" | "ignore";
|
||||
}
|
35
node_modules/astro-i18next/dist/types/utils.d.ts
generated
vendored
Normal file
35
node_modules/astro-i18next/dist/types/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/// <reference types="node" />
|
||||
import load from "@proload/core";
|
||||
import { AstroI18nextConfig } from "./types";
|
||||
/**
|
||||
* Adapted from astro's tailwind integration:
|
||||
* https://github.com/withastro/astro/tree/main/packages/integrations/tailwind
|
||||
*/
|
||||
export declare const getUserConfig: (root: URL, configPath?: string) => Promise<load.Config<AstroI18nextConfig>>;
|
||||
/**
|
||||
* Moves the default locale in the first index
|
||||
*/
|
||||
export declare const moveDefaultLocaleToFirstIndex: (locales: string[], baseLocale: string) => void;
|
||||
/**
|
||||
* Interpolates a localized string (loaded with the i18nKey) to a given reference string.
|
||||
*/
|
||||
export declare const interpolate: (i18nKey: string, referenceString: string, namespace?: string | null) => string;
|
||||
/**
|
||||
* Creates a reference string from an HTML string. The reverse of interpolate(), for use
|
||||
* with <Trans> when not explicitly setting a key
|
||||
*/
|
||||
export declare const createReferenceStringFromHTML: (html: string) => string;
|
||||
export declare const handleTrailingSlash: (path: string, trailingSlash: AstroI18nextConfig["trailingSlash"]) => string;
|
||||
/**
|
||||
* Injects the given locale to a path
|
||||
*/
|
||||
export declare const localizePath: (path?: string, locale?: string | null, base?: string) => string;
|
||||
/**
|
||||
* Injects the given locale to a url
|
||||
*/
|
||||
export declare const localizeUrl: (url: string, locale?: string | null, base?: string) => string;
|
||||
/**
|
||||
* Returns the locale detected from a given path
|
||||
*/
|
||||
export declare const detectLocaleFromPath: (path: string) => string;
|
||||
export declare const deeplyStringifyObject: (obj: object | Array<any>) => string;
|
Reference in New Issue
Block a user