ucraft-com/translation-app-sdk

使用gRPC访问翻译的SDK

v1.4.16 2024-08-15 09:25 UTC

README

介绍

欢迎使用PHP翻译应用SDK!这个库允许您轻松地将我们的翻译应用集成到PHP应用程序中,让您能够轻松管理应用程序中的翻译。无论您是在构建多语言网站还是全球化应用,此SDK都简化了处理翻译的过程。

安装

使用Composer安装翻译应用SDK

composer require ucraft-com/translation-app-sdk

QueryTranslationItemsValueObject

QueryTranslationItemsValueObject用于查询翻译项。它包含指定资源、资源ID、语言代码和查询的附加选项的值。

使用示例

use Uc\TranslationAppSdk\ValueObjects\QueryTranslationItemsValueObject;

// Create a QueryTranslationItemsValueObject instance
$queryObject = new QueryTranslationItemsValueObject(
    'en-US', // locale
    'your_resource', // optional, ex: project_id 
    1, // optional, ex: project id (1)
    'key', // optional, key to search
    ['key' => 'asc'], // optional, or 'updated_at' => 'desc'
    1, // optional, page number
    20, // optional, first n entites
    false, // optional, find all, default false
);

// Accessing properties
$resource = $queryObject->getResource();
$resourceId = $queryObject->getResourceId();
$languageCode = $queryObject->getLanguageCode();
$key = $queryObject->getKey();
$orderBy = $queryObject->getOrderBy();
$page = $queryObject->getPage();
$first = $queryObject->getFirst();
$findAll = $queryObject->getFindAll();

UpsertTranslationItemValueObject

UpsertTranslationItemValueObject用于插入或更新翻译项。它包含指定翻译值、语言代码、翻译条目ID、资源、资源ID、编辑器名称和可选参数的值。

使用示例

use Uc\TranslationAppSdk\ValueObjects\UpsertTranslationItemValueObject;

// Create an UpsertTranslationItemValueObject instance
$upsertObject = new UpsertTranslationItemValueObject(
    'Hello, World!', // value
    'en-US', // locale
    'your_translation_entry_id', // translation entry id (relation)
    'John Doe', // editor name
    'your_resource', // optional, ex: project_id 
    1, // optional, ex: project id (1)
    null, // optional, translation id (when updating, when null: creating)
    ['param1' => 'value1', 'param2' => 'value2'] // optional, some params that may be used
);

// Accessing properties
$resource = $upsertObject->getResource();
$resourceId = $upsertObject->getResourceId();
$key = $upsertObject->getKey();
$editorName = $upsertObject->getEditorName();
$value = $upsertObject->getValue();
$languageCode = $upsertObject->getLanguageCode();
$hasTranslationId = $upsertObject->hasTranslationId();
$translationId = $upsertObject->getTranslationId();
$hasParams = $upsertObject->hasParams();
$params = $upsertObject->getParams();

TranslationAppClient

TranslationAppClient是一个客户端类,允许您与用于管理翻译的RPC方法进行交互。

使用示例

use Uc\TranslationAppSdk\TranslationAppClient;
use Uc\TranslationAppSdk\ValueObjects\UpsertTranslationItemValueObject;
use Uc\TranslationAppSdk\ValueObjects\QueryTranslationItemsValueObject;

// Create a TranslationAppClient instance
$client = new TranslationAppClient($yourTranslationClientInstance);

// Example QueryTranslationItemsValueObject
$queryObject = new QueryTranslationItemsValueObject(
    'en-US',
    'your_resource',
    1,
    'key',
    ['key' => 'asc'],
    1,
    20,
    false,
);

// Example UpsertTranslationItemValueObject
$upsertObject = new UpsertTranslationItemValueObject(
    'Hello, World!',
    'en-US',
    'your_translation_entry_id',
    'John Doe',
    'your_resource', 
    1, 
    null, 
    ['param1' => 'value1', 'param2' => 'value2'] 
);

// Get paginated translations
$paginatedTranslations = $client->getTranslations($queryObject);

// Find all translations without pagination
$allTranslations = $client->findAll($queryObject);

// Upsert a translation item
$upsertedTranslation = $client->upsert($upsertObject);

许可证

PHP翻译应用SDK是开源软件,受MIT许可证许可。