Skip to content

Commit f76feba

Browse files
authored
feat: vNext migration (#11)
* feat: vNext migration * feat: make engineId optional, use single /process/localize endpoint
1 parent cde45bd commit f76feba

File tree

5 files changed

+498
-121
lines changed

5 files changed

+498
-121
lines changed

README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ require 'vendor/autoload.php';
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', // optional — override the default engine
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 | No || 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

@@ -77,6 +87,7 @@ use LingoDotDev\Sdk\LingoDotDevEngine;
7787
// Initialize the SDK with your API key
7888
$engine = new LingoDotDevEngine([
7989
'apiKey' => 'your-api-key',
90+
'engineId' => 'your-engine-id', // optional
8091
]);
8192
```
8293

@@ -122,6 +133,21 @@ $localizedObject = $engine->localizeObject([
122133
*/
123134
```
124135

136+
You can pass a reference to provide additional context:
137+
138+
```php
139+
// Localize with reference for additional context
140+
$localizedObject = $engine->localizeObject([
141+
'greeting' => 'Hello',
142+
], [
143+
'sourceLocale' => 'en',
144+
'targetLocale' => 'es',
145+
'reference' => [
146+
'fr' => ['greeting' => 'Bonjour']
147+
],
148+
]);
149+
```
150+
125151
### Chat Localization
126152

127153
Translate a chat conversation while preserving speaker names:
@@ -184,20 +210,20 @@ Track the progress of a localization operation:
184210
$engine->localizeText('Hello, world!', [
185211
'sourceLocale' => 'en',
186212
'targetLocale' => 'es',
187-
], function ($progress, $chunk, $processedChunk) {
213+
], function ($progress) {
188214
echo "Localization progress: $progress%\n";
189215
});
190216
```
191217

192218
## Demo App
193219

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`.
220+
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 optionally `LINGODOTDEV_ENGINE_ID`), and run `php index.php`.
195221

196222
Want to see everything in action?
197223

198224
1. Clone this repository or copy the `index.php` from the **demo** below into an empty directory.
199225
2. Run `composer install` to pull in the SDK.
200-
3. Populate the `LINGODOTDEV_API_KEY` environment variable with your key.
226+
3. Populate the `LINGODOTDEV_API_KEY` environment variable (and optionally `LINGODOTDEV_ENGINE_ID`).
201227
4. Execute the script with `php index.php` and observe the output.
202228

203229
`index.php` demo:
@@ -209,24 +235,26 @@ require 'vendor/autoload.php';
209235

210236
use LingoDotDev\Sdk\LingoDotDevEngine;
211237

212-
$engine = new LingoDotDevEngine([
238+
$config = [
213239
'apiKey' => getenv('LINGODOTDEV_API_KEY'),
214-
]);
240+
];
241+
if (getenv('LINGODOTDEV_ENGINE_ID')) {
242+
$config['engineId'] = getenv('LINGODOTDEV_ENGINE_ID');
243+
}
244+
$engine = new LingoDotDevEngine($config);
215245

216246
// 1. Text
217247
$helloEs = $engine->localizeText('Hello world!', [
218248
'sourceLocale' => 'en',
219249
'targetLocale' => 'es',
220250
]);
221-
222-
echo "Text ES ⇒ $helloEs\n\n";
251+
echo "Text ES: $helloEs\n\n";
223252

224253
// 2. Object
225-
$object = [
254+
$objectFr = $engine->localizeObject([
226255
'greeting' => 'Good morning',
227256
'farewell' => 'Good night',
228-
];
229-
$objectFr = $engine->localizeObject($object, [
257+
], [
230258
'sourceLocale' => 'en',
231259
'targetLocale' => 'fr',
232260
]);
@@ -244,7 +272,6 @@ print_r($chatJa);
244272

245273
// 4. Detect language
246274
$lang = $engine->recognizeLocale('Ciao mondo');
247-
248275
echo "Detected: $lang\n";
249276
```
250277

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)