1. Go to this page and download the library: Download yiisoft/i18n-formatter-intl 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/ */
yiisoft / i18n-formatter-intl example snippets
declare(strict_types=1);
use Yiisoft\Translator\MessageFormatterInterface;
use Yiisoft\Translator\Formatter\Intl\IntlMessageFormatter;
return [
MessageFormatterInterface::class => IntlMessageFormatter::class,
];
/** @var \Yiisoft\Translator\Translator $translator **/
$categoryName = 'moduleId';
$pathToModuleTranslations = './module/messages/';
$additionalCategorySource = new Yiisoft\Translator\CategorySource(
$categoryName,
new \Yiisoft\Translator\Message\Php\MessageSource($pathToModuleTranslations),
new \Yiisoft\Translator\Formatter\Intl\IntlMessageFormatter()
);
$translator->addCategorySource($additionalCategorySource);
$translator->translate('Test string: {str}', ['str' => 'string data'], 'moduleId', 'en');
// output: Test string: string data