Advanced customization of translations in Symfony2

后端 未结 3 1755
無奈伤痛
無奈伤痛 2020-12-10 16:35

I have a Symfony2 project and I am using Translation component for translating text. I have all translations in yml file like so

3条回答
  •  半阙折子戏
    2020-12-10 17:17

    AFAIK, Translator component doesn't support it.

    But if you want same kind of behavior, you could do by overriding the translator service.

    1) Override the service

    # app/config/config.yml
    parameters:
        translator.class:      Acme\HelloBundle\Translation\Translator
    

    First, you can set the parameter holding the service's class name to your own class by setting it in app/config/config.yml. FYI: https://github.com/symfony/FrameworkBundle/blob/master/Resources/config/translation.xml

    2) Extend the translator class provided symfony framework bundle. FYI: https://github.com/symfony/FrameworkBundle/blob/master/Translation/Translator.php

    3) Overwrite the trans function which is provider by translator component. https://github.com/symfony/Translation/blob/master/Translator.php

    Hope this helps!

提交回复
热议问题