1. Go to this page and download the library: Download kocicak/l10n library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kocicak / l10n example snippets
php composer.phar
// first we create a new instance of plural rule
$plural = new \l10n\Plural\PluralRule1();
// create new instance of Translator with selected plural rule
$translator = new \l10n\Translator\Translator($plural);
// add translations
// $translator->setText($key, $text, $plural = 0);
$translator->setText('statistics.users', '%n% person'); // 0 or nothing for singular
$translator->setText('statistics.users', '%n% people', 1);
// get translations
// $translator->translate($key, $n = 1, array $parameters = array());
//
// or for singular
// $translator->translate($key, array $parameters = array());
echo $translator->translate('statistics.users', 0) . '<br>'; // 0 people
echo $translator->translate('statistics.users', 1) . '<br>'; // 1 person
echo $translator->translate('statistics.users', 50) . '<br>'; // 50 people
echo $translator->translate('statistics.users', 100) . '<br>'; // 100 people
// we can use %variables% in translations
// in default is available variable %n% for number $n (singular/plural number)
$translator->setText('user', 'I am %firstname% %lastname%');
echo $translator->translate('user', ['%firstname%' => 'John', '%lastname%' => 'Doe']); // I am John Doe
// first we create a new instance of class based on IPlural
$language = new \l10n\Language\EnglishLanguage();
// create new instance of Translator with selected language
$translator = new \l10n\Translator\Translator($language);
// add translations
// $translator->setText($key, $text, $plural = 0);
$translator->setText('statistics.users', '%n% person'); // 0 or nothing for singular
$translator->setText('statistics.users', '%n% people', 1);
// get translations
// $translator->translate($key, $n = 1, array $parameters = array());
//
// or for singular
// $translator->translate($key, array $parameters = array());
echo $translator->translate('statistics.users', 0) . '<br>'; // 0 people
echo $translator->translate('statistics.users', 1) . '<br>'; // 1 person
echo $translator->translate('statistics.users', 50) . '<br>'; // 50 people
echo $translator->translate('statistics.users', 100) . '<br>'; // 100 people
// we can use %variables% in translations
// in default is available variable %n% for number $n (singular/plural number)
$translator->setText('user', 'I am %firstname% %lastname%');
echo $translator->translate('user', ['%firstname%' => 'John', '%lastname%' => 'Doe']); // I am John Doe
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.