定制 lingodotdev/sdk 二次开发

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

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

lingodotdev/sdk

Composer 安装命令:

composer require lingodotdev/sdk

包简介

Official PHP SDK for Lingo.dev

README 文档

README

Official PHP SDK for Lingo.dev, a powerful localization engine that supports various content types including plain text, objects, and chat sequences.

Installation

You can install the SDK via Composer:

composer require lingodotdev/sdk

Basic Usage

After installing the package, bootstrap the engine with your API key:

require 'vendor/autoload.php';

use LingoDotDev\Sdk\LingoDotDevEngine;

$engine = new LingoDotDevEngine([
    'apiKey' => 'your-api-key',       // replace with your actual key
    'engineId' => 'your-engine-id',   // optional — override the default engine
]);

Configuration Options

Option Type Required Default Description
apiKey string Yes Your Lingo.dev API key
engineId string No Your Lingo.dev Engine ID
apiUrl string No https://api.lingo.dev API base URL
batchSize int No 25 Max items per chunk (1–250)
idealBatchItemSize int No 250 Max words per chunk (1–2500)

Scenarios demonstrated in this README

  1. Text Localization
  2. Object Localization
  3. Chat Localization
  4. Batch Localization
  5. Language Detection
  6. Progress Tracking

Requirements

  • PHP 8.1 or higher
  • Composer
  • GuzzleHttp Client

Getting Started

Creating a New PHP Project with Lingo.dev SDK

Follow these steps to create a new PHP project that uses the Lingo.dev SDK:

  1. Create a project directory:

    mkdir my-lingo-project
    cd my-lingo-project
  2. Initialize Composer:

    composer init --name=your-vendor/your-project --description="Your project description" --type=project --require="php:^8.1" --author="Your Name <your.email@example.com>"
  3. Add Lingo.dev SDK as a dependency:

    composer require lingodotdev/sdk

API Scenarios

Initialize the SDK

<?php

use LingoDotDev\Sdk\LingoDotDevEngine;

// Initialize the SDK with your API key
$engine = new LingoDotDevEngine([
    'apiKey' => 'your-api-key',
    'engineId' => 'your-engine-id',   // optional
]);

Text Localization

Translate a simple text string from one language to another:

// Localize a text string from English to Spanish
$localizedText = $engine->localizeText('Hello, world!', [
    'sourceLocale' => 'en',
    'targetLocale' => 'es',
]);
// Output: "¡Hola, mundo!"

Object Localization

Translate an array of strings while preserving the structure:

// Localize an object from English to French
$localizedObject = $engine->localizeObject([
    'greeting' => 'Hello',
    'farewell' => 'Goodbye',
    'messages' => [
        'welcome' => 'Welcome to our service',
        'thanks' => 'Thank you for your business'
    ]
], [
    'sourceLocale' => 'en',
    'targetLocale' => 'fr',
]);
/* Output:
[
    'greeting' => 'Bonjour',
    'farewell' => 'Au revoir',
    'messages' => [
        'welcome' => 'Bienvenue dans notre service',
        'thanks' => 'Merci pour votre confiance'
    ]
]
*/

You can pass a reference to provide additional context:

// Localize with reference for additional context
$localizedObject = $engine->localizeObject([
    'greeting' => 'Hello',
], [
    'sourceLocale' => 'en',
    'targetLocale' => 'es',
    'reference' => [
        'fr' => ['greeting' => 'Bonjour']
    ],
]);

Chat Localization

Translate a chat conversation while preserving speaker names:

// Localize a chat conversation from English to German
$localizedChat = $engine->localizeChat([
    ['name' => 'Alice', 'text' => 'Hello, how are you?'],
    ['name' => 'Bob', 'text' => 'I am fine, thank you!'],
    ['name' => 'Alice', 'text' => 'What are you doing today?']
], [
    'sourceLocale' => 'en',
    'targetLocale' => 'de',
]);
/* Output:
[
    ['name' => 'Alice', 'text' => 'Hallo, wie geht es dir?'],
    ['name' => 'Bob', 'text' => 'Mir geht es gut, danke!'],
    ['name' => 'Alice', 'text' => 'Was machst du heute?']
]
*/

Language Detection

Detect the language of a given text:

// Detect language
$locale = $engine->recognizeLocale('Bonjour le monde');
// Output: "fr"

Batch Localization

Translate a text to multiple languages at once:

// Batch localize text to multiple languages
$localizedTexts = $engine->batchLocalizeText('Hello, world!', [
    'sourceLocale' => 'en',
    'targetLocales' => ['es', 'fr', 'de', 'it'],
]);
/* Output:
[
    "¡Hola, mundo!",
    "Bonjour le monde!",
    "Hallo, Welt!",
    "Ciao, mondo!"
]
*/

Progress Tracking

Track the progress of a localization operation:

// Localize with progress tracking
$engine->localizeText('Hello, world!', [
    'sourceLocale' => 'en',
    'targetLocale' => 'es',
], function ($progress) {
    echo "Localization progress: $progress%\n";
});

Demo App

If you prefer to start with a minimal example instead of the detailed scenarios above, create index.php in an empty folder, copy the following snippet, install dependencies with composer require lingodotdev/sdk, set LINGODOTDEV_API_KEY (and optionally LINGODOTDEV_ENGINE_ID), and run php index.php.

Want to see everything in action?

  1. Clone this repository or copy the index.php from the demo below into an empty directory.
  2. Run composer install to pull in the SDK.
  3. Populate the LINGODOTDEV_API_KEY environment variable (and optionally LINGODOTDEV_ENGINE_ID).
  4. Execute the script with php index.php and observe the output.

index.php demo:

<?php

require 'vendor/autoload.php';

use LingoDotDev\Sdk\LingoDotDevEngine;

$config = [
    'apiKey' => getenv('LINGODOTDEV_API_KEY'),
];
if (getenv('LINGODOTDEV_ENGINE_ID')) {
    $config['engineId'] = getenv('LINGODOTDEV_ENGINE_ID');
}
$engine = new LingoDotDevEngine($config);

// 1. Text
$helloEs = $engine->localizeText('Hello world!', [
    'sourceLocale' => 'en',
    'targetLocale' => 'es',
]);
echo "Text ES: $helloEs\n\n";

// 2. Object
$objectFr = $engine->localizeObject([
    'greeting' => 'Good morning',
    'farewell' => 'Good night',
], [
    'sourceLocale' => 'en',
    'targetLocale' => 'fr',
]);
print_r($objectFr);

// 3. Chat
$chatJa = $engine->localizeChat([
    ['name' => 'Alice', 'text' => 'Hi'],
    ['name' => 'Bob', 'text' => 'Hello!'],
], [
    'sourceLocale' => 'en',
    'targetLocale' => 'ja',
]);
print_r($chatJa);

// 4. Detect language
$lang = $engine->recognizeLocale('Ciao mondo');
echo "Detected: $lang\n";

Release Process

The SDK uses semantic versioning (MAJOR.MINOR.PATCH) and is automatically published to Packagist when changes are merged to the main branch. The release process includes:

  1. Running tests to ensure code quality
  2. Detecting the current version from git tags
  3. Automatically bumping the patch version
  4. Creating a new git tag for the new version

Packagist automatically fetches new versions from the GitHub repository when tags are pushed, making the new version immediately available for installation via Composer. The version is determined by git tags rather than being stored in composer.json, following Packagist best practices.

Documentation

For more detailed documentation, visit the Lingo.dev Documentation.

License

This SDK is released under the MIT License.

lingodotdev/sdk 适用场景与选型建议

lingodotdev/sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 595 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 lingodotdev/sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-03