承接 joggapp/laravel-google-translate 相关项目开发

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

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

joggapp/laravel-google-translate

最新稳定版本:v9.0.0

Composer 安装命令:

composer require joggapp/laravel-google-translate

包简介

Laravel package for the Google Translate API

README 文档

README

Laravel package for the Google Translate API

Latest Version Total Downloads

This package makes using the Google Translate API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.

translate

Installation

  • You can install this package via composer using this command:
composer require joggapp/laravel-google-translate
  • The package will automatically register itself.

  • We have documented how to setup the project and get the necessary configurations from the Google Cloud Platform console in a step by step detailed manner over here.

  • You can publish the config file using the following command:

php artisan vendor:publish --provider="JoggApp\GoogleTranslate\GoogleTranslateServiceProvider"

This will create the package's config file called googletranslate.php in the config directory. These are the contents of the published config file:

return [
    /*
    |----------------------------------------------------------------------------------------------------
    | The ISO 639-1 code of the language in lowercase to which the text will be translated to by default.
    |----------------------------------------------------------------------------------------------------
    */
    'default_target_translation' => 'en',

    /*
    |-------------------------------------------------------------------------------
    | Path to the json file containing the authentication credentials.
    |
    | The process to get this file is documented in a step by step detailed manner
    | over here:
    | https://github.com/JoggApp/laravel-google-translate/blob/master/google.md
    |-------------------------------------------------------------------------------
    */
    'api_key' => env('GOOGLE_TRANSLATE_API_KEY'),
];

How to use

  • After setting up the config file values you are all set to use the following methods ????

  • Detecting the language. You can pass both, a single string or an array of multiple strings to it:

GoogleTranslate::detectLanguage('Hello world'): array

GoogleTranslate::detectLanguage(['Hello world', 'Laravel is the best']);

// Returns multi-dimensional array containing result set for all the array elements.
  • Translating the string(s): The translate method accepts a third optional argument which can be the code of the language you want the string to be translated in. You can specify the default option in the config file:
// GoogleTranslate::translate($input, $from = null, $to = null, $format = 'text'): array

GoogleTranslate::translate('Hello world'): array

GoogleTranslate::translate(['Hello world', 'Laravel is the best']);

// Returns multi-dimensional array containing result set for all the array elements.
  • Get all the available translations from 'Google Translation' for a particular language by passing its language code:
GoogleTranslate::getAvailableTranslationsFor('en'): array
  • Translate unless the language is same as the first argument. This method is a clean way to ask the package to detect the language of the given string, if it is same as the first argument, translation isn't performed. 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:
GoogleTranslate::unlessLanguageIs('en', string $text);
  • Translating and just returning back the translated string. It accepts an optional second argument which is the language code you want the string to be translated in. You can specify the default option in the config file.
GoogleTranslate::justTranslate(string $text): string
  • There is is an optional third parameter for format to take advantage for better html translation support. Google Translate API currently supports 'text' and 'html' as parameters. The default for this parameter is 'text' as it has the best use case for most translations. Google Translate API Docs
GoogleTranslate::unlessLanguageIs('en', string $text, string $format);
  • There is also a nice blade helper called @translate that comes with the package to make its use more neat in the view files. It accepts an optional second argument which is the language code you want the string to be translated in. You can specify the default option in the config file.
@translate('Hello World')

Testing

You can run the tests with:

vendor/bin/phpunit

Changelog

Please see the CHANGELOG for more information about what has changed recently.

Security

If you discover any security related issues, please email them to harish@jogg.co instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see the License File for more information.

joggapp/laravel-google-translate 适用场景与选型建议

joggapp/laravel-google-translate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 236k 次下载、GitHub Stars 达 169, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「package」 「api」 「google」 「laravel」 「translate」 「google translate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 joggapp/laravel-google-translate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 joggapp/laravel-google-translate 我们能提供哪些服务?
定制开发 / 二次开发

基于 joggapp/laravel-google-translate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 236k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 170
  • 点击次数: 14
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 169
  • Watchers: 14
  • Forks: 56
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知