1. Go to this page and download the library: Download slick/i18n 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/ */
use Slick\I18n\Language;
use Slick\I18n\Translation;
use Slick\I18n\Translator;
/**
* Set locale based on the browser accept language
*/
$locale = 'en_US';
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
}
$translation = new Translation(new Language($locale), __DIR__.'/i18n');
$translator = new Translator($translation);
setlocale(LC_ALL, $locale);
echo $translator->translate('Hello world'); // will output 'Olá mundo'
echo $translator->translatePlural('User', 'Users', 2); // will output 'Utilizadores'
use Slick\I18n\TranslateMethods;
use Slick\I18n\TranslationCapableInterface;
use Slick\I18n\TranslatotInterface;
class MyClass implements TranslationCapableInterface
{
use TranslateMethods;
public function __construct(TranslatotInterface $translator)
{
$this->tranlator = $translator;
}
public function getUsers()
{
return $this->translatePlural('User', 'Users', $this->getUserCount());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.