Skip to content

Commit b6d4f7d

Browse files
Simplify workflow, remove demo dir, enhance README with usage examples and release process
Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>
1 parent 0d63be7 commit b6d4f7d

File tree

7 files changed

+139
-241
lines changed

7 files changed

+139
-241
lines changed

.github/workflows/publish.yml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ permissions:
1010
contents: write
1111

1212
jobs:
13-
test:
13+
test-and-publish:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout code
1717
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
1820

1921
- name: Setup PHP
2022
uses: shivammathur/setup-php@v2
@@ -33,26 +35,10 @@ jobs:
3335
- name: Run tests
3436
run: vendor/bin/phpunit tests/
3537

36-
publish:
37-
needs: test
38-
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
39-
runs-on: ubuntu-latest
40-
steps:
41-
- name: Checkout code
42-
uses: actions/checkout@v3
43-
with:
44-
fetch-depth: 0
45-
46-
- name: Setup PHP
47-
uses: shivammathur/setup-php@v2
48-
with:
49-
php-version: '8.1'
50-
extensions: mbstring, intl
51-
coverage: none
52-
tools: composer:v2
53-
38+
# Only proceed with version bump and publishing if on main branch and tests passed
5439
- name: Get current version
5540
id: current_version
41+
if: success() && (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch')
5642
run: |
5743
# Check if version exists in composer.json
5844
VERSION=$(php -r '
@@ -69,6 +55,7 @@ jobs:
6955
7056
- name: Bump patch version
7157
id: bump_version
58+
if: success() && (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch')
7259
run: |
7360
# Get current version
7461
CURRENT_VERSION=${{ steps.current_version.outputs.version }}
@@ -101,18 +88,21 @@ jobs:
10188
10289
- name: Commit and push version bump
10390
uses: stefanzweifel/git-auto-commit-action@v4
91+
if: success() && (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch')
10492
with:
10593
commit_message: "chore: bump PHP SDK version to ${{ steps.bump_version.outputs.new_version }}"
10694
file_pattern: composer.json
10795
commit_user_name: "Lingo.dev"
10896
commit_user_email: "hi@lingo.dev"
10997

11098
- name: Create tag for release
99+
if: success() && (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch')
111100
run: |
112101
git tag v${{ steps.bump_version.outputs.new_version }}
113102
git push origin v${{ steps.bump_version.outputs.new_version }}
114103
115104
- name: Publish to Packagist
105+
if: success() && (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch')
116106
run: |
117107
php scripts/packagist-publish.php
118108
env:

README.md

Lines changed: 130 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,174 @@
11
# Lingo.dev PHP SDK
22

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.
44

55
## Installation
66

7+
You can install the SDK via Composer:
8+
79
```bash
810
composer require lingodotdev/sdk
911
```
1012

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
1223

1324
```php
1425
<?php
1526

16-
use Lingodotdev\Sdk\LingoDotDevEngine;
27+
use LingoDotDev\Sdk\LingoDotDevEngine;
1728

1829
// Initialize the SDK with your API key
1930
$engine = new LingoDotDevEngine([
2031
'apiKey' => 'your-api-key',
2132
]);
33+
```
34+
35+
### Text Localization
2236

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
2441
$localizedText = $engine->localizeText('Hello, world!', [
2542
'sourceLocale' => 'en',
2643
'targetLocale' => 'es',
2744
]);
45+
// Output: "¡Hola, mundo!"
46+
```
2847

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
3054
$localizedObject = $engine->localizeObject([
3155
'greeting' => 'Hello',
32-
'farewell' => 'Goodbye'
56+
'farewell' => 'Goodbye',
57+
'messages' => [
58+
'welcome' => 'Welcome to our service',
59+
'thanks' => 'Thank you for your business'
60+
]
3361
], [
3462
'sourceLocale' => 'en',
3563
'targetLocale' => 'fr',
3664
]);
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:
3780

38-
// Localize a chat conversation
81+
```php
82+
// Localize a chat conversation from English to German
3983
$localizedChat = $engine->localizeChat([
4084
['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?']
4287
], [
4388
'sourceLocale' => 'en',
4489
'targetLocale' => 'de',
4590
]);
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
46101

102+
Detect the language of a given text:
103+
104+
```php
47105
// Detect language
48106
$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+
]);
49155
```
50156

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+
51168
## Documentation
52169

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.

demo/.env.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

demo/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

demo/README.md

Lines changed: 0 additions & 106 deletions
This file was deleted.

demo/composer.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)