Skip to content

Commit 0533ab1

Browse files
committed
feat: vNext migration
1 parent cde45bd commit 0533ab1

File tree

5 files changed

+455
-120
lines changed

5 files changed

+455
-120
lines changed

README.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ composer require lingodotdev/sdk
1212

1313
## Basic Usage
1414

15-
After installing the package, bootstrap the engine with your API key:
15+
After installing the package, bootstrap the engine with your API key and Engine ID:
1616

1717
```php
1818
require 'vendor/autoload.php';
1919

2020
use LingoDotDev\Sdk\LingoDotDevEngine;
2121

2222
$engine = new LingoDotDevEngine([
23-
'apiKey' => 'your-api-key', // replace with your actual key
23+
'apiKey' => 'your-api-key', // replace with your actual key
24+
'engineId' => 'your-engine-id', // replace with your actual engine id
2425
]);
2526
```
2627

28+
### Configuration Options
29+
30+
| Option | Type | Required | Default | Description |
31+
|---|---|---|---|---|
32+
| `apiKey` | string | Yes || Your Lingo.dev API key |
33+
| `engineId` | string | Yes || Your Lingo.dev Engine ID |
34+
| `apiUrl` | string | No | `https://api.lingo.dev` | API base URL |
35+
| `batchSize` | int | No | `25` | Max items per chunk (1–250) |
36+
| `idealBatchItemSize` | int | No | `250` | Max words per chunk (1–2500) |
37+
2738
### Scenarios demonstrated in this README
2839

2940
1. Text Localization
@@ -38,7 +49,6 @@ $engine = new LingoDotDevEngine([
3849
- PHP 8.1 or higher
3950
- Composer
4051
- GuzzleHttp Client
41-
- Respect Validation
4252

4353
## Getting Started
4454

@@ -74,9 +84,10 @@ Follow these steps to create a new PHP project that uses the Lingo.dev SDK:
7484

7585
use LingoDotDev\Sdk\LingoDotDevEngine;
7686

77-
// Initialize the SDK with your API key
87+
// Initialize the SDK with your API key and Engine ID
7888
$engine = new LingoDotDevEngine([
7989
'apiKey' => 'your-api-key',
90+
'engineId' => 'your-engine-id',
8091
]);
8192
```
8293

@@ -93,6 +104,17 @@ $localizedText = $engine->localizeText('Hello, world!', [
93104
// Output: "¡Hola, mundo!"
94105
```
95106

107+
You can enable fast mode for quicker (but potentially lower quality) translations:
108+
109+
```php
110+
// Localize with fast mode enabled
111+
$localizedText = $engine->localizeText('Hello, world!', [
112+
'sourceLocale' => 'en',
113+
'targetLocale' => 'es',
114+
'fast' => true,
115+
]);
116+
```
117+
96118
### Object Localization
97119

98120
Translate an array of strings while preserving the structure:
@@ -122,6 +144,21 @@ $localizedObject = $engine->localizeObject([
122144
*/
123145
```
124146

147+
You can pass a reference to provide additional context:
148+
149+
```php
150+
// Localize with reference for additional context
151+
$localizedObject = $engine->localizeObject([
152+
'greeting' => 'Hello',
153+
], [
154+
'sourceLocale' => 'en',
155+
'targetLocale' => 'es',
156+
'reference' => [
157+
'fr' => ['greeting' => 'Bonjour']
158+
],
159+
]);
160+
```
161+
125162
### Chat Localization
126163

127164
Translate a chat conversation while preserving speaker names:
@@ -184,20 +221,20 @@ Track the progress of a localization operation:
184221
$engine->localizeText('Hello, world!', [
185222
'sourceLocale' => 'en',
186223
'targetLocale' => 'es',
187-
], function ($progress, $chunk, $processedChunk) {
224+
], function ($progress) {
188225
echo "Localization progress: $progress%\n";
189226
});
190227
```
191228

192229
## Demo App
193230

194-
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 run `php index.php`.
231+
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 `LINGODOTDEV_ENGINE_ID`, and run `php index.php`.
195232

196233
Want to see everything in action?
197234

198235
1. Clone this repository or copy the `index.php` from the **demo** below into an empty directory.
199236
2. Run `composer install` to pull in the SDK.
200-
3. Populate the `LINGODOTDEV_API_KEY` environment variable with your key.
237+
3. Populate the `LINGODOTDEV_API_KEY` and `LINGODOTDEV_ENGINE_ID` environment variables.
201238
4. Execute the script with `php index.php` and observe the output.
202239

203240
`index.php` demo:
@@ -211,22 +248,21 @@ use LingoDotDev\Sdk\LingoDotDevEngine;
211248

212249
$engine = new LingoDotDevEngine([
213250
'apiKey' => getenv('LINGODOTDEV_API_KEY'),
251+
'engineId' => getenv('LINGODOTDEV_ENGINE_ID'),
214252
]);
215253

216254
// 1. Text
217255
$helloEs = $engine->localizeText('Hello world!', [
218256
'sourceLocale' => 'en',
219257
'targetLocale' => 'es',
220258
]);
221-
222-
echo "Text ES ⇒ $helloEs\n\n";
259+
echo "Text ES: $helloEs\n\n";
223260

224261
// 2. Object
225-
$object = [
262+
$objectFr = $engine->localizeObject([
226263
'greeting' => 'Good morning',
227264
'farewell' => 'Good night',
228-
];
229-
$objectFr = $engine->localizeObject($object, [
265+
], [
230266
'sourceLocale' => 'en',
231267
'targetLocale' => 'fr',
232268
]);
@@ -244,7 +280,6 @@ print_r($chatJa);
244280

245281
// 4. Detect language
246282
$lang = $engine->recognizeLocale('Ciao mondo');
247-
248283
echo "Detected: $lang\n";
249284
```
250285

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
],
1212
"require": {
1313
"php": "^8.1",
14-
"guzzlehttp/guzzle": "^7.0",
15-
"respect/validation": "^2.0"
14+
"guzzlehttp/guzzle": "^7.0"
1615
},
1716
"require-dev": {
1817
"phpunit/phpunit": "^9.0"

0 commit comments

Comments
 (0)