Language translation using PHP

后端 未结 6 1600
名媛妹妹
名媛妹妹 2021-01-03 13:51

Hi i am devloping sample site in php i need to translate whole website in to persian. how can it possible in php?? I have tried using the following code.. This code will wor

6条回答
  •  不知归路
    2021-01-03 14:16

    AS per me you can try this method.This method is already implemented in our system and it is working properly.

    Make php file of each language and define all the variables and use those variables in pages.

    for e.g For english

    english.php

    $hello="Hello";
    

    persian.php

    $hello=html_entity_decode(htmlentities("سلام"));
    

    Now use this variable to page like this.

    your_page.php

    
    

    You have load specific language file as per get language variable from URL.

    It is better that you have define this language variable into config file.

    config.php

    if(isset($_GET['lang']) && $_GET['lang']=='persian')
    {
       require_once('persian.php');
    }
    else
    {
       require_once('english.php');
    }
    

提交回复
热议问题