|
- <?php
-
- namespace Lc\ShopBundle\Twig;
-
- use Symfony\Contracts\Translation\TranslatorInterface;
- use Twig\Extension\AbstractExtension;
- use Twig\TwigFilter;
- use Twig\TwigFunction;
-
- class BackendTwigExtension extends AbstractExtension
- {
- public $trans;
-
- public function __construct(TranslatorInterface $translator)
- {
- $this->trans = $translator;
-
- }
-
-
- public function getFunctions()
- {
- return array(
-
- );
- }
- public function getFilters()
- {
- return [
- new TwigFilter('lc_trad', [$this, 'lcTrad'])
- ];
- }
-
- public function lcTrad($field, $entityName, $type="field")
- {
-
- $tradKey = $type.'.'.$entityName.'.'.$field;
- $tradDefaultKey = $type.'.default.'.$field;
- $trad = $this->trans->trans($tradKey, array(), 'lcshop');
- if($trad == $tradKey){
- $trad = $this->trans->trans($tradDefaultKey, array(), 'lcshop');
- }
- return $trad;
- }
-
-
- }
|