php-gettext
The preset for gettext in PHP. It reads .po catalogs and gettext, _ and __ calls. It applies only when you list it.
The php-gettext preset supports gettext in PHP projects.
Detection
The preset has no detection. It applies only when you list it in presets. The preset is exclusive: x18n applies no listed preset after it.
import { phpGettext } from '@x18n/cli/presets'
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: [phpGettext()],
})presets: [php-gettext]Locale files
If your config has no resources, the preset uses locale/{locale}/LC_MESSAGES/*.po and locales/{locale}.po. The po format reads and writes these catalogs. Each msgid is a key, and its msgstr is the value:
locale/de/LC_MESSAGES/messages.po
msgid "Hello"
msgstr "Hallo"Supported syntax
In PHP files, the preset reads gettext, _ and __. The key is the source message:
index.php
<?php echo gettext("Hello"); echo _("Missing");These usages are Hello and Missing.
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
printf: %s, %d, %1$s.
Extraction templates
| Kinds | Template |
|---|---|
| any | gettext('{key}') |