sysoce/laravel-translation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sysoce/laravel-translation

Composer 安装命令:

composer require sysoce/laravel-translation

包简介

Provides a translation dictionary layer between a translation service and your Laravel application.

README 文档

README

This package provides a translation dictionary layer between a translation service and your Laravel application. The dictionary layer can be used to avoid cost and speed up reoccurring translations. When you translate text through a translation service the translation is saved to your database and will be used instead of the translation service next time you translate the same text.

Installation

Laravel

This package can be used in Laravel 5.4 or higher.

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:

'providers' => [
    // ...
    Sysoce\Translation\TranslationServiceProvider::class,
];

You can publish the migration with:

php artisan vendor:publish --provider="Sysoce\Translation\TranslationServiceProvider" --tag="migrations"

After the migration has been published you can create the translations table by running the migration:

php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Sysoce\Translation\TranslationServiceProvider" --tag="config"

Usage

The Client

To use this package you need to connect to a translation service. This package provides a wrapper for Google Cloud Translate out of the box. To use this translation client you need to install the Google Cloud Translate package:

composer require google/cloud-translate

Enter the path to your JSON key file obtained from the Google Cloud Console in the published config/translation.php config file or simply specify the path in your .env file:

/*
 * If the client requires a key file, enter its path below.
 */
'keyFilePath' => env('GOOGLE_APPLICATION_CREDENTIALS', ''),

You can create a wrapper for other Translation services by implementing the Sysoce\Translation\Contracts\Client contract.

Using the translation dictionary layer

To use the translation dictionary layer

// Set source language for translation
app(Translation::class)->setSource('en');
// Set target language for translation
app(Translation::class)->setTarget('ja');

// Translate text
$translation = app(Translation::class)->translate('hello');

// Print translation (outputs 'こんにちは')
echo $translation->text

Extending

If you need to EXTEND the existing Translation model note that:

  • Your Translation model needs to extend the Sysoce\Translation\Models\Translation model

If you need to REPLACE the existing Translation model you need to keep the following things in mind:

  • Your Translation model needs to implement the Sysoce\Translation\Traits\HasHashIdTrait and Sysoce\Translation\Traits\TranslationTrait traits

Whether extending or replacing, you will need to specify your new model in the configuration. To do this you must update the models.translation value in the configuration file after publishing the configuration.

Testing

./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

License

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

sysoce/laravel-translation 适用场景与选型建议

sysoce/laravel-translation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 11 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-09