Lingui Configuration

Configuration is read from 3 different sources (the first found wins):

  • from lingui section in package.json

  • from .linguirc

  • from lingui.config.js

<rootDir> is replaced with base directory of the configuration file.

Default config:

{
  "lingui": {
    "compileNamespace": "cjs",
    "extractBabelOptions": {},
    "fallbackLocale": "",
    "sourceLocale": "",
    "localeDir": "<rootDir>/locale",
    "srcPathDirs": [
        "<rootDir>"
    ],
    "srcPathIgnorePatterns": [
        "/node_modules/"
    ],
    "format": "lingui",
  }
}

compileNamespace

Default: cjs

Specify namespace for exporting compiled messages. See compile command.

cjs

Use CommonJS exports:

/* eslint-disable */module.exports={languageData: {"..."}, messages: {"..."}}

es

Use ES6 default export:

/* eslint-disable */export default{languageData: {"..."}, 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 to window.i18n creates file similar to this:

/* eslint-disable */window.i18n={languageData: {"..."}, messages: {"..."}}

extractBabelOptions

Default: {}

Specify extra babel options used to parse source files when messages are being extracted. Not required in most cases.

{
  "extractBabelOptions": {
    "plugins": ["@babel/plugin-syntax-dynamic-import"]
  }
}

fallbackLocale

Default: ''

Translation from fallbackLocale is used when translation for given locale is missing.

If fallbackLocale isn’t defined or translation in fallbackLocale is missing too, either message default or message ID is used instead.

format

Default: lingui

Format of message catalogs. Possible values are:

lingui

Each message is an object composed in the following format:

{
  "MessageID": {
    "translation": "Translated Message",
    "defaults": "Default string (from source code)",
    "origin": [
      ["path/to/src.js", 42]
    ]
  }
}

Origin is filename and line number from where the message was extracted.

Note that origins may produce a large amount of merge conflicts. Origins can be disabled by setting origins: false in formatOptions.

minimal

Simple JSON with message ID -> translation mapping:

{
   "MessageID": "Translated Message"
}

po

Gettext PO file:

#: src/App.js:4, src/Component.js:2
msgid "MessageID"
msgstr "Translated Message"

formatOptions

Default: { origins: true }

Object for configuring message catalog output. See individual formats for options.

sourceLocale

Default: ''

Locale of message IDs, which is used in source files. Catalog for sourceLocale doesn’t require translated messages, because message IDs are used by default. However, it’s still possible to override message ID by providing custom translation.

The difference between fallbackLocale and sourceLocale is that fallbackLocale is used in translation, while sourceLocale is used for the message ID.

srcPathDirs

Default: [<rootDir>]

List of directories with source files from which messages are extracted. Ignored directories are defined in srcPathIgnorePatterns.

srcPathIgnorePatterns

Default: ["/node_modules/"]

Ignored paths when looking for source files to extract messages from.

localeDir

Default: <rootDir>/locale

Directory where message catalogs should be saved.

sorting

Default: messageId

Sorting order for catalog files. Possible values are:

messageId

Sort by the message ID.

origin

Sort by file origin of the message.