g4 / translate
g4 i18n php library
Installs: 24 287
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 13
Forks: 2
Open Issues: 0
Requires
- php: >=8.3
- g4/commando: *
- g4/constants: *
- jblond/twig-trans: ^1.1
- twig/twig: 3.*
Requires (Dev)
- g4/code-coverage: 2.0.*
- phpunit/phpunit: 9.*
- squizlabs/php_codesniffer: 3.*
README
- Configuration of the gettext extension
- Utlity tool to generate .mo files
- Utility tool for extracting template strings
Install
Using Composer and Packagist
composer require g4/translate
Resources
- Twig The i18n Extension http://twig.sensiolabs.org/doc/extensions/i18n.html
- PHP gettext extension http://fr.php.net/manual/en/function.gettext.php
Requirements
- "twig/twig" https://packagist.org/packages/twig/twig
- "twig/extensions" https://packagist.org/packages/twig/extensions
Usage
Set locale early in the program before rendering any internationalized template.
use G4\Translate\Locale\Locale; use G4\Translate\Locale\Options; $options = new Options(); $options ->setDomain('myDomain') ->setLocale('en_US') ->setPath('/path/to/locale/files'); (new Locale($options))->set();
Command line interface
Convert .po files to .mo
./vendor/bin/translate --path /path/to/locale/files
where --path is path to your locale folder
Extract template strings
./vendor/bin/translate-extract -t /path/to/templates -w /path/to/tmp -g /path/to/locale/files -d myDomain
where:
- -t is path to folder that contains templates
- -w is path to temp folder
- -g is path to folder where myDomain.po file with strings will be generated
- -d domain name
Development
Install dependencies
$ make install
Run tests
$ make test
License
(The MIT License) see LICENSE file for details...