PHP code example of lingodotdev / sdk

1. Go to this page and download the library: Download lingodotdev/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/ */

    

lingodotdev / sdk example snippets




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
]);



use LingoDotDev\Sdk\LingoDotDevEngine;

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

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

// 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'
    ]
]
*/

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

// 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?']
]
*/

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

// 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!"
]
*/

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



ingoDotDev\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";
bash
   composer init --name=your-vendor/your-project --description="Your project description" --type=project --