定制 sharpapi/laravel-content-translate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sharpapi/laravel-content-translate

Composer 安装命令:

composer require sharpapi/laravel-content-translate

包简介

AI Content Translation for Laravel powered by SharpAPI.com

README 文档

README

Latest Version on Packagist Total Downloads

This package provides a Laravel integration for the SharpAPI Content Translation service. It allows you to translate text to different languages with AI-powered accuracy, which is perfect for multilingual applications, content localization, and more.

Installation

You can install the package via composer:

composer require sharpapi/laravel-content-translate

Configuration

Publish the config file with:

php artisan vendor:publish --tag="sharpapi-content-translate"

This is the contents of the published config file:

return [
    'api_key' => env('SHARP_API_KEY'),
    'base_url' => env('SHARP_API_BASE_URL', 'https://sharpapi.com/api/v1'),
    'api_job_status_polling_wait' => env('SHARP_API_JOB_STATUS_POLLING_WAIT', 180),
    'api_job_status_polling_interval' => env('SHARP_API_JOB_STATUS_POLLING_INTERVAL', 10),
    'api_job_status_use_polling_interval' => env('SHARP_API_JOB_STATUS_USE_POLLING_INTERVAL', false),
];

Make sure to set your SharpAPI key in your .env file:

SHARP_API_KEY=your-api-key

Usage

use SharpAPI\ContentTranslate\ContentTranslateService;

$service = new ContentTranslateService();

// Translate text to a different language
$translatedText = $service->translate(
    'Hello, how are you today?',
    'Spanish', // target language
    'friendly', // optional voice tone
    'casual conversation' // optional context
);

// $translatedText will contain the translated text as a string

Parameters

  • text (string): The text content to translate
  • language (string): The target language for translation
  • voiceTone (string|null): The tone of voice for the translation (e.g., professional, casual, friendly)
  • context (string|null): Additional context to improve translation accuracy

Response Format

{
    "data": {
        "type": "api_job_result",
        "id": "5de4887a-0dfd-49b6-8edb-9280e468c210",
        "attributes": {
            "status": "success",
            "type": "content_translate",
            "result": {
                "content": "The rise in sea levels threatens to engulf the Maldives where fresh water is already starting to run out, but the new president of the Indian Ocean archipelago refuses any relocation of its population abroad. In an interview with AFP, President Mohamed Muizzu, a 45-year-old civil engineering graduate trained in the United Kingdom, instead promises an ambitious program of land rehabilitation and island elevation, which environmental organizations criticize.",
                "to_language": "English",
                "from_language": "French"
            }
        }
    }
}

## Supported Languages

The service supports a wide range of languages, including but not limited to:
- English
- Spanish
- French
- German
- Italian
- Portuguese
- Russian
- Chinese
- Japanese
- Arabic
- And many more

## Credits

- [Dawid Makowski](https://github.com/dawidmakowski)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-09