PHP code example of rafaph / twig-translation-extension
1. Go to this page and download the library: Download rafaph/twig-translation-extension 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/ */
rafaph / twig-translation-extension example snippets
$langPath = __DIR__ . '/lang';
$locale = 'pt';
$translator = new \Illuminate\Translation\Translator(
new \Illuminate\Translation\FileLoader(
new \Illuminate\Filesystem\Filesystem(),
$langPath
),
$locale
);
$translator->setFallback('en');
// ...
$twig->addExtension(
new \Raph\Twig\Extension\TranslationExtension($translator)
);
//in lang/en/messages.php
return [
'hello' => 'Hello :name!',
'there' => '{0} There are none|[1,19] There are some|[20,Inf] There are many'
];