Lingo.dev + .po (Gettext)
Lingo.dev CLI translates GNU gettext .po files while preserving msgid references, metadata, and gettext-specific formatting conventions. The CLI follows GNU gettext specification exactly, works with xgettext, msgfmt, and Poedit tools, handles msgctxt for disambiguation, supports complex plural form rules, and preserves all translator and build information.
Quick Setup
Configure for gettext portable object files:
{
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"po": {
"include": ["locale/[locale]/LC_MESSAGES/messages.po"]
}
}
}
Reminder: [locale]
is a placeholder that should remain in the config literally, as it's replaced with the actual locale during CLI run.
Translate PO Files
npx lingo.dev@latest i18n
Preserves msgid references, translator comments, and gettext metadata while updating msgstr translations.
Gettext Structure Handling
Basic Message Translation
#: src/main.c:42
msgid "Welcome to our application"
msgstr "Bienvenido a nuestra aplicación"
#: src/dialog.c:15
#, c-format
msgid "You have %d new messages"
msgstr "Tienes %d mensajes nuevos"
Plural Forms
#: src/counter.c:28
msgid "One file selected"
msgid_plural "%d files selected"
msgstr[0] "Un archivo seleccionado"
msgstr[1] "%d archivos seleccionados"
Context Handling
#: src/menu.c:12
msgctxt "menu item"
msgid "File"
msgstr "Archivo"
#: src/toolbar.c:8
msgctxt "document type"
msgid "File"
msgstr "Fichero"
Metadata Preservation
PO Header Information
# Translation file for MyApp
# Copyright (C) 2024 MyCompany
# This file is distributed under the same license as the MyApp package.
#
msgid ""
msgstr ""
"Project-Id-Version: MyApp 1.0\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-01-15 10:30+0000\n"
"Language: es\n"
"Content-Type: text/plain; charset=UTF-8\n"
All header metadata and translator comments are preserved exactly.
Comment Types
- Translator Comments:
# This needs context
- Extracted Comments:
#. Developer note about usage
- Reference Comments:
#: src/file.c:123
- Flag Comments:
#, c-format, fuzzy
Advanced Configuration
Multiple Domains
"po": {
"include": [
"locale/[locale]/LC_MESSAGES/messages.po",
"locale/[locale]/LC_MESSAGES/errors.po"
]
}
Lock Message IDs
"po": {
"include": ["locale/[locale]/LC_MESSAGES/messages.po"],
"lockedKeys": ["version", "copyright"]
}