--- title: Configuration description: Learn how to configure Lingui for your project --- # Configuration The following reference covers all supported configuration options in Lingui. To learn more about configuring Lingui, read the [Installation and Setup](/installation) guide. By default, Lingui looks for the configuration in the following locations: - `lingui.config.js` or `lingui.config.ts` file exporting a configuration object (recommended). You can also define the environment variable `LINGUI_CONFIG` with the path to your config file. In the case of TypeScript-based config you can use ESM format and _export default_. ## catalogs Default value: ```js [ { path: "/locale/{locale}/messages", include: [""], exclude: ["**/node_modules/**"], }, ]; ``` The `catalogs` configuration defines the location of message catalogs and specifies which files are included when the [`extract`](/ref/cli#extract) command scans for messages. - `path`: the directory where the message catalogs are located. It should not end with a slash and must not include a file extension, which depends on the [`format`](#format) configuration. The `{locale}` token will be replaced by the catalog's locale. - `include` and `exclude`: these patterns specify which files to include or exclude during the extraction process. They are passed to [minimatch](https://github.com/isaacs/minimatch) for pattern matching. - [``](#rootdir): represents the root directory of the project. It is replaced with the actual root directory when the configuration is loaded. By default, [``](#rootdir) represents the configuration file's location. The `path`, `include`, and `exclude` patterns are interpreted relative to the current process CWD (current working directory). The `{name}` token in the `path` will be replaced with the catalog name. Be sure to include the `{name}` pattern in the source path as well, as it acts like a `*` glob pattern: ```json { "catalogs": [ { "path": "/components/{name}/locale/{locale}", "include": ["/components/{name}/"] } ] } ``` #### Examples Let's assume we use `locales: ["en", "cs"]` and `format: "po"` in all examples. #### All catalogs in one directory ```json { "catalogs": [ { "path": "locales/{locale}" } ] } ``` ```bash locales/ ├── en.po └── cs.po ``` #### Catalogs in separate directories ```js { catalogs: [ { path: "locales/{locale}/messages", }, ]; } ``` ```bash {3,5} locales ├── en/ │ └── messages.po └── cs/ └── messages.po ``` #### Separate catalogs per component, placed inside component directory ```json { "catalogs": [ { "path": "components/{name}/locale/{locale}", "include": ["components/{name}/"] } ] } ``` ```shell {4,5,10,11} components/ ├── RegistrationForm/ │ ├── locale/ │ │ ├── en.po │ │ └── cs.po │ ├── RegistrationForm.test.js │ └── RegistrationForm.js └── LoginForm/ ├── locale/ │ ├── en.po │ └── cs.po ├── LoginForm.test.js └── LoginForm.js ``` #### Separate catalogs per component, placed inside shared directory ```json { "catalogs": [ { "path": "locale/{locale}/{name}", "include": ["components/{name}/"] } ] } ``` ```shell {4,5,7,8} . ├── locale/ │ ├── en/ │ │ ├── RegistrationForm.po │ │ └── LoginForm.po │ └── cs/ │ ├── RegistrationForm.po │ └── LoginForm.po └── components/ ├── RegistrationForm/ │ ├── RegistrationForm.test.js │ └── RegistrationForm.js └── LoginForm/ ├── LoginForm.test.js └── LoginForm.js ``` ## locales Default value: `[]` The locale tags used in the project. The [`extract`](/ref/cli#extract) and [`compile`](/ref/cli#compile) commands write a catalog for each locale specified. Each locale should be a valid [BCP-47 code](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html): ```json { "locales": ["en", "cs"] } ``` ## fallbackLocales Default value: `{}` Translations from `fallbackLocales` are used if the translation for the given locale is missing. It uses [CLDR Parent Locales](https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/parentLocales.json) by default, unless you override it with a `false` to use the default message or message ID instead: ```json { "fallbackLocales": false } ``` The `fallbackLocales` object allows to configure fallback locales for each locale instance: ```json { "fallbackLocales": { "en-US": ["en-GB", "en"], "es-MX": "es" } } ``` In this example, if any translation isn't found on `en-US`, then it will search on `en-GB`, after that if not found we'll search in `en`. it's also possible to configure a `default` fallback locale for all locales: ```json {5} { "fallbackLocales": { "en-US": ["en-GB", "en"], "es-MX": "es", "default": "en" } } ``` ## sourceLocale Default value: `""` `sourceLocale` specifies the default language of message IDs in your source files. The catalog for `sourceLocale` doesn't need actual translations since message IDs are used as-is by default. However, you can still override any message ID by providing a custom translation. The main difference between `sourceLocale` and [`fallbackLocales`](#fallbacklocales) is their purpose: `sourceLocale` defines the language used for message IDs, while `fallbackLocales` provides alternative translations when specific messages are missing for a particular locale. ## pseudoLocale Default value: `""` Locale used for pseudolocalization. For example, when you set `pseudoLocale: "en"`, all messages in the `en` catalog will be pseudo-localized. The locale must be included in the `locales` config. It can be provided as a string (deprecated), an object to additionally configure the underlying [`pseudolocale`](https://github.com/MartinCerny-awin/pseudolocale) library, or an array of objects to define multiple pseudolocales with different parameters. The token delimiter is managed internally by Lingui (to keep HTML tags, ICU macros and variables intact) and therefore cannot be configured. :::caution The string form (`pseudoLocale: "pseudo"`) is deprecated and will be removed in a future major release. Use the object form (`pseudoLocale: { locale: "pseudo" }`) or an array of objects instead. ::: | Option | Type | Default | Description | | ----------------- | --------- | ----------- | --------------------------------------------------------------------------------------------------- | | `locale` | `string` | — | Locale used for pseudolocalization (required in the object form) | | `prepend` | `string` | `""` | String prepended to the beginning of every pseudo-localized message | | `append` | `string` | `""` | String appended to the end of every pseudo-localized message | | `extend` | `number` | `0` | Extends the width of the string by the given percentage (e.g. `0.3` adds 30%) | | `extendCharacter` | `string` | `" "` | Character used to pad messages when `extend` is set | | `override` | `string` | `undefined` | Replaces every (non-token) character with the given one. Handy to quickly spot untranslated strings | | `rightToLeft` | `boolean` | `false` | Emulates right-to-left languages by inserting Unicode RTL override marks | ```ts title="lingui.config.{js,ts}" import { defineConfig } from "@lingui/cli"; // Simple form export default defineConfig({ locales: ["en", "pseudo"], sourceLocale: "en", pseudoLocale: "pseudo", catalogs: [], }); // Extended form export default defineConfig({ locales: ["en", "pseudo"], sourceLocale: "en", pseudoLocale: { locale: "pseudo", prepend: "⟦ ", append: " ⟧", extend: 0.4, extendCharacter: ".", }, catalogs: [], }); // Multiple pseudolocales export default defineConfig({ locales: ["en", "pseudo-en", "pseudo-ar"], sourceLocale: "en", pseudoLocale: [ { locale: "pseudo-en", prepend: "⟦ ", append: " ⟧", extend: 0.4 }, { locale: "pseudo-ar", rightToLeft: true }, ], catalogs: [], }); ``` Read more about [Pseudolocalization](/guides/pseudolocalization). ## catalogsMergePath Default value: `""` Define the path where translated catalogs are merged into a single file per locale during the [`compile`](/ref/cli#compile) process. #### Example Let's assume we have [separate catalogs per component, placed inside shared directory](#separate-catalogs-per-component-placed-inside-shared-directory). Using the `catalogsMergePath`, separate catalogs can be merged into a single file: ```diff { "catalogs": [ { "path": "/locale/{locale}/{name}", "include": ["components/{name}/"] } ], + "catalogsMergePath": "locales/{locale}" } ``` ```diff . ├── locale/ │ ├── en/ │ │ ├── RegistrationForm.po - │ │ ├── RegistrationForm.js │ │ ├── LoginForm.po - │ │ └── LoginForm.js │ └── cs/ │ ├── RegistrationForm.po - │ ├── RegistrationForm.js │ ├── LoginForm.po - │ └── LoginForm.js + ├── locales/ + │ ├── en.js + │ └── cs.js └── components/ ├── RegistrationForm/ │ ├── RegistrationForm.test.js │ └── RegistrationForm.js └── LoginForm/ ├── LoginForm.test.js └── LoginForm.js ``` ## compileNamespace Default value: `cjs` Specify namespace for exporting compiled messages. See [`compile`](/ref/cli#compile) command. #### cjs Use CommonJS exports: ```js /* eslint-disable */module.exports={messages: {"..."}} ``` #### es Use ES6 named export: ```js /* eslint-disable */export const messages = {"..."} ``` #### ts Use ES6 named export + `.ts` file with an additional `{compiledFile}.d.ts` file: ```js /* eslint-disable */export const messages = {"..."} ``` ```ts import { Messages } from "@lingui/core"; declare const messages: Messages; export { messages }; ``` #### json ```json {"messages": {"..."}} ``` #### (window\|global).(.\*) Assign compiled messages to `window` or `global` object. Specify an identifier after `window` or `global` to which the catalog is assigned, e.g. `window.i18n`. For example, setting [`compileNamespace`](#compilenamespace) to `window.i18n` creates file similar to this: ```js /* eslint-disable */window.i18n={messages: {"..."}} ``` ## descriptorFields Default value: `auto` Controls which descriptor fields the macro compiler preserves in the transformed code. Macro plugins read this when they are not given their own `descriptorFields` option, so a single setting here applies to every transpiler instead of having to be repeated in each plugin's options. - `auto`: In production (`NODE_ENV === "production"`), keeps only the `id`. Otherwise, behaves like `all`. - `all`: Keeps every field: `id`, `message`, `context`, and `comment`. Used by the Lingui CLI during extraction. - `id-only`: Strips everything except the `id`. Most optimized for production. - `message`: Keeps `id`, `message`, and `context` (but not `comment`). Use when you need runtime access to message and context. ```js export default { locales: ["en"], descriptorFields: "id-only", }; ``` ## extractorParserOptions :::note This option is deprecated. If you want to change parser options, pass it directly to extractor implementation ```ts import { createBabelExtractor } from "@lingui/cli/api/extractors/babel"; export default { // [...] extractors: [createBabelExtractor({ parserOptions: { tsExperimentalDecorators: true } })], }; ``` ::: Specify additional options used to parse source files when extracting messages. ```json { "extractorParserOptions": { "tsExperimentalDecorators": false, "flow": false } } ``` #### tsExperimentalDecorators Default value: `false` By default, standard decorators (Stage3) are applied to TS files. Enable this if you want to use TypeScript's experimental decorators. #### flow Default value: `false` Lingui does not ship with [Flow](https://flow.org/) typing. However, you can use Lingui in projects written in Flow. Enable this option to tell the extractor that your sources use Flow syntax. ## compilerBabelOptions Default value: ```json { "minified": true, "jsescOption": { "minimal": true } } ``` Specify extra babel options used to generate files when messages are being compiled. We use internally `@babel/generator` that accepts some configuration for generating code with/out ASCII characters. These are all the options available: [jsesc](https://github.com/mathiasbynens/jsesc). ```json { "compilerBabelOptions": { "jsescOption": { "minimal": false } } } ``` This example configuration will compile with escaped ASCII characters ([jsesc#minimal](https://github.com/mathiasbynens/jsesc#minimal)). ## format Default value: `po` Message catalog format. The `po` formatter is used by default. Other formatters are available as separate packages. ```js title="lingui.config.{js,ts}" import { defineConfig } from "@lingui/cli"; import { formatter } from "@lingui/format-po"; export default defineConfig({ // [...] format: formatter({ lineNumbers: false }), }); ``` Read more about available formatters in [Catalog Formats](/ref/catalog-formats) or create your own [Custom Formatter](/guides/custom-formatter). ## orderBy Default value: `message` Order of messages in catalog: #### message Sort by source message. #### messageId Sort by the message ID, `js-lingui-id` will be used if no custom id provided. #### origin Sort by message origin (e.g. `App.js:3`) #### Custom Function You can provide custom sort function: ```ts export default defineConfig({ // [...] orderBy: (a, b) => { /* `a` and `b` has a shape * { * messageId: string * entry: ExtractedMessageType * } */ const aIsGlobal = a.messageId.startsWith("global."); const bIsGlobal = b.messageId.startsWith("global."); // Put `global.*` entries first if (aIsGlobal && !bIsGlobal) return -1; if (!aIsGlobal && bIsGlobal) return 1; // Otherwise, sort alphabetically return a.messageId.localeCompare(b.messageId); }, }); ``` ## rootDir Default: The root of the directory containing your Lingui configuration file or the `package.json`. This is the directory where the Lingui CLI scans for messages in your source files during the extraction process. Note that using `` as a string token in any other path-based config settings will refer back to this value. ## runtimeConfigModule Default value: `["@lingui/core", "i18n"]` This setting specifies the module path for the exported `i18n` object. The first value in the array is the module path, and the second is the name of the import. This configuration is essential for [macros](/ref/macro) that need to reference the global `i18n` object. You only need to set this value if you use custom object created using [`setupI18n`](/ref/core#setupi18n): For example, if you have a custom module that exports the `i18n` object: ```jsx import { i18n } from "./custom-i18n-config"; ``` ```json { "runtimeConfigModule": ["./custom-i18n-config", "i18n"] } ``` You may use a different named export: ```jsx import { myI18n } from "./custom-i18n-config"; ``` ```json { "runtimeConfigModule": ["./custom-i18n-config", "myI18n"] } ``` In more advanced scenarios, you may need to change the module from which the [`Trans`](/ref/macro#trans) or [`useLingui`](/ref/macro#uselingui) macros are imported: ```jsx import { Trans, useLingui } from "./custom-config"; ``` ```json { "runtimeConfigModule": { "Trans": ["./custom-config", "Trans"], "useLingui": ["./custom-config", "useLingui"] } } ``` ## extractors Default value: `[babel]` Extractors it's the way to customize which extractor you want for your codebase. ```js { "extractors": [ myCustomExtractor, ] } ``` See the [Custom Extractor](/guides/custom-extractor) guide for instructions on creating your own extractor, or use the [native extractor](/guides/custom-extractor#native-extractor) to extract without Babel. ## macro.corePackage Default value: `["@lingui/macro", "@lingui/core/macro"]` Allows customizing the Core Macro package name that the Lingui macro detects. ```js // lingui.config { macro: { corePackage: ["@lingui/myMacro"], } } // app.tsx import { msg } from "@lingui/myMacro"; msg`Hello`; // <-- would be correctly picked up by macro ``` This setting mostly useful for external framework integrations. ## macro.jsxPackage Default value: `["@lingui/macro", "@lingui/react/macro"]` Allows customizing the JSX Macro package name that the Lingui macro detects. ```jsx // lingui.config { macro: { jsxPackage: ["@lingui/myMacro"], } } // app.tsx import { Trans } from "@lingui/myMacro"; Hello; // <-- would be correctly picked up by macro ``` This setting mostly useful for external framework integrations. ## macro.jsxPlaceholderAttribute Default value: `undefined` The JSX attribute name used to assign explicit placeholder names to JSX elements inside ``. When set, the macro reads this attribute from JSX elements to use as the placeholder name in the message string, and strips the attribute from the output. ```jsx // lingui.config { macro: { jsxPlaceholderAttribute: "_t", } } // source Click here ; // extracted message: "Click here" ``` Without this option, JSX elements are assigned auto-generated numeric placeholders (e.g. `<0>here`), which are less readable for translators and may cause issues if the element order changes. :::note TypeScript Usage In React/TypeScript projects, you need to declare the custom attribute so that TypeScript doesn't report an error. Add the following to a `.d.ts` file included in your project: ```ts import "react"; declare module "react" { interface Attributes { _t?: string; // replace with your `jsxPlaceholderAttribute` value } } ``` ::: ## macro.jsxPlaceholderDefaults Default value: `undefined` A mapping of JSX element tag names to default placeholder names. When a JSX element inside `` matches a key in this map and does not have an explicit placeholder attribute (see [`macro.jsxPlaceholderAttribute`](#macrojsxplaceholderattribute)), the corresponding value is used as the placeholder name. ```jsx // lingui.config { macro: { jsxPlaceholderAttribute: "_t", jsxPlaceholderDefaults: { a: "link", em: "emphasis", strong: "bold", }, } } // source Click here and this ; // extracted message: "Click here and this" ``` Explicit attributes (via `jsxPlaceholderAttribute`) take priority over defaults. :::caution One Name per Distinct Element A placeholder name can be used only once per message. If two elements in the same `` resolve to the same name but differ in tag or props, for example two `` elements with different `href` values both mapped to `link`, the macro throws an error instead of numbering them (``, ``). Give at least one of them an explicit name via `jsxPlaceholderAttribute`: ```jsx Read the{" "} docs {" "} or the{" "} FAQ . // extracted message: "Read the docs or the FAQ." ``` Identical elements, such as two `
` with no props, share a single placeholder without error. ::: See [Translator-friendly Messages](/guides/translator-friendly-messages#name-your-tags) for when and why to name tags. :::tip Enforce Named Placeholders with ESLint You can enforce that all JSX tags in `` have named placeholders across your codebase using the Lingui [ESLint Plugin](/ref/eslint-plugin) rule [`no-unnamed-tag-placeholders`](https://github.com/lingui/eslint-plugin/blob/main/docs/rules/no-unnamed-tag-placeholders.md). ::: ## macro.idPrefixLeader Default value: `undefined` If defined, the `/* lingui-set idPrefix="..." */`) directive will only prepend `idPrefix` to explicit IDs that start with this leader string. This allows you to selectively apply prefixes to specific IDs while leaving others untouched. The leader string is **kept** in the final ID. ```js // lingui.config export default { macro: { idPrefixLeader: ".", }, }; ``` ```jsx // source import { Trans } from "@lingui/react/macro" // lingui-set idPrefix="myPrefix" With prefix // id="myPrefix.withPrefix" Unprefixed // id="unprefixed" ``` ## macro.jsxRuntime Default value: `undefined` Controls which JSX runtime semantics the Lingui JSX macro emit. Accepts `"react"`, `"solid"` or `"vue"`. ```ts // lingui.config { macro: { jsxRuntime: "solid"; } } ``` ## experimental.runtimeMacro Default value: `false` :::caution Experimental This option is experimental and may change in a minor release. ::: Extracts messages defined with the [runtime macro](/ref/core#runtime-macro) (imports from `@lingui/core/runtime-macro`) to your catalogs. ```js // lingui.config { experimental: { runtimeMacro: true, } } ```