PHP code example of ucraft-com / translation-app-sdk
1. Go to this page and download the library: Download ucraft-com/translation-app-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ucraft-com / translation-app-sdk example snippets
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();
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();
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);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.