PHP code example of justmd5 / deeplx

1. Go to this page and download the library: Download justmd5/deeplx library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

justmd5 / deeplx example snippets



lx=new \Justmd5\DeeplX\DeepLTranslator();

try {
//translate chinese to english
    var_dump($deeplx->zh2en("你好"));
    //output:
        //    array(4) {
        //    ["status"]=>
        //    int(1000)
        //    ["code"]=>
        //    int(1000)
        //    ["message"]=>
        //    string(2) "ok"
        //    ["data"]=>
        //    string(12) "How are you?"
        //    }
//translate english to chinese
    var_dump($deeplx->en2zh("hello my friend."));
    //output:
        //array(4) {
        //  ["status"]=>
        //  int(1000)
        //  ["code"]=>
        //  int(1000)
        //  ["message"]=>
        //  string(2) "ok"
        //  ["data"]=>
        //  string(24) "你好,我的朋友。"
        //}
        
        
//normal translate func demo
    $result = $translator->translate('hello', 'ja')->result();
    var_dump($result);
    //output:
        //array(4) {
        //  ["status"]=>
        //  int(1000)
        //  ["code"]=>
        //  int(1000)
        //  ["message"]=>
        //  string(2) "ok"
        //  ["data"]=>
        //  string(12) "こんにちわ"
        //}

} catch (Exception $e) {
    var_dump($e);
}