Home / File/ i18n.ts — astro Source File

i18n.ts — astro Source File

Architecture documentation for i18n.ts, a typescript file in the astro codebase. 11 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 11 imports 11 functions

Entity Profile

Dependency Diagram

graph LR
  113cc879_696f_ac71_941f_004a5fb4282c["i18n.ts"]
  e9dfb380_680c_13fb_c9d4_a88e777254bd["../core/app/common.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> e9dfb380_680c_13fb_c9d4_a88e777254bd
  97dbad4f_4a90_206c_6e29_6a54c12480f2["../core/app/index.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> 97dbad4f_4a90_206c_6e29_6a54c12480f2
  a4f2698c_5256_262a_ba7c_f72b51878d10["../core/app/types.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> a4f2698c_5256_262a_ba7c_f72b51878d10
  8df634da_0f30_1e1f_1314_2439b0c9baab["../core/errors/errors-data.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> 8df634da_0f30_1e1f_1314_2439b0c9baab
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  fe669073_2e4e_f283_db9d_18a6d7df3f04["../i18n/index.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> fe669073_2e4e_f283_db9d_18a6d7df3f04
  135a8084_d596_67c2_9209_cca6693604e6["../types/public/common.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> 135a8084_d596_67c2_9209_cca6693604e6
  c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> c32d12e2_d85e_28c0_eea7_9b29629857e0
  28857b9f_4720_3f29_4abb_a7eec34dcca5["../types/public/context.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> 28857b9f_4720_3f29_4abb_a7eec34dcca5
  baa53824_73a3_1e03_2043_4d0c058ecca5["../types/public/index.js"]
  113cc879_696f_ac71_941f_004a5fb4282c --> baa53824_73a3_1e03_2043_4d0c058ecca5
  5447f408_177f_be13_5466_8a8f2a8b1b99["server"]
  113cc879_696f_ac71_941f_004a5fb4282c --> 5447f408_177f_be13_5466_8a8f2a8b1b99
  style 113cc879_696f_ac71_941f_004a5fb4282c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// @ts-expect-error This is an internal module
import * as config from 'astro:config/server';
import { toFallbackType } from '../core/app/common.js';
import { toRoutingStrategy } from '../core/app/index.js';
import type { SSRManifest } from '../core/app/types.js';
import {
	IncorrectStrategyForI18n,
	InvalidI18nMiddlewareConfiguration,
} from '../core/errors/errors-data.js';
import { AstroError } from '../core/errors/index.js';
import type { RedirectToFallback } from '../i18n/index.js';
import * as I18nInternals from '../i18n/index.js';
import type { MiddlewareHandler } from '../types/public/common.js';
import type { AstroConfig, ValidRedirectStatus } from '../types/public/config.js';
import type { APIContext } from '../types/public/context.js';
import type { ServerDeserializedManifest } from '../types/public/index.js';

const { trailingSlash, site, i18n, build } = config as ServerDeserializedManifest;
const { format } = build;
const isBuild = import.meta.env.PROD;
const { defaultLocale, locales, domains, fallback, routing } = i18n!;
const base = import.meta.env.BASE_URL;

let strategy = toRoutingStrategy(routing, domains);
let fallbackType = toFallbackType(routing);

export type GetLocaleOptions = I18nInternals.GetLocaleOptions;

const noop = (method: string) =>
	function () {
		throw new AstroError({
			...IncorrectStrategyForI18n,
			message: IncorrectStrategyForI18n.message(method),
		});
	};

/**
 * @param locale A locale
 * @param path An optional path to add after the `locale`.
 * @param options Customise the generated path
 *
 * Returns a _relative_ path with passed locale.
 *
 * ## Errors
 *
 * Throws an error if the locale doesn't exist in the list of locales defined in the configuration.
 *
 * ## Examples
 *
 * ```js
 * import { getRelativeLocaleUrl } from "astro:i18n";
 * getRelativeLocaleUrl("es"); // /es
 * getRelativeLocaleUrl("es", "getting-started"); // /es/getting-started
 * getRelativeLocaleUrl("es_US", "getting-started", { prependWith: "blog" }); // /blog/es-us/getting-started
 * getRelativeLocaleUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // /blog/es_US/getting-started
 * ```
 */
export const getRelativeLocaleUrl = (locale: string, path?: string, options?: GetLocaleOptions) =>
	I18nInternals.getLocaleRelativeUrl({
		locale,
// ... (440 more lines)

Domain

Subdomains

Dependencies

  • ../core/app/common.js
  • ../core/app/index.js
  • ../core/app/types.js
  • ../core/errors/errors-data.js
  • ../core/errors/index.js
  • ../i18n/index.js
  • ../types/public/common.js
  • ../types/public/config.js
  • ../types/public/context.js
  • ../types/public/index.js
  • server

Frequently Asked Questions

What does i18n.ts do?
i18n.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in i18n.ts?
i18n.ts defines 11 function(s): MiddlewareHandler, context, getAbsoluteLocaleUrl, getAbsoluteLocaleUrlList, getLocaleByPath, getPathByLocale, getRelativeLocaleUrl, getRelativeLocaleUrlList, middleware, noop, and 1 more.
What does i18n.ts depend on?
i18n.ts imports 11 module(s): ../core/app/common.js, ../core/app/index.js, ../core/app/types.js, ../core/errors/errors-data.js, ../core/errors/index.js, ../i18n/index.js, ../types/public/common.js, ../types/public/config.js, and 3 more.
Where is i18n.ts in the architecture?
i18n.ts is located at packages/astro/src/virtual-modules/i18n.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/virtual-modules).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free