Skip to content

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.

Use defineConfig from the framework package you are configuring:

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],
});

The framework field is optional. Add it only when you need framework-specific behavior such as:

  • packages for replacing the framework macro package name
  • whitespace for rich-text Component Macro whitespace handling
  • runtimeWarnings for generated runtime diagnostics
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}" }],
framework: {
svelte: {
packages: ["@acme/i18n/macro"],
whitespace: "svelte",
runtimeWarnings: {
transContentOverride: "on",
},
},
},
extractors: [svelteExtractor],
});

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.

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:

lingui.config.ts
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.

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:

vite.config.ts
import { defineConfig } from "vite";
import linguiForSvelte from "lingui-for-svelte/unplugin/vite";
export default defineConfig({
plugins: [linguiForSvelte({ config: "./config/lingui.config.ts" })],
});
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" })],
});