Create a webpage with Multilanguage in PHP

后端 未结 10 2106
醉话见心
醉话见心 2020-12-11 09:37

I would like to develop a multilanguage page in PHP, for exemple english/german/japanese.. so when i click on german the page language will change to german, then i click en

10条回答
  •  粉色の甜心
    2020-12-11 10:08

    Usually you'd need a UTF-8 enabled website. This is set via the header of the file. (and can be set via header()) function.

    Then I'm guessing you want to have the site in English and Chinese. Then I'd recommend to have a language file. Perhaps an array or an object where you store the paragraphs you want to display on the site. And then you just print out that paragraph.

    Then to know what language the user is asking for, I'd use $_SESSION to store the user's chosen language.

    Then your language file could look like this

    $lang["en"]["Welcome"] = "Welcome to the site";
    

    And then the Chinese welcome file would have something like this

    $lang["ch"]["Welcome"] = "歡迎";
    

    Then in the location you want to print this out. You would do

    echo $lang[$_SESSION["lang"]]["Welcome"];
    

提交回复
热议问题