This library permits you to easily create translations for PHP scripts and apps.
- PHP >= 7.3
You can install the package with git clone
and composer install
in the directory.
Or you can directly use composer :
composer require scoobydam/php-translator
This library is an easy-to-use and light one.
use ScoobyTranslator\Translator\Translator;
$translator = new Translator(__DIR__ . '/translations', 'fr');
$translator->translate('key_to_translate');
This example will search for a fr.php
file in the dir you passed the path in the first parameter.
This file might be like following
<?php
// __DIR__/translations/fr.php
$translations = [
'general' => [
'key' => 'value',
],
];
It needs to define the $translations
variable and at least the general
context key.
To know all what you can do, you can find full documentation here.
You can send PRs if you want to :)
Just, please, follow these conventions.