mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 16:14:16 +02:00
Flextype Core: I18n Twig Extension - added
This commit is contained in:
@@ -271,6 +271,9 @@ $flextype['view'] = function ($container) {
|
||||
// Add Emitter Twig Extension
|
||||
$view->addExtension(new FlashTwigExtension($container));
|
||||
|
||||
// Add I18n Twig Extension
|
||||
$view->addExtension(new I18nTwigExtension());
|
||||
|
||||
return $view;
|
||||
};
|
||||
|
||||
|
25
flextype/twig/I18nTwigExtension.php
Normal file
25
flextype/twig/I18nTwigExtension.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\I18n\I18n;
|
||||
|
||||
class I18nTwigExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* Callback for twig.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFunction('tr', array($this, 'tr')),
|
||||
];
|
||||
}
|
||||
|
||||
public function tr(string $translate, string $locale = null, array $values = []) : string
|
||||
{
|
||||
return I18n::find($translate, $locale, $values);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user