lingui
The preset for Lingui. It reads .po catalogs, the t macro, Trans, msg, defineMessage and useLingui.
The lingui preset supports Lingui.
Detection
The preset applies when the project depends on @lingui/core, @lingui/react or @lingui/macro.
x18n.config.ts
import { lingui } from '@x18n/cli/presets'
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: [lingui()],
})Locale files
If your config has no resources, the preset uses src/locales/{locale}/messages.po and locales/{locale}/messages.po. The po format reads and writes these gettext catalogs. Each msgid is a key, and its msgstr is the value:
src/locales/en/messages.po
msgid "Hello"
msgstr "Hello"
msgid "welcome"
msgstr "Welcome"Supported syntax
Lingui keys are often the source message itself. The macros and calls below are usages of Hello and welcome:
src/a.tsx
import { t } from '@lingui/core/macro'
import { Trans } from '@lingui/react/macro'
const a = t`Hello`
const b = <Trans id="welcome" />
const c = <Trans>Hello</Trans>- The tagged template
t`...`and the text of<Trans>...</Trans>are usages. i18n._,i18n.t,tand_are translate calls with the key as the first argument.t,msg,defineMessage,i18n._and<Trans>also take the key from anidproperty.useLingui()returnstand_.
Keys for extracted strings
The preset sets extract.keygen to source, so x18n extract uses the text itself as the key. Set extract.keygen in the config to change it.
Placeholders
ICU MessageFormat, as for next-intl.
Extraction templates
| Kinds | Template | Imports |
|---|---|---|
jsx-text | <Trans>{key}</Trans> | import { Trans } from '@lingui/react/macro' |
js-string, js-template | t`{key}` | import { t } from '@lingui/core/macro' |