承接 mgcodeur/super-translator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mgcodeur/super-translator

最新稳定版本:1.0.5

Composer 安装命令:

composer require mgcodeur/super-translator

包简介

SuperTranslator is a PHP package that allows you to translate text from one language to another using the Google Translate API.

README 文档

README

Run Tests Packagist Downloads (custom server)

About SuperTranslator

SuperTranslator is a PHP package that allows you to translate text from one language to another using the Google Translate API.

Installation

Install the package via composer:

composer require mgcodeur/super-translator

Basic Usage

require_once 'vendor/autoload.php'; // if you don't use autoloading
use Mgcodeur\SuperTranslator\GoogleTranslate;

$from = 'en';
$to = 'fr';
$text = 'Hello World!';

$translatedText = GoogleTranslate::translate($from, $to, $text);
echo $translatedText;
// Output: Bonjour le monde!

Automatic language detection

If you want to automatically detect the language of the text to translate, you can use the translateAuto method of the GoogleTranslate class like this:

require_once 'vendor/autoload.php'; // if you don't use autoloading
use Mgcodeur\SuperTranslator\GoogleTranslate;

$to = 'fr';
$text = 'Hello World!';

$translatedText = GoogleTranslate::translateAuto($to, $text);
echo $translatedText;
// Output: Bonjour le monde!

You can alse use 'auto' as the value of the $from parameter:

require_once 'vendor/autoload.php'; // if you don't use autoloading
use Mgcodeur\SuperTranslator\GoogleTranslate;

$from = 'auto';
$to = 'fr';
$text = 'Hello World!';

$translatedText = GoogleTranslate::translate($from, $to, $text);
echo $translatedText;
// Output: Bonjour le monde!

Translate multiple languages

If you want to translate a text into multiple languages, you just have to pass an array of languages to the translate or translateAuto method of the GoogleTranslate class like this:

require_once 'vendor/autoload.php'; // if you don't use autoloading
use Mgcodeur\SuperTranslator\GoogleTranslate;

$from = 'en';
$to = ['fr', 'es', 'de'];

$text = 'Hello World!';

$translatedText = GoogleTranslate::translate($from, $to, $text);

//Nb: the $translatedText variable is an array

# Output: [
#    'fr' => 'Bonjour le monde!',
#    'es' => '¡Hola Mundo!',
#    'de' => 'Hallo Welt!'
# ]

Contributors ✨

Thanks go to these wonderful people ✨:

统计信息

  • 总下载量: 82
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固