---
title: "lingui"
description: "The preset for Lingui. It reads .po catalogs, the t macro, Trans, msg, defineMessage and useLingui."
canonical_url: "https://x18n.dev/presets/lingui"
---
# lingui

> The preset for Lingui. It reads .po catalogs, the t macro, Trans, msg, defineMessage and useLingui.

The `lingui` preset supports [Lingui](https://lingui.dev).

## Detection

The preset applies when the project depends on `@lingui/core`, `@lingui/react` or `@lingui/macro`.

```ts [x18n.config.ts]
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. The preset sets `keySeparator: false`, so a `.` or `:` in a `msgid` stays part of the key:

```po [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`:

```tsx [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`, `t` and `_` are translate calls with the key as the first argument.
- `t`, `msg`, `defineMessage`, `i18n._` and `<Trans>` also take the key from an `id` property.
- `useLingui()` returns `t` and `_`.

## 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](https://x18n.dev/presets/next-intl#placeholders).

## 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'`      |


## Sitemap

See the full [sitemap](https://x18n.dev/sitemap.md) for all pages.
