naimkhalifa/laravel-google-cloud-translation
Composer 安装命令:
composer require naimkhalifa/laravel-google-cloud-translation
包简介
A package to easily integrate Google Cloud Translation API with Laravel
README 文档
README
Installation
You can install the package via composer:
composer require naimkhalifa/laravel-google-cloud-translation
You can publish the config file with:
php artisan vendor:publish --provider="NaimKhalifa\GoogleCloudTranslation\GoogleCloudTranslationServiceProvider"
This is the contents of the published config file:
return [ /* |-------------------------------------------------------------------------- | Google Cloud Translation API Key |-------------------------------------------------------------------------- | | Your Google Cloud Translation API Key. | You can get it from https://console.cloud.google.com/apis/credentials | More info at https://cloud.google.com/translate/docs/setup | */ 'api_key' => env('GOOGLE_CLOUD_TRANSLATION_API_KEY'), /* |-------------------------------------------------------------------------- | Default Source Language |-------------------------------------------------------------------------- | | The default source language to translate from. | You can find the list of supported languages here: | https://cloud.google.com/translate/docs/languages | */ 'default_source_language' => 'en', /* |-------------------------------------------------------------------------- | Default Target Language |-------------------------------------------------------------------------- | | The default target language to translate to. | Obviously, it must be different from the default source language. | */ 'default_target_language' => 'es', /* |-------------------------------------------------------------------------- | Default Format |-------------------------------------------------------------------------- | | The default format to translate to. | Acceptable values are html or text. | */ 'default_format' => 'text', ];
Usage
GoogleCloudTranslation::translate(string $text, array $options)
Use this method if you want to translate a single text string.
# This would translate using default_source_language # and default_target_language config values GoogleCloudTranslation::translate('Hello World'); # with options GoogleCloudTranslation::translate('Hello World', [ 'source' => 'en', 'target' => 'fr', 'format' => 'text', # or 'html' ]);
GoogleCloudTranslation::translateBatch(array $input, array $options)
Use this method if you want to translate multiple strings at once.
GoogleCloudTranslation::translateBatch([ 'Something else', 'Another string to translate', 'And a third one because we can' ]) # You can also pass options to this method GoogleCloudTranslation::translateBatch('Hello World', [ 'source' => 'en', 'target' => 'fr', 'format' => 'text', # or 'html' ]);
Commands
Translate language files
This Artisan command allows you to translate strings in a language file using Google Cloud Translation.
The format of the file you want to translate should conform to what you would typically find under Laravel /lang folder.
php artisan google-cloud-translation:translate-lang-file [options]
Options
--source: Specify the source language for translation. (Required)
--target: Specify the target language for translation. (Required)
--file: Specify the path to the language file you want to translate. (Required)
--dryrun: Enable dry run mode, which will display translations without saving them to a file. (Optional, enabled by default)
Example
php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php
This is when you're running the command with --dryrun option enabled (by default).
This command will translate all the strings in the messages.php language file from English (en) to French (fr) and display the translations on the terminal.
You then have to confirm with prompt for the translations to be saved to destination file (in this example, that would be resources/lang/fr/messages.php).
Be careful that this will override any existing file that lives at that path! Basically replacing it.
If you want to bypass confirmation and directly write to destination, you can disable dryrun mode (--dryrun=false)
php artisan google-cloud-translation:translate-lang-file --source=en --target=fr --file=resources/lang/en/messages.php --dryrun=false
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.
naimkhalifa/laravel-google-cloud-translation 适用场景与选型建议
naimkhalifa/laravel-google-cloud-translation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「naimkhalifa」 「laravel-google-cloud-translation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 naimkhalifa/laravel-google-cloud-translation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 naimkhalifa/laravel-google-cloud-translation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 naimkhalifa/laravel-google-cloud-translation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
This is my package filament-translations-manager
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-27