PHP
Translate string literals in static PHP locale arrays without executing application code.
PHP applications often load messages from a file that returns an array. The php file handler translates literal string values in that array and keeps lookup keys, comments, numbers, and surrounding syntax. It scans the file without running PHP.
Supported source shape #
For example:
<?php
return [
'checkout' => [
'title' => 'Complete your order',
'delivery' => 'Delivery within :days days',
],
];The text paths are checkout.title and checkout.delivery. Nested bracket arrays and array(...) syntax are supported. The string keys stay unchanged so application lookup continues to use the same identities.
Keep message values in static arrays. Concatenation, function calls, and variable-derived strings require evaluation that this scanner does not perform. A literal found near an expression is not the expression's computed result. Move such messages into literal resource values before relying on file translation to select them.
Quoting and existing targets #
The handler retains each source string's single- or double-quote delimiter and escapes replacements for that delimiter. Double-quoted output retains interpolation tokens already present in the source, such as {$name}, and escapes newly introduced dollar sequences. Check application placeholders such as :days with the values the caller supplies.
Incremental comparison uses each literal's path in the returned array. Unchanged source messages can retain their accepted target values. Changing a key changes the identity used for comparison even when the English words stay the same. The CLI's key controls support locking source values, preserving target values, and removing ignored entries in PHP files.
Key-scoped reconstruction can remove unresolved associative entries with no target value. Do not assume that a partial run produces a complete locale file. Review nested structures and any positional values that your application expects.
Configure and validate the file #
The CLI infers php from .php. Use CLI configuration or GitHub to select source locale files and their destinations.
Run php -l on the target file, then load its messages in the application. Render parameterized copy with the values its callers supply. For Laravel, request-locale selection and fallback remain application configuration; Localize a web app connects the translated resource to those steps.