PHPackages                             translated/lara-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. translated/lara-sdk

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

translated/lara-sdk
===================

Official Lara SDK for PHP

1.8.1(3w ago)713.8k↑42.5%1[1 issues](https://github.com/translated/lara-php/issues)[2 PRs](https://github.com/translated/lara-php/pulls)MITPHPPHP &gt;=5.6.0

Since Nov 28Pushed 3w ago8 watchersCompare

[ Source](https://github.com/translated/lara-php)[ Packagist](https://packagist.org/packages/translated/lara-sdk)[ Docs](https://laratranslate.com/)[ RSS](/packages/translated-lara-sdk/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (24)Used By (0)

Lara PHP SDK
============

[](#lara-php-sdk)

[![PHP Version](https://camo.githubusercontent.com/a8050e32d41a0d9c4197f459b273647647b9f7b250e24dccec191ccf7882bd3f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e342b2d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

This SDK empowers you to build your own branded translation AI leveraging our translation fine-tuned language model.

All major translation features are accessible, making it easy to integrate and customize for your needs.

🌍 **Features:**
---------------

[](#-features)

- **Text Translation**: Single strings, multiple strings, and complex text blocks
- **Document Translation**: Word, PDF, and other document formats with status monitoring
- **Image Translation**: Translate whole images or extract and translate text blocks
- **Translation Memory**: Store and reuse translations for consistency
- **Glossaries**: Enforce terminology standards across translations
- **Styleguides**: Define tone, voice, and writing style rules for translations
- **Language Detection**: Automatic source language identification
- **Advanced Options**: Translation instructions and more

📚 Documentation
---------------

[](#-documentation)

Lara's SDK full documentation is available at

🚀 Quick Start
-------------

[](#-quick-start)

### Installation

[](#installation)

```
composer require translated/lara-sdk
```

### Basic Usage

[](#basic-usage)

```
require_once 'vendor/autoload.php';

use Lara\LaraCredentials;
use Lara\Translator;
use Lara\LaraException;

// Set your credentials using environment variables (recommended)
$credentials = new LaraCredentials(
    getenv('LARA_ACCESS_KEY_ID'),
    getenv('LARA_ACCESS_KEY_SECRET')
);

// Create translator instance
$lara = new Translator($credentials);

// Simple text translation
try {
    $result = $lara->translate("Hello, world!", "en-US", "fr-FR");
    echo "Translation: " . $result->getTranslation() . PHP_EOL;
    // Output: Translation: Bonjour, le monde !
} catch (LaraException $error) {
    echo "Translation error: " . $error->getMessage() . PHP_EOL;
}
```

📖 Examples
----------

[](#-examples)

The `examples/` directory contains comprehensive examples for all SDK features.

**All examples use environment variables for credentials, so set them first:**

```
export LARA_ACCESS_KEY_ID="your-access-key-id"
export LARA_ACCESS_KEY_SECRET="your-access-key-secret"
```

### Text Translation

[](#text-translation)

- **[text\_translation.php](examples/text_translation.php)** - Complete text translation examples
    - Single string translation
    - Multiple strings translation
    - Translation with instructions
    - TextBlocks translation (mixed translatable/non-translatable content)
    - Auto-detect source language
    - Advanced translation options
    - Get available languages
    - Detect language

```
cd examples
php text_translation.php
```

### Document Translation

[](#document-translation)

- **[document\_translation.php](examples/document_translation.php)** - Document translation examples
    - Basic document translation
    - Advanced options with memories and glossaries
    - Step-by-step translation with status monitoring

```
cd examples
php document_translation.php
```

### Image Translation

[](#image-translation)

- **[image\_translation.php](examples/image_translation.php)** - Image translation examples
    - Basic image translation
    - Advanced options with memories and glossaries
    - Extract and translate text from an image

```
cd examples
php image_translation.php
```

### Translation Memory Management

[](#translation-memory-management)

- **[memories\_management.php](examples/memories_management.php)** - Memory management examples
    - Create, list, update, delete memories
    - Add individual translations
    - Multiple memory operations
    - TMX file import with progress monitoring
    - Translation deletion
    - Translation with TUID and context

```
cd examples
php memories_management.php
```

### Glossary Management

[](#glossary-management)

- **[glossaries\_management.php](examples/glossaries_management.php)** - Glossary management examples
    - Create, list, update, delete glossaries
    - CSV import with status monitoring
    - Glossary export (sync and async)
    - Glossary terms count
    - Import status checking

```
cd examples
php glossaries_management.php
```

### Styleguide Management

[](#styleguide-management)

- **[styleguides\_management.php](examples/styleguides_management.php)** - Styleguide management examples
    - Create, list, get, update, delete styleguides
    - Update name, content, or both at once
    - Handling of non-existent styleguides

```
cd examples
php styleguides_management.php
```

🔧 API Reference
---------------

[](#-api-reference)

### Core Components

[](#core-components)

### 🔐 Authentication

[](#-authentication)

The SDK supports authentication via access key and secret:

```
$credentials = new LaraCredentials("your-access-key-id", "your-access-key-secret");
$lara = new Translator($credentials);
```

**Environment Variables (Recommended):**

```
export LARA_ACCESS_KEY_ID="your-access-key-id"
export LARA_ACCESS_KEY_SECRET="your-access-key-secret"
```

```
$credentials = new LaraCredentials(
    getenv('LARA_ACCESS_KEY_ID'),
    getenv('LARA_ACCESS_KEY_SECRET')
);
```

### 🌍 Translator

[](#-translator)

```
// Create translator with credentials
$lara = new Translator($credentials);
```

#### Text Translation

[](#text-translation-1)

```
// Basic translation
$result = $lara->translate("Hello", "en-US", "fr-FR");

// Multiple strings
$result = $lara->translate(["Hello", "World"], "en-US", "fr-FR");

// TextBlocks (mixed translatable/non-translatable content)
use Lara\TextBlock;

$textBlocks = [
    new TextBlock('Translatable text', true),
    new TextBlock('', false),  // Non-translatable HTML
    new TextBlock('More translatable text', true),
];
$result = $lara->translate($textBlocks, "en-US", "fr-FR");

// With advanced options
$options = new TranslateOptions([
    'instructions' => ["Formal tone"],
    'adaptTo' => ["mem_1A2b3C4d5E6f7G8h9I0jKl"],  // Replace with actual memory IDs
    'glossaries' => ["gls_1A2b3C4d5E6f7G8h9I0jKl"],  // Replace with actual glossary IDs
    'style' => "fluid",
    'timeoutInMillis' => 10000
]);

$result = $lara->translate("Hello", "en-US", "fr-FR", $options);
```

#### Quality Estimation

[](#quality-estimation)

Use `qualityEstimation()` to score how well a translation matches its source. Pass a single sentence/translation pair to get a single result, or two parallel arrays to get one result per pair.

```
// Single pair
$single = $lara->qualityEstimation(
    "en-US",
    "it-IT",
    "Hello, how are you today?",
    "Ciao, come stai oggi?"
);
echo $single->getScore(); // e.g. 0.768

// Batch
$batch = $lara->qualityEstimation(
    "en-US",
    "it-IT",
    ["Good morning.", "The weather is nice."],
    ["Buongiorno.", "Il tempo è bello."]
);
foreach ($batch as $r) {
    echo $r->getScore() . "\n"; // e.g. 0.751, 0.713
}
```

### 📖 Document Translation

[](#-document-translation)

#### Simple document translation

[](#simple-document-translation)

```
$filePath = "/path/to/your/document.txt";  // Replace with actual file path
$fileStream = $lara->documents->translate($filePath, "en-US", "fr-FR");

// With options
$options = new DocumentTranslateOptions();
$options->setAdaptTo(["mem_1A2b3C4d5E6f7G8h9I0jKl"]);  // Replace with actual memory IDs
$options->setGlossaries(["gls_1A2b3C4d5E6f7G8h9I0jKl"]);  // Replace with actual glossary IDs

$fileStream = $lara->documents->translate($filePath, "en-US", "fr-FR", $options);
```

### Document translation with status monitoring

[](#document-translation-with-status-monitoring)

#### Document upload

[](#document-upload)

```
//Optional: upload options
$uploadOptions = new DocumentUploadOptions();
$uploadOptions->setAdaptTo(["mem_1A2b3C4d5E6f7G8h9I0jKl"]);  // Replace with actual memory IDs
$uploadOptions->setGlossaries(["gls_1A2b3C4d5E6f7G8h9I0jKl"]);  // Replace with actual glossary IDs

$document = $lara->documents->upload($filePath, "en-US", "fr-FR", $uploadOptions);
```

#### Document translation status monitoring

[](#document-translation-status-monitoring)

```
$status = $lara->documents->status($document->getId());
```

#### Download translated document

[](#download-translated-document)

```
$downloadOptions = new DocumentDownloadOptions();

$fileStream = $lara->documents->download($document->getId(), $downloadOptions);
```

### 🖼️ Image Translation

[](#️-image-translation)

```
use Lara\ImageTranslationOptions;
use Lara\ImageTextTranslationOptions;

// Translate image and receive a translated image stream
$translatedImageStream = $lara->images->translate("/path/to/your/image.png", "en", "fr", new ImageTranslationOptions([
    'model' => 'inpainting',
    'style' => 'faithful'
]));

// Extract and translate text blocks from an image
$textBlocks = $lara->images->translateText("/path/to/your/image.png", "en", "fr", new ImageTextTranslationOptions([
    'adaptTo' => ["mem_1A2b3C4d5E6f7G8h9I0jKl"],
    'glossaries' => ["gls_1A2b3C4d5E6f7G8h9I0jKl"],
]));
```

### 🧠 Memory Management

[](#-memory-management)

```
// Create memory
$memory = $lara->memories->create("MyMemory");

// Create memory with external ID (MyMemory integration)
$memory = $lara->memories->create("Memory from MyMemory", "aabb1122");  // Replace with actual external ID

// Important: To update/overwrite a translation unit you must provide a tuid. Calls without a tuid always create a new unit and will not update existing entries.
// Add translation to single memory
$memoryImport = $lara->memories->addTranslation("mem_1A2b3C4d5E6f7G8h9I0jKl", "en-US", "fr-FR", "Hello", "Bonjour", "greeting_001");

// Add translation to multiple memories
$memoryImport = $lara->memories->addTranslation(
    ["mem_1A2b3C4d5E6f7G8h9I0jKl", "mem_2XyZ9AbC8dEf7GhI6jKlMn"],  // Replace with actual memory IDs
    "en-US", "fr-FR", "Hello", "Bonjour", "greeting_002"
);

// Add with context
$memoryImport = $lara->memories->addTranslation(
    "mem_1A2b3C4d5E6f7G8h9I0jKl", "en-US", "fr-FR", "Hello", "Bonjour", "tuid",
    "sentenceBefore", "sentenceAfter"
);

// TMX import from file
$tmxFilePath = "/path/to/your/memory.tmx";  // Replace with actual TMX file path
$memoryImport = $lara->memories->importTmx("mem_1A2b3C4d5E6f7G8h9I0jKl", $tmxFilePath);

// TMX import with gzip compression
$memoryImport = $lara->memories->importTmx("mem_1A2b3C4d5E6f7G8h9I0jKl", $tmxFilePath, true);

// TMX import with a callback URL (notified when the import completes)
$memoryImport = $lara->memories->importTmx(
    "mem_1A2b3C4d5E6f7G8h9I0jKl",
    $tmxFilePath,
    false,
    "https://your-server.example.com/lara/import-callback"
);

// TMX import with both gzip compression and a callback URL
$memoryImport = $lara->memories->importTmx(
    "mem_1A2b3C4d5E6f7G8h9I0jKl",
    $tmxFilePath,
    true,
    "https://your-server.example.com/lara/import-callback"
);

// Async memory export - returns a job ID; the result is delivered to your callback URL when ready
$exportJob = $lara->memories->exportAsync(
    "mem_1A2b3C4d5E6f7G8h9I0jKl",
    "https://your-server.example.com/lara/export-callback",
    "tmx" // optional, defaults to the server-side default ("tmx" or "jtm")
);
$jobId = $exportJob->getJobId();

// Delete translation
// Important: if you omit tuid, all entries that match the provided fields will be removed
$deleteJob = $lara->memories->deleteTranslation(
    "mem_1A2b3C4d5E6f7G8h9I0jKl", "en-US", "fr-FR", "Hello", "Bonjour", "greeting_001"
);

// Wait for import completion
$completedImport = $lara->memories->waitForImport($memoryImport, 300); // 5 minutes
```

### 📚 Glossary Management

[](#-glossary-management)

```
// Create glossary
$glossary = $lara->glossaries->create("MyGlossary");

// Import CSV from file
$csvFilePath = "/path/to/your/glossary.csv";  // Replace with actual CSV file path
$glossaryImport = $lara->glossaries->importCsv("gls_1A2b3C4d5E6f7G8h9I0jKl", $csvFilePath);

// Check import status
$importStatus = $lara->glossaries->getImportStatus($glossaryImport->getId());

// Wait for import completion
$completedImport = $lara->glossaries->waitForImport($glossaryImport, 300); // 5 minutes

// Export glossary
$csvData = $lara->glossaries->export("gls_1A2b3C4d5E6f7G8h9I0jKl", "csv/table-uni", "en-US");

// Async glossary export - returns a job ID; the result is delivered to your callback URL when ready
$exportJob = $lara->glossaries->exportAsync(
    "gls_1A2b3C4d5E6f7G8h9I0jKl",
    "https://your-server.example.com/lara/export-callback",
    "csv/table-uni",
    "en-US"
);
$jobId = $exportJob->getJobId();

// Get glossary terms count
$counts = $lara->glossaries->counts("gls_1A2b3C4d5E6f7G8h9I0jKl");
```

### 📋 Styleguide Management

[](#-styleguide-management)

```
// Create styleguide
$styleguide = $lara->styleguides->create("MyStyleguide", "Always use formal language.");

// List all styleguides
$styleguides = $lara->styleguides->getAll();

// Get a specific styleguide
$styleguide = $lara->styleguides->get("stg_1A2b3C4d5E6f7G8h9I0jKl");

// Update styleguide — pass null for fields you don't want to change
// Update only the name
$styleguide = $lara->styleguides->update("stg_1A2b3C4d5E6f7G8h9I0jKl", "UpdatedStyleguide");

// Update only the content
$styleguide = $lara->styleguides->update("stg_1A2b3C4d5E6f7G8h9I0jKl", null, "Always use informal language.");

// Update both
$styleguide = $lara->styleguides->update("stg_1A2b3C4d5E6f7G8h9I0jKl", "UpdatedStyleguide", "Always use informal language.");

// Delete styleguide
$styleguide = $lara->styleguides->delete("stg_1A2b3C4d5E6f7G8h9I0jKl");
```

### Translation Options

[](#translation-options)

```
// Constructor array pattern (recommended)
$options = new TranslateOptions([
    'adaptTo' => ["mem_1A2b3C4d5E6f7G8h9I0jKl"],              // Memory IDs to adapt to
    'glossaries' => ["gls_1A2b3C4d5E6f7G8h9I0jKl"],           // Glossary IDs to use
    'instructions' => ["instruction"],                        // Translation instructions
    'style' => "fluid",                                       // Translation style (fluid, faithful, creative)
    'contentType' => "text/plain",                            // Content type (text/plain, text/html, etc.)
    'multiline' => true,                                      // Enable multiline translation
    'timeoutInMillis' => 10000,                               // Request timeout in milliseconds
    'sourceHint' => "en",                                     // Hint for source language detection
    'noTrace' => false,                                       // Disable request tracing
    'verbose' => false,                                       // Enable verbose response
]);

// Alternative setter pattern
$options = new TranslateOptions();
$options->setSourceHint("en-US");
$options->setAdaptTo(["mem_1A2b3C4d5E6f7G8h9I0jKl", "mem_2XyZ9AbC8dEf7GhI6jKlMn"]);  // Replace with actual memory IDs
$options->setInstructions(["Formal tone", "Use technical terminology"]);
$options->setGlossaries(["gls_1A2b3C4d5E6f7G8h9I0jKl", "gls_2XyZ9AbC8dEf7GhI6jKlMn"]);  // Replace with actual glossary IDs
$options->setContentType("text/html");
$options->setMultiline(true);
$options->setTimeoutInMillis(15000);
$options->setNoTrace(false);
$options->setVerbose(true);
$options->setStyle("faithful");
```

### Language Codes

[](#language-codes)

The SDK supports full language codes (e.g., `en-US`, `fr-FR`, `es-ES`) as well as simple codes (e.g., `en`, `fr`, `es`):

```
// Full language codes (recommended)
$result = $lara->translate("Hello", "en-US", "fr-FR");

// Simple language codes
$result = $lara->translate("Hello", "en", "fr");
```

### 🌐 Supported Languages

[](#-supported-languages)

The SDK supports all languages available in the Lara API. Use the `getLanguages()` method to get the current list:

```
$languages = $lara->getLanguages();
echo "Supported languages: " . implode(', ', $languages) . PHP_EOL;
```

⚙️ Configuration
----------------

[](#️-configuration)

### Error Handling

[](#error-handling)

The SDK provides detailed error information:

```
try {
    $result = $lara->translate("Hello", "en-US", "fr-FR");
    echo "Translation: " . $result->getTranslation() . PHP_EOL;
} catch (LaraException $e) {
    echo "API Error: " . $e->getMessage() . PHP_EOL;
} catch (LaraTimeoutException $e) {
    echo "Timeout Error: " . $e->getMessage() . PHP_EOL;
}
```

📋 Requirements
--------------

[](#-requirements)

- PHP 7.4 or higher
- Composer
- Valid Lara API credentials

🧪 Testing
---------

[](#-testing)

Run the examples to test your setup:

```
# All examples use environment variables for credentials, so set them first:
export LARA_ACCESS_KEY_ID="your-access-key-id"
export LARA_ACCESS_KEY_SECRET="your-access-key-secret"
```

```
# Run basic text translation example
cd examples
php text_translation.php
```

📄 License
---------

[](#-license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Happy translating! 🌍✨

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance92

Actively maintained with recent releases

Popularity33

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~10 days

Total

23

Last Release

21d ago

Major Versions

0.0.1 → 1.0.02024-12-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/eba17b14fdf8497bfa0156bd48dcb1b57c03985e7c151f263d5b5869462568b5?d=identicon)[translated](/maintainers/translated)

---

Top Contributors

[![f4b1ux](https://avatars.githubusercontent.com/u/44729888?v=4)](https://github.com/f4b1ux "f4b1ux (28 commits)")[![spirokristollari](https://avatars.githubusercontent.com/u/48963860?v=4)](https://github.com/spirokristollari "spirokristollari (17 commits)")[![davidecaroselli](https://avatars.githubusercontent.com/u/1674891?v=4)](https://github.com/davidecaroselli "davidecaroselli (14 commits)")[![davc0n](https://avatars.githubusercontent.com/u/57829860?v=4)](https://github.com/davc0n "davc0n (7 commits)")[![ikhimenko](https://avatars.githubusercontent.com/u/49020902?v=4)](https://github.com/ikhimenko "ikhimenko (2 commits)")[![giastfader](https://avatars.githubusercontent.com/u/2334584?v=4)](https://github.com/giastfader "giastfader (1 commits)")[![Ostico](https://avatars.githubusercontent.com/u/8008416?v=4)](https://github.com/Ostico "Ostico (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/translated-lara-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/translated-lara-sdk/health.svg)](https://phpackages.com/packages/translated-lara-sdk)
```

###  Alternatives

[prewk/result

Result object for PHP inspired by Rust

121950.9k13](/packages/prewk-result)[shaozeming/aliyun-sts

基于阿里云openapi系列接口中STS最新版本的SDK进行封装的composer package

2021.1k1](/packages/shaozeming-aliyun-sts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
