Using PHP Gettext Extension vs PHP Arrays in Multilingual Websites?

后端 未结 5 841
礼貌的吻别
礼貌的吻别 2021-01-02 07:39

So far the only 2 good things that I\'ve seen about using gettext instead of arrays is that I don\'t have to create the \"greeting\" \"sub-array\" (or whatever its called).

5条回答
  •  盖世英雄少女心
    2021-01-02 08:08

    The most obvious pro for using gettext() is of course that the source string is positioned where it belongs. I.e. it makes much more sense to write this

    echo _("This is a string");
    

    than

    echo $lang['a_string'];
    

    Not to mention that you have to craft a new variable placeholder for every possible translation. With gettext() the translation string itself acts as the index.

提交回复
热议问题