Skip to content

Commit ec50c13

Browse files
committed
feat: refactor api
1 parent 4b7b899 commit ec50c13

File tree

4 files changed

+361
-107
lines changed

4 files changed

+361
-107
lines changed

src/BatchTranslationOptions.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* PHP SDK for Lingo.dev
4+
*
5+
* @category Localization
6+
* @package Lingodotdev\Sdk
7+
* @author Lingo.dev Team <hi@lingo.dev>
8+
* @license MIT https://opensource.org/licenses/MIT
9+
* @link https://lingo.dev
10+
*/
11+
12+
namespace LingoDotDev\Sdk;
13+
14+
/**
15+
* Options for batch text translation to multiple languages.
16+
*
17+
* @category Localization
18+
* @package Lingodotdev\Sdk
19+
* @author Lingo.dev Team <hi@lingo.dev>
20+
* @license MIT https://opensource.org/licenses/MIT
21+
* @link https://lingo.dev
22+
*/
23+
class BatchTranslationOptions
24+
{
25+
/**
26+
* Source language code (e.g., 'en')
27+
* Required field.
28+
*/
29+
public string $sourceLocale;
30+
31+
/**
32+
* Array of target language codes (e.g., ['es', 'fr', 'de'])
33+
* Required field.
34+
*
35+
* @var string[]
36+
*/
37+
public array $targetLocales;
38+
39+
/**
40+
* Enable fast mode - trades translation quality for speed
41+
* Default: false (quality mode)
42+
*/
43+
public bool $fast = false;
44+
45+
46+
/**
47+
* Create a fluent builder for batch translation options.
48+
*
49+
* @param string $sourceLocale Source language code
50+
*/
51+
public static function create(string $sourceLocale): self
52+
{
53+
$instance = new self();
54+
$instance->sourceLocale = $sourceLocale;
55+
$instance->targetLocales = [];
56+
return $instance;
57+
}
58+
59+
/**
60+
* Set target locales.
61+
*
62+
* @param string[] $locales Target language codes
63+
*/
64+
public function to(array $locales): self
65+
{
66+
$this->targetLocales = $locales;
67+
return $this;
68+
}
69+
70+
/**
71+
* Add a single target locale.
72+
*
73+
* @param string $locale Target language code
74+
*/
75+
public function addTarget(string $locale): self
76+
{
77+
$this->targetLocales[] = $locale;
78+
return $this;
79+
}
80+
81+
/**
82+
* Enable fast translation mode.
83+
*/
84+
public function withFastMode(): self
85+
{
86+
$this->fast = true;
87+
return $this;
88+
}
89+
}

src/EngineConfig.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* PHP SDK for Lingo.dev
4+
*
5+
* @category Localization
6+
* @package Lingodotdev\Sdk
7+
* @author Lingo.dev Team <hi@lingo.dev>
8+
* @license MIT https://opensource.org/licenses/MIT
9+
* @link https://lingo.dev
10+
*/
11+
12+
namespace LingoDotDev\Sdk;
13+
14+
/**
15+
* Configuration for LingoDotDevEngine initialization.
16+
*
17+
* @category Localization
18+
* @package Lingodotdev\Sdk
19+
* @author Lingo.dev Team <hi@lingo.dev>
20+
* @license MIT https://opensource.org/licenses/MIT
21+
* @link https://lingo.dev
22+
*/
23+
class EngineConfig
24+
{
25+
/**
26+
* Your Lingo.dev API token
27+
*/
28+
public string $apiKey;
29+
30+
/**
31+
* API base URL (default: https://engine.lingo.dev)
32+
*/
33+
public string $apiUrl = 'https://engine.lingo.dev';
34+
35+
/**
36+
* Maximum records per request (1-250, default: 25)
37+
*/
38+
public int $batchSize = 25;
39+
40+
/**
41+
* Maximum words per request (1-2500, default: 250)
42+
*/
43+
public int $idealBatchItemSize = 250;
44+
45+
/**
46+
* Create configuration with API key.
47+
*
48+
* @param string $apiKey Your Lingo.dev API token
49+
*/
50+
public static function create(string $apiKey): self
51+
{
52+
$instance = new self();
53+
$instance->apiKey = $apiKey;
54+
return $instance;
55+
}
56+
57+
/**
58+
* Set custom API URL.
59+
*
60+
* @param string $url API endpoint URL
61+
*/
62+
public function withApiUrl(string $url): self
63+
{
64+
$this->apiUrl = $url;
65+
return $this;
66+
}
67+
68+
/**
69+
* Set batch size limit.
70+
*
71+
* @param int $size Records per request (1-250)
72+
*/
73+
public function withBatchSize(int $size): self
74+
{
75+
$this->batchSize = $size;
76+
return $this;
77+
}
78+
79+
/**
80+
* Set ideal batch item size.
81+
*
82+
* @param int $size Max words per request (1-2500)
83+
*/
84+
public function withIdealBatchItemSize(int $size): self
85+
{
86+
$this->idealBatchItemSize = $size;
87+
return $this;
88+
}
89+
}

0 commit comments

Comments
 (0)