gabrielesbaiz/google-translate-toolkit
Composer 安装命令:
composer require gabrielesbaiz/google-translate-toolkit
包简介
A lightweight helper package to handle translations using Google Translate API.
README 文档
README
A lightweight helper package to handle translations using Google Translate API.
Original code from JoggApp/laravel-google-translate
Features
- ✅ Basic translation
- ✅ Advanced translation
- ✅ Detect language
- ✅ Batch detect language
- ✅ Batch detect language
- ✅ Batch translation
- ✅ Get available translations for a given text
Installation
You can install the package via composer:
composer require gabrielesbaiz/google-translate-toolkit
You can publish the config file with:
php artisan vendor:publish --tag="google-translate-toolkit-config"
This is the contents of the published config file:
return [ /* * The ISO 639-1 code of the default source language. */ 'default_source_translation' => 'en', /* * The ISO 639-1 code of the language in lowercase to which * the text will be translated to by default. */ 'default_target_translation' => 'en', /* * Api Key generated within Google Cloud Dashboard. */ 'api_key' => env('GOOGLE_TRANSLATE_API_KEY'), ];
Usage
$googleTranslateToolkit = new Gabrielesbaiz\GoogleTranslateToolkit(); echo $googleTranslateToolkit->translate('Hello world');
Using facade:
use GoogleTranslateToolkit; GoogleTranslateToolkit::translate('Hello world');
Available Methods
GoogleTranslateToolkit::detectLanguage(string $text): array- Detect the language.GoogleTranslateToolkit::detectLanguage(array $texts): array- Detect the language.GoogleTranslateToolkit::translate(string $text): array- Translate the given text.GoogleTranslateToolkit::translate(array $texts): array- Translate the given text.GoogleTranslateToolkit::justTranslate(string $text)): string- Translate the given text.GoogleTranslateToolkit::getAvailableTranslationsFor('en'): array- Get all the available translations from 'Google Translation' for a particular language by passing its language code.GoogleTranslateToolkit::unlessLanguageIs('en', string $text): array- Translate unless the language is same as the first argument. It accepts an optional third argument which is the language code you want the string to be translated in. You can specify the default option in the config file. If the languages are same, the input string is returned as it is, else an array is returned containing the translation results.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
gabrielesbaiz/google-translate-toolkit 适用场景与选型建议
gabrielesbaiz/google-translate-toolkit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.74k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 03 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Gabriele Sbaiz」 「google-translate-toolkit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gabrielesbaiz/google-translate-toolkit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gabrielesbaiz/google-translate-toolkit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gabrielesbaiz/google-translate-toolkit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight helper package to handle Eloquent model duplication.
Custom Laravel Nova 4 map detail field
A lightweight heklper package to handle WhatsApp messages using api.whatsapp.com
A lightweight helper package to handle Unsplash photos
Custom Laravel Nova 4 map card.
Customer Nova field for JSON data.
统计信息
- 总下载量: 9.74k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-03