This guide explains how to use Lara CLI with PO (Portable Object) files, the standard gettext format used in PHP, Python, and many other platforms.
PO files are part of the GNU gettext internationalization system. They store translatable strings in a structured text format and are widely used in web applications, particularly those built with:
- PHP (Laravel, Symfony, WordPress)
- Python (Django, Flask)
- Ruby on Rails
- C/C++ applications
- Many other platforms
To configure PO files in your lara.yaml:
files:
po:
include:
- "locales/[locale]/LC_MESSAGES/messages.po"
exclude: []
lockedKeys: []
ignoredKeys: []files:
po:
include:
- "locales/[locale]/LC_MESSAGES/messages.po"
- "locales/[locale]/LC_MESSAGES/errors.po"This follows the traditional gettext structure:
locales/
├── en/
│ └── LC_MESSAGES/
│ ├── messages.po
│ └── errors.po
├── es/
│ └── LC_MESSAGES/
│ ├── messages.po
│ └── errors.po
files:
po:
include:
- "i18n/[locale].po"
- "translations/[locale]/app.po"This uses a simpler directory structure:
i18n/
├── en.po
├── es.po
└── fr.po
The basic translation unit in PO files:
msgid "Hello, world!"
msgstr "Hola, mundo!"
Use contexts to differentiate identical strings with different meanings:
msgctxt "navigation"
msgid "Home"
msgstr "Inicio"
msgctxt "housing"
msgid "Home"
msgstr "Casa"
Handle singular and plural translations:
msgid "item"
msgid_plural "items"
msgstr[0] "campo"
msgstr[1] "campi"
Lara CLI automatically:
- ✅ Preserves message order from the original file
- ✅ Maintains all metadata and headers
- ✅ Handles contexts and plural forms correctly
- ✅ Updates
PO-Revision-Dateautomatically - ✅ Sets
X-Generatorto "Lara-CLI"
PO file headers are preserved and updated:
msgid ""
msgstr ""
"Language: es\n"
"PO-Revision-Date: 2024-01-15 10:30:00+0000\n"
"X-Generator: Lara-CLI\n"
When using lockedKeys or ignoredKeys with PO files, the patterns match against the msgid:
files:
po:
include:
- "locales/[locale]/LC_MESSAGES/messages.po"
lockedKeys:
- "USER_ID"
- "API_*"
ignoredKeys:
- "DEBUG_*"Here's a complete configuration example for a PHP Laravel project:
version: "1.0.0"
project:
instruction: "E-commerce application, use formal tone"
locales:
source: en
target:
- es
- fr
- de
- it
memories:
- mem_abc123
glossaries:
- gls_xyz789
files:
po:
include:
- "lang/[locale]/messages.po"
- "lang/[locale]/validation.po"
exclude:
- "lang/[locale]/test-*.po"
lockedKeys:
- "API_*"
- "SYSTEM_*"
ignoredKeys:
- "DEBUG_*"
- "TEMP_*"
fileInstructions:
- path: "lang/[locale]/validation.po"
instruction: "Validation messages, keep concise and clear"If you already have PO files with translations:
- Run
lara-cli initto create your configuration - Run
lara-cli translatefor the first time - only missing or changed translations will be processed - Continue developing - Lara CLI tracks changes via checksums and only translates what's new or modified
Ensure your source locale PO files are well-formatted and contain the original text you want to translate.
Use msgctxt to differentiate strings that have the same text but different meanings:
msgctxt "button"
msgid "Save"
msgstr ""
msgctxt "financial"
msgid "Save"
msgstr ""
Use file-level or key-level instructions for better translation quality:
files:
po:
include:
- "lang/[locale]/messages.po"
fileInstructions:
- path: "lang/[locale]/messages.po"
instruction: "Customer-facing messages, friendly tone"Prevent translation of constants and placeholders:
files:
po:
lockedKeys:
- "APP_NAME"
- "VERSION_*"
- "URL_*"Lara CLI preserves the original message order. If you notice changes, ensure your source PO file is properly formatted.
Lara CLI handles plural forms automatically. Ensure your source file correctly defines plural forms for proper translation.
PO files should use UTF-8 encoding. Lara CLI respects the charset specified in the PO file headers.
- Supported Formats - Overview of all supported file formats
- Files Configuration - General file configuration options
- Instructions - How to use translation instructions