1. Go to this page and download the library: Download steelywing/translation 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/ */
steelywing / translation example snippets
use SteelyWing\Translation\Dictionary\DictionaryArray;
use SteelyWing\Translation\Dictionary\DictionaryCSV;
use SteelyWing\Translation\Translator;
$translator = new Translator();
// Use array as dictionary
//$dict = new DictionaryArray(g!
echo $translator->translate('hello', [':user' => 'Steely Wing']);
echo "\n<br>\n";
// 你好,Steely Wing!
echo $translator->translate('hello', [':user' => 'Steely Wing'], 'zh_tw');
echo "\n<br>\n";
// I love programming!
echo $translator->translate('i love programming');
echo "\n<br>\n";
// 我喜爱编程!
echo $translator->translate('i love programming', [], 'zh_cn');
echo "\n<br>\n";
// 世界,你好!
echo $translator->translate('hello world', [], 'zh_tw');
echo "\n<br>\n";
// Echo empty, no fallback locale set
echo $translator->translate('english only', [], 'zh_tw');
echo "\n<br>\n";
// Return the key if key not found
$translator->setFallbackToKey(true);
echo $translator->translate('english only', [], 'zh_tw');
echo "\n<br>\n";
// Fallback to "en", echo "English Only"
$translator->setFallback('en');
echo $translator->translate('english only', [], 'zh_tw');
echo "\n<br>\n";
use SteelyWing\Translation\Dictionary\DictionaryChinese;
$chinese = new DictionaryChinese($dict);
$translator->addDictionary($chinese);
// Auto translate "繁體轉簡體中文測試" to "繁体转简体中文測試"
echo $translator->translate('simplified chinese testing', [], 'zh_cn');
echo "\n<br>\n";
// Auto translate "简体转繁体中文测试" to "簡體轉繁體中文測試"
echo $translator->translate('traditional chinese testing', [], 'zh_tw');
echo "\n<br>\n";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.