Skip to content

Commit d6d0872

Browse files
feat: add PHP SDK implementation (#682)
* Add PHP SDK implementation with Packagist publishing workflow Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * feat: integrate PHP SDK with changesets system Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * feat: add php directory to workspace Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * chore: remove Replexica references and improve Packagist publishing workflow Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * chore: simplify PHP SDK publishing workflow Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * chore: simplify versioning and remove changesets integration Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * chore: remove LingoEngine for consistency Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * chore: use GitHub marketplace action for Packagist publishing Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> * chore: add test job and use git-auto-commit-action Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Max Prilutskiy <maks.prilutskiy@gmail.com>
1 parent 0f91e0a commit d6d0872

6 files changed

Lines changed: 702 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Publish PHP SDK to Packagist
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'php/sdk/**'
9+
workflow_dispatch:
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.0'
22+
extensions: mbstring, intl
23+
coverage: none
24+
tools: composer:v2
25+
26+
- name: Install dependencies
27+
working-directory: ./php/sdk
28+
run: composer install --prefer-dist
29+
30+
- name: Run tests
31+
working-directory: ./php/sdk
32+
run: composer test
33+
34+
- name: Check code style
35+
working-directory: ./php/sdk
36+
run: composer cs
37+
38+
publish:
39+
needs: test
40+
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v3
45+
with:
46+
fetch-depth: 0
47+
48+
- name: Setup PHP
49+
uses: shivammathur/setup-php@v2
50+
with:
51+
php-version: '8.0'
52+
extensions: mbstring, intl
53+
coverage: none
54+
tools: composer:v2, composer-semver
55+
56+
- name: Install dependencies
57+
working-directory: ./php/sdk
58+
run: composer install --no-dev --no-interaction --prefer-dist
59+
60+
- name: Get current version
61+
id: current_version
62+
run: |
63+
VERSION=$(php -r 'echo json_decode(file_get_contents("php/sdk/composer.json"), true)["version"];')
64+
echo "version=$VERSION" >> $GITHUB_OUTPUT
65+
66+
- name: Bump patch version
67+
id: bump_version
68+
run: |
69+
# Use composer-semver for version bumping (always patch for main branch pushes)
70+
NEW_VERSION=$(composer semver ${{ steps.current_version.outputs.version }} --increment=patch)
71+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
72+
73+
# Update version in composer.json
74+
php -r '
75+
$composerJson = json_decode(file_get_contents("php/sdk/composer.json"), true);
76+
$composerJson["version"] = "${{ steps.bump_version.outputs.new_version }}";
77+
file_put_contents("php/sdk/composer.json", json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
78+
'
79+
80+
- name: Commit and push version bump
81+
uses: stefanzweifel/git-auto-commit-action@v4
82+
with:
83+
commit_message: "chore: bump PHP SDK version to ${{ steps.bump_version.outputs.new_version }}"
84+
file_pattern: php/sdk/composer.json
85+
commit_user_name: "Devin AI"
86+
commit_user_email: "devin-ai-integration[bot]@users.noreply.github.com"
87+
push_options: "--force"
88+
89+
- name: Publish to Packagist
90+
uses: wscourge/packagist-publish@v1
91+
with:
92+
username: lingodotdev
93+
api_token: ${{ secrets.PACKAGIST_API_TOKEN }}

php/sdk/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Lingo.dev PHP SDK
2+
3+
Official PHP SDK for Lingo.dev.
4+
5+
## Installation
6+
7+
```bash
8+
composer require lingodotdev/sdk
9+
```
10+
11+
## Usage
12+
13+
```php
14+
<?php
15+
16+
use Lingodotdev\Sdk\LingoDotDevEngine;
17+
18+
// Initialize the SDK with your API key
19+
$engine = new LingoDotDevEngine([
20+
'apiKey' => 'your-api-key',
21+
]);
22+
23+
// Localize a text string
24+
$localizedText = $engine->localizeText('Hello, world!', [
25+
'sourceLocale' => 'en',
26+
'targetLocale' => 'es',
27+
]);
28+
29+
// Localize an object
30+
$localizedObject = $engine->localizeObject([
31+
'greeting' => 'Hello',
32+
'farewell' => 'Goodbye'
33+
], [
34+
'sourceLocale' => 'en',
35+
'targetLocale' => 'fr',
36+
]);
37+
38+
// Localize a chat conversation
39+
$localizedChat = $engine->localizeChat([
40+
['name' => 'Alice', 'text' => 'Hello, how are you?'],
41+
['name' => 'Bob', 'text' => 'I am fine, thank you!']
42+
], [
43+
'sourceLocale' => 'en',
44+
'targetLocale' => 'de',
45+
]);
46+
47+
// Detect language
48+
$locale = $engine->recognizeLocale('Bonjour le monde');
49+
```
50+
51+
## Documentation
52+
53+
[Documentation](https://lingo.dev/go/docs)

php/sdk/composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "lingodotdev/sdk",
3+
"description": "Official PHP SDK for Lingo.dev",
4+
"version": "0.1.0",
5+
"type": "library",
6+
"license": "MIT",
7+
"autoload": {
8+
"psr-4": {
9+
"Lingodotdev\\Sdk\\": "src/"
10+
}
11+
},
12+
"autoload-dev": {
13+
"psr-4": {
14+
"Lingodotdev\\Sdk\\Tests\\": "tests/"
15+
}
16+
},
17+
"require": {
18+
"php": ">=7.4",
19+
"guzzlehttp/guzzle": "^7.0",
20+
"respect/validation": "^2.0"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "^9.0",
24+
"squizlabs/php_codesniffer": "^3.0"
25+
},
26+
"scripts": {
27+
"test": "phpunit",
28+
"cs": "phpcs",
29+
"cs-fix": "phpcbf"
30+
}
31+
}

0 commit comments

Comments
 (0)