Skip to content

Commit 4c292f1

Browse files
docs: update readme
1 parent 4456354 commit 4c292f1

File tree

1 file changed

+88
-46
lines changed

1 file changed

+88
-46
lines changed

README.md

Lines changed: 88 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ You can install the SDK via Composer:
1010
composer require lingodotdev/sdk
1111
```
1212

13+
## Basic Usage
14+
15+
After installing the package, bootstrap the engine with your API key:
16+
17+
```php
18+
require 'vendor/autoload.php';
19+
20+
use LingoDotDev\Sdk\LingoDotDevEngine;
21+
22+
$engine = new LingoDotDevEngine([
23+
'apiKey' => 'your-api-key', // replace with your actual key
24+
]);
25+
```
26+
27+
### Scenarios demonstrated in this README
28+
29+
1. Text Localization
30+
2. Object Localization
31+
3. Chat Localization
32+
4. Batch Localization
33+
5. Language Detection
34+
6. Progress Tracking
35+
1336
## Requirements
1437

1538
- PHP 8.1 or higher
@@ -24,67 +47,25 @@ composer require lingodotdev/sdk
2447
Follow these steps to create a new PHP project that uses the Lingo.dev SDK:
2548

2649
1. **Create a project directory**:
50+
2751
```bash
2852
mkdir my-lingo-project
2953
cd my-lingo-project
3054
```
3155

3256
2. **Initialize Composer**:
57+
3358
```bash
3459
composer init --name=your-vendor/your-project --description="Your project description" --type=project --require="php:^8.1" --author="Your Name <your.email@example.com>"
3560
```
3661

3762
3. **Add Lingo.dev SDK as a dependency**:
63+
3864
```bash
3965
composer require lingodotdev/sdk
4066
```
4167

42-
4. **Create a simple PHP script** (index.php):
43-
```php
44-
<?php
45-
46-
require 'vendor/autoload.php';
47-
48-
use LingoDotDev\Sdk\LingoDotDevEngine;
49-
50-
// Get API key from environment variable or command line
51-
$apiKey = getenv('LINGODOTDEV_API_KEY') ?: $argv[1] ?? null;
52-
53-
if (!$apiKey) {
54-
echo "Error: API key is required. Set LINGODOTDEV_API_KEY environment variable or pass it as a command-line argument.\n";
55-
exit(1);
56-
}
57-
58-
// Initialize the SDK
59-
$engine = new LingoDotDevEngine([
60-
'apiKey' => $apiKey,
61-
]);
62-
63-
// Make your first localization call
64-
try {
65-
$result = $engine->localizeText('Hello, this is my first localization with Lingo.dev!', [
66-
'sourceLocale' => 'en',
67-
'targetLocale' => 'es',
68-
]);
69-
70-
echo "Original: Hello, this is my first localization with Lingo.dev!\n";
71-
echo "Translated to Spanish: $result\n";
72-
} catch (\Exception $e) {
73-
echo "Error: " . $e->getMessage() . "\n";
74-
}
75-
```
76-
77-
5. **Run your script**:
78-
```bash
79-
# Option 1: Pass API key as command-line argument
80-
php index.php your-api-key-here
81-
82-
# Option 2: Set environment variable and run
83-
export LINGODOTDEV_API_KEY=your-api-key-here
84-
php index.php
85-
```
86-
87-
## Basic Usage
68+
## API Scenarios
8869

8970
### Initialize the SDK
9071

@@ -208,6 +189,67 @@ $engine->localizeText('Hello, world!', [
208189
});
209190
```
210191

192+
## Demo App
193+
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`.
195+
196+
Want to see everything in action?
197+
198+
1. Clone this repository or copy the `index.php` from the **demo** below into an empty directory.
199+
2. Run `composer install` to pull in the SDK.
200+
3. Populate the `LINGODOTDEV_API_KEY` environment variable with your key.
201+
4. Execute the script with `php index.php` and observe the output.
202+
203+
`index.php` demo:
204+
205+
```php
206+
<?php
207+
208+
require 'vendor/autoload.php';
209+
210+
use LingoDotDev\Sdk\LingoDotDevEngine;
211+
212+
$engine = new LingoDotDevEngine([
213+
'apiKey' => getenv('LINGODOTDEV_API_KEY'),
214+
]);
215+
216+
// 1. Text
217+
$helloEs = $engine->localizeText('Hello world!', [
218+
'sourceLocale' => 'en',
219+
'targetLocale' => 'es',
220+
]);
221+
222+
echo "Text ES ⇒ $helloEs\n\n";
223+
224+
// 2. Object
225+
$object = [
226+
'greeting' => 'Good morning',
227+
'farewell' => 'Good night',
228+
];
229+
$objectFr = $engine->localizeObject($object, [
230+
'sourceLocale' => 'en',
231+
'targetLocale' => 'fr',
232+
]);
233+
print_r($objectFr);
234+
235+
// 3. Chat
236+
$chatJa = $engine->localizeChat([
237+
['name' => 'Alice', 'text' => 'Hi'],
238+
['name' => 'Bob', 'text' => 'Hello!'],
239+
], [
240+
'sourceLocale' => 'en',
241+
'targetLocale' => 'ja',
242+
]);
243+
print_r($chatJa);
244+
245+
// 4. Detect language
246+
$lang = $engine->recognizeLocale('Ciao mondo');
247+
248+
echo "Detected: $lang\n";
249+
```
250+
251+
---
252+
211253
## Release Process
212254

213255
The SDK uses semantic versioning (MAJOR.MINOR.PATCH) and is automatically published to Packagist when changes are merged to the main branch. The release process includes:

0 commit comments

Comments
 (0)