PHP code example of joeybab3 / phphtmltranslator

1. Go to this page and download the library: Download joeybab3/phphtmltranslator 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/ */

    

joeybab3 / phphtmltranslator example snippets



oeybab3\HTMLTranslator\HTMLTranslator as Translator;

$dsn = "mysql:host=127.0.0.1;dbname=database_name;charset=$charset";
$username = "";
$password = "";
try {
    $db = new PDO($dsn, $username, $password);
} catch (\PDOException $e) {
    throw new \PDOException($e->getMessage(), (int)$e->getCode());
}

Translator::createTranslationCacheTable($db);


oeybab3\HTMLTranslator\HTMLTranslator as Translator;

$TR = new Translator($db, "es"); // translate to Spanish
$html = "<div class='test'><span>This text is not bold but <b>this text is bold</b></span><span>This text, on the other hand, will be a separate translation entirely.</span>";

$result = $TR->tokenizedTranslate($html);

// <div class='test'><span>Este texto no está en negrita pero <b>este texto está en negrita</b></span><span>Este texto, por otro lado, será una traducción completamente separada. </span>