Twig: Working internationalization (i18n) example

后端 未结 2 1799
终归单人心
终归单人心 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:44

    I've tried everything possible in slim 3 but nothing was working, only slim 2, so I've created my own way. Basically the system detects the language from the browser and load the correct translation file, more details in the picture:

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题