Framework Config
lingui-for-svelte and lingui-for-astro can read framework-specific options from the same
lingui.config.ts file that Lingui already uses for locales, catalogs, and extractors.
Start with the package helper
Section titled “Start with the package helper”Use defineConfig from the framework package you are configuring:
import { defineConfig } from "lingui-for-svelte/config";import { svelteExtractor } from "lingui-for-svelte/extractor";
export default defineConfig({ locales: ["en", "ja"], sourceLocale: "en", catalogs: [{ path: "src/lib/i18n/locales/{locale}" }], extractors: [svelteExtractor],});import { defineConfig } from "lingui-for-astro/config";import { astroExtractor } from "lingui-for-astro/extractor";
export default defineConfig({ locales: ["en", "ja"], sourceLocale: "en", catalogs: [{ path: "src/lib/i18n/locales/{locale}" }], extractors: [astroExtractor],});Add framework only when needed
Section titled “Add framework only when needed”The framework field is optional. Add it only when you need framework-specific behavior such as:
packagesfor replacing the framework macro package namewhitespacefor rich-text Component Macro whitespace handlingruntimeWarningsfor generated runtime diagnostics
import { defineConfig } from "lingui-for-svelte/config";import { svelteExtractor } from "lingui-for-svelte/extractor";
export default defineConfig({ locales: ["en", "ja"], sourceLocale: "en", catalogs: [{ path: "src/lib/i18n/locales/{locale}" }], framework: { svelte: { packages: ["@acme/i18n/macro"], whitespace: "svelte", runtimeWarnings: { transContentOverride: "on", }, }, }, extractors: [svelteExtractor],});import { defineConfig } from "lingui-for-astro/config";import { astroExtractor } from "lingui-for-astro/extractor";
export default defineConfig({ locales: ["en", "ja"], sourceLocale: "en", catalogs: [{ path: "src/lib/i18n/locales/{locale}" }], framework: { astro: { packages: ["@acme/i18n/macro"], whitespace: "astro", runtimeWarnings: { transContentOverride: "on", }, }, }, extractors: [astroExtractor],});The build transform and extractor both load this config. For example, if whitespace is defined
under framework.svelte, the Svelte Vite plugin and svelteExtractor read the same value.
When packages is set, it replaces the default framework macro package name rather than adding to
it. Include the default package name explicitly if the project still imports it.
Mixed framework projects
Section titled “Mixed framework projects”The available keys under framework are registered through TypeScript module augmentation.
Importing a package’s config or extractor entrypoint enables that package’s key.
If one config file covers both Svelte and Astro, import both packages:
import { defineConfig } from "lingui-for-astro/config";import { astroExtractor } from "lingui-for-astro/extractor";import { svelteExtractor } from "lingui-for-svelte/extractor";
export default defineConfig({ locales: ["en", "ja"], sourceLocale: "en", catalogs: [{ path: "src/lib/i18n/locales/{locale}" }], framework: { astro: { whitespace: "astro", }, svelte: { whitespace: "svelte", }, }, extractors: [astroExtractor, svelteExtractor],});In this example, lingui-for-astro/config provides defineConfig and the Astro framework key.
Importing lingui-for-svelte/extractor also augments the config registry, so framework.svelte is
typed in the same file.
Explicit config sources
Section titled “Explicit config sources”With the default lingui.config.* file, framework plugins and extractors discover the config
automatically.
If your project uses a non-standard config path or an inline config object, pass it with the
config option:
import { defineConfig } from "vite";import linguiForSvelte from "lingui-for-svelte/unplugin/vite";
export default defineConfig({ plugins: [linguiForSvelte({ config: "./config/lingui.config.ts" })],});import { defineConfig } from "lingui-for-svelte/config";import { svelteExtractor } from "lingui-for-svelte/extractor";
export default defineConfig({ locales: ["en", "ja"], sourceLocale: "en", catalogs: [{ path: "src/lib/i18n/locales/{locale}" }], extractors: [svelteExtractor({ config: "./config/lingui.config.ts" })],});