galette / smarty-xgettext
Smarty xgettext features
Fund package maintenance!
paypal.me/pools/c/8u4dEPpM0q
Installs: 24 883
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/galette/smarty-xgettext
Requires
- php: ^7.3 || ^8
- geekwright/po: ^2.0
- smarty/smarty: ^3.1
- symfony/console: ^5.1
- symfony/finder: ^5.1
Requires (Dev)
- phpunit/phpunit: ^8 || ^9
- squizlabs/php_codesniffer: ^3.5
- symfony/var-dumper: ^3.3
README
A command line utility to extract translations source strings from Smarty templates to a PO-Template (.pot) file.
This utility will scan templates for {_T string=""} placeholders for translation strings and output a .pot file (.po template).
Features:
- scan files and directories recursively,
- include original string location,
- supports plurals
{_T string="singular" plural="plural"}, - supports contexts
{_T string="string" context="mycontext"}, - supports comments
{_T string="string" comment="Explanation"} - supports domains
{_T string="string" domain="mydomain""},{_T string="singular" plural="plural" domain="mydomain}, ...
Usage:
./vendor/bin/smarty-xgettext -o smarty.pot <filename or directory> <file2> <...>
find templates -name '*.tpl.html' -o -name '*.tpl.text' -o -name '*.tpl.js' -o -name '*.tpl.xml' | xargs ./vendor/bin/smarty-xgettext -o smarty.pot
If a parameter is a directory, the template files within will be parsed, recursively.
If you want to combine Smarty translations with your PHP ones, you can combine results with the msgcat command:
./vendor/bin/smarty-xgettext.php -o smarty.pot /path/to/source/templates
xgettext /path/to/source/php --keyword=_T --output=php.pot
msgcat -o project.pot --use-first php.pot smarty.pot
Developing
- clone this repository
- get composer
- install composer dependencies:
php composer.phar install - start using it:
php bin/smarty-xgettext
Initially based on tsmatry2c. Original project (which seems not maintained) was using Smarty blocks while Galette relies on a function.