symfony - Default to blank string in Twig template if translation is not found -


is there way default blank string rather translation key in event translation has not been found in twig template?

i attempting sort of thing using default twig filter alongside trans filter not work:

{{ 'crmpicco.general.course.opening_hours_weekend'|default('')|trans }} 

you can overwrite translation extension own, trans , transchoice filter behave want:

<?php // src/appbundle/twig/emptytranslationextension.php  namespace appbundle\twig;  use symfony\bridge\twig\extension\translationextension;  class emptytranslationextension extends translationextension {     public function trans($message, array $arguments = [], $domain = null, $locale = null)     {         $value = parent::trans($message, $arguments, $domain, $locale);          return ($message === $value) ? '' : $value;     }      public function transchoice($message, $count, array $arguments = [], $domain = null, $locale = null)     {         $value = parent::transchoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);          return ($message === $value) ? '' : $value;     } } 

and register extension replacement default one:

# app/config/services.yml  services:     twig.extension.trans:         class: appbundle\twig\emptytranslationextension         public: false         arguments:             - @translator         tags:             - { name: twig.extension } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -