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