sy / translate
Translation library
Installs: 1 353
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.0
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-10-08 12:17:03 UTC
README
Translation library
Installation
Install the latest version with
$ composer require sy/translate
Basic Usage
PHP translator
Translation data are stored in a PHP file, for example in fr.php:
<?php return [ 'Hello world' => 'Bonjour monde', ... ]
<?php use Sy\Translate\PhpTranslator; // Create a translator $translator = new PhpTranslator(); // Set translation files directory $translator->setTranslationDir(__DIR__ . '/path/to/directory'); // Set translation file $translator->setTranslationLang('fr'); // Return 'Bonjour monde' $translator->translate('Hello world'),
Gettext translator
Translation data are stored in a .mo file, for example in fr.mo
<?php use Sy\Translate\GettextTranslator; // Create a translator $translator = new GettextTranslator(); // Set translation files directory $translator->setTranslationDir(__DIR__ . '/path/to/directory'); // Set translation file $translator->setTranslationLang('fr'); // Return 'Bonjour monde' $translator->translate('Hello world'),