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

后端 未结 7 1527
被撕碎了的回忆
被撕碎了的回忆 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:44

    I have no experience on gettext so no comment on that topic, but I have built a few multi-lingual sites using the following methods:

    METHOD 1

    I wouldn't say my format is the best, just that it's effective. I've also used array. Depending on where the content is stored.

    For example, I'll have an associative array of text with the indexes identifying which text:

    $text['english']['welcome'] = "Welcome to my site. blah blah blah";
    $text['english']['login'] = "Please enter your username and password to login";
    

    And maybe set your language with a constant or config variable.

    METHOD 2

    I've built two sites with identical structures and back-ends but each one used a different database and were maintained separately: data_french, data_english.

提交回复
热议问题