jszsl001/translation

调用翻译API进行翻译

2.2 2024-07-24 05:58 UTC

This package is auto-updated.

Last update: 2024-09-24 06:21:31 UTC


README

translation_api

快速开始

安装

composer require jszsl001/translation

使用

use jszsl001\Translation\Translation;

$text = 'hello world';

$translation = new Translation();
$result = $translation-> translate($text, 'en', 'zh-CN');

var_dump($result);

演示

<?php
require_once "vendor/autoload.php";

use jszsl001\Translation\Translation;

$text = <<<EOT
    The world is a vast and beautiful place, full of wonder and excitement. There are so many things to see and do, and so many people to meet. We can travel to different countries, learn new languages, and experience different cultures. We can try new foods, meet new people, and make new friends. We can learn new things, expand our horizons, and challenge ourselves. The possibilities are endless.
    So what are you waiting for? Get out there and explore the world! There's a whole world waiting for you to discover.
    EOT;


$translation = new Translation();
$result = $translation
//    -> setChannel('google') // 可选 google, microsoft
//    -> setProxy('http://127.0.0.1:1081') // 可选
    -> translate($text, 'en', 'zh-CN');

var_dump($result);

免责声明

此包仅用于教育目的开发。请勿依赖此包,使用后请删除,因为它可能会在任何时候崩溃,因为它是基于抓取谷歌翻译网站。建议购买官方谷歌翻译API用于其他类型的使用。