Twig: Working internationalization (i18n) example

后端 未结 2 1797
终归单人心
终归单人心 2021-02-13 20:36

I am looking for a working i18n example for Twig (the template engine).

Documentation is a bit sparse when it comes to language files. Where should they go, how should

2条回答
  •  执念已碎
    2021-02-13 20:45

    The twig i18n extension is based on gettext. So first of all everything related to gettext applies. You find that documented here: Gettext Docs.

    So now to the more concrete parts of you question, but please ensure you've at least understood the basic principles with gettext:

    Where should they [the language files] go

    Into the directory that has been registered for the text-domain.

    , how should they look and what should they be named?

    Language files should be named the following:

    text-domain-locale.po/mo

    Example for a text domain called myAppPhp and the fr_FR locale:

    myAppPhp-fr_FR.po
    myAppPhp-fr_FR.mo
    

    I have been trying with .po/.mo files, no luck.

    .po/.mo sounds good to me, maybe you have just missed the path where to move them or you have forgotten to add the text-domain in front.

提交回复
热议问题