|
1 | 1 | # Lingo.dev PHP SDK |
2 | 2 |
|
3 | | -Official PHP SDK for Lingo.dev. |
| 3 | +Official PHP SDK for Lingo.dev, a powerful localization engine that supports various content types including plain text, objects, and chat sequences. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
| 7 | +You can install the SDK via Composer: |
| 8 | + |
7 | 9 | ```bash |
8 | 10 | composer require lingodotdev/sdk |
9 | 11 | ``` |
10 | 12 |
|
11 | | -## Usage |
| 13 | +## Requirements |
| 14 | + |
| 15 | +- PHP 8.1 or higher |
| 16 | +- Composer |
| 17 | +- GuzzleHttp Client |
| 18 | +- Respect Validation |
| 19 | + |
| 20 | +## Basic Usage |
| 21 | + |
| 22 | +### Initialize the SDK |
12 | 23 |
|
13 | 24 | ```php |
14 | 25 | <?php |
15 | 26 |
|
16 | | -use Lingodotdev\Sdk\LingoDotDevEngine; |
| 27 | +use LingoDotDev\Sdk\LingoDotDevEngine; |
17 | 28 |
|
18 | 29 | // Initialize the SDK with your API key |
19 | 30 | $engine = new LingoDotDevEngine([ |
20 | 31 | 'apiKey' => 'your-api-key', |
21 | 32 | ]); |
| 33 | +``` |
| 34 | + |
| 35 | +### Text Localization |
22 | 36 |
|
23 | | -// Localize a text string |
| 37 | +Translate a simple text string from one language to another: |
| 38 | + |
| 39 | +```php |
| 40 | +// Localize a text string from English to Spanish |
24 | 41 | $localizedText = $engine->localizeText('Hello, world!', [ |
25 | 42 | 'sourceLocale' => 'en', |
26 | 43 | 'targetLocale' => 'es', |
27 | 44 | ]); |
| 45 | +// Output: "¡Hola, mundo!" |
| 46 | +``` |
28 | 47 |
|
29 | | -// Localize an object |
| 48 | +### Object Localization |
| 49 | + |
| 50 | +Translate an array of strings while preserving the structure: |
| 51 | + |
| 52 | +```php |
| 53 | +// Localize an object from English to French |
30 | 54 | $localizedObject = $engine->localizeObject([ |
31 | 55 | 'greeting' => 'Hello', |
32 | | - 'farewell' => 'Goodbye' |
| 56 | + 'farewell' => 'Goodbye', |
| 57 | + 'messages' => [ |
| 58 | + 'welcome' => 'Welcome to our service', |
| 59 | + 'thanks' => 'Thank you for your business' |
| 60 | + ] |
33 | 61 | ], [ |
34 | 62 | 'sourceLocale' => 'en', |
35 | 63 | 'targetLocale' => 'fr', |
36 | 64 | ]); |
| 65 | +/* Output: |
| 66 | +[ |
| 67 | + 'greeting' => 'Bonjour', |
| 68 | + 'farewell' => 'Au revoir', |
| 69 | + 'messages' => [ |
| 70 | + 'welcome' => 'Bienvenue dans notre service', |
| 71 | + 'thanks' => 'Merci pour votre confiance' |
| 72 | + ] |
| 73 | +] |
| 74 | +*/ |
| 75 | +``` |
| 76 | + |
| 77 | +### Chat Localization |
| 78 | + |
| 79 | +Translate a chat conversation while preserving speaker names: |
37 | 80 |
|
38 | | -// Localize a chat conversation |
| 81 | +```php |
| 82 | +// Localize a chat conversation from English to German |
39 | 83 | $localizedChat = $engine->localizeChat([ |
40 | 84 | ['name' => 'Alice', 'text' => 'Hello, how are you?'], |
41 | | - ['name' => 'Bob', 'text' => 'I am fine, thank you!'] |
| 85 | + ['name' => 'Bob', 'text' => 'I am fine, thank you!'], |
| 86 | + ['name' => 'Alice', 'text' => 'What are you doing today?'] |
42 | 87 | ], [ |
43 | 88 | 'sourceLocale' => 'en', |
44 | 89 | 'targetLocale' => 'de', |
45 | 90 | ]); |
| 91 | +/* Output: |
| 92 | +[ |
| 93 | + ['name' => 'Alice', 'text' => 'Hallo, wie geht es dir?'], |
| 94 | + ['name' => 'Bob', 'text' => 'Mir geht es gut, danke!'], |
| 95 | + ['name' => 'Alice', 'text' => 'Was machst du heute?'] |
| 96 | +] |
| 97 | +*/ |
| 98 | +``` |
| 99 | + |
| 100 | +### Language Detection |
46 | 101 |
|
| 102 | +Detect the language of a given text: |
| 103 | + |
| 104 | +```php |
47 | 105 | // Detect language |
48 | 106 | $locale = $engine->recognizeLocale('Bonjour le monde'); |
| 107 | +// Output: "fr" |
| 108 | +``` |
| 109 | + |
| 110 | +### Batch Localization |
| 111 | + |
| 112 | +Translate a text to multiple languages at once: |
| 113 | + |
| 114 | +```php |
| 115 | +// Batch localize text to multiple languages |
| 116 | +$localizedTexts = $engine->batchLocalizeText('Hello, world!', [ |
| 117 | + 'sourceLocale' => 'en', |
| 118 | + 'targetLocales' => ['es', 'fr', 'de', 'it'], |
| 119 | +]); |
| 120 | +/* Output: |
| 121 | +[ |
| 122 | + "¡Hola, mundo!", |
| 123 | + "Bonjour le monde!", |
| 124 | + "Hallo, Welt!", |
| 125 | + "Ciao, mondo!" |
| 126 | +] |
| 127 | +*/ |
| 128 | +``` |
| 129 | + |
| 130 | +### Progress Tracking |
| 131 | + |
| 132 | +Track the progress of a localization operation: |
| 133 | + |
| 134 | +```php |
| 135 | +// Localize with progress tracking |
| 136 | +$engine->localizeText('Hello, world!', [ |
| 137 | + 'sourceLocale' => 'en', |
| 138 | + 'targetLocale' => 'es', |
| 139 | +], function ($progress, $chunk, $processedChunk) { |
| 140 | + echo "Localization progress: $progress%\n"; |
| 141 | +}); |
| 142 | +``` |
| 143 | + |
| 144 | +## Advanced Configuration |
| 145 | + |
| 146 | +You can customize the SDK behavior with additional configuration options: |
| 147 | + |
| 148 | +```php |
| 149 | +$engine = new LingoDotDevEngine([ |
| 150 | + 'apiKey' => 'your-api-key', |
| 151 | + 'apiUrl' => 'https://custom-engine.lingo.dev', // Custom API URL |
| 152 | + 'batchSize' => 50, // Custom batch size (1-250) |
| 153 | + 'idealBatchItemSize' => 500 // Custom batch item size (1-2500) |
| 154 | +]); |
49 | 155 | ``` |
50 | 156 |
|
| 157 | +## Release Process |
| 158 | + |
| 159 | +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: |
| 160 | + |
| 161 | +1. Running tests to ensure code quality |
| 162 | +2. Automatically bumping the patch version |
| 163 | +3. Creating a git tag for the new version |
| 164 | +4. Publishing the package to Packagist |
| 165 | + |
| 166 | +Packagist automatically fetches new versions from the GitHub repository when tags are pushed, making the new version immediately available for installation via Composer. |
| 167 | + |
51 | 168 | ## Documentation |
52 | 169 |
|
53 | | -[Documentation](https://lingo.dev/go/docs) |
| 170 | +For more detailed documentation, visit the [Lingo.dev Documentation](https://lingo.dev/go/docs). |
| 171 | + |
| 172 | +## License |
| 173 | + |
| 174 | +This SDK is released under the MIT License. |
0 commit comments