what is the best method to build “multilingual” script in php?

后端 未结 7 1546
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 04:13

I am building a website and it need to be in 7 languages? I was wondering if there is a good practice can be applied to get multilingual php script?

  • Easy for m
7条回答
  •  悲哀的现实
    2020-12-16 04:40

    Contrary to daddz I would recommend against using gettext in PHP:

    • The locale setting is per-process. This means that when you are working with a multithreaded apache or any other multithreaded webserver running PHP in-process, calling setlocale in one thread will affect the other threads.

      Because you can't know which thread/process is handling which request, you'll run into awful problems with users intermittently getting the wrong locale.

    • The locale you set in PHP has influence on functions like printf or even strtotime. You will certainly get bit by "strange" number formats arriving in your backend code if you work with gettext/setlocale

    Use any of the other solutions lined to by Eran or quickly do something yourself (PHP arrays work very nicely). Also use the intl-extension which will be in core PHP 5.3 for number and date formating and collation.

    Using gettext on a web based solution over and over proved to be quite like opening the proverbial can of worms.

提交回复
热议问题