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
Post a Comment