From 2b4bc3fbb371621d953f1ee790d8040665031cdb Mon Sep 17 00:00:00 2001 From: Andrew H Date: Fri, 2 Aug 2024 13:58:51 -0400 Subject: [PATCH] chore: clean up for readme and stack translator --- README.md | 23 +++++++++++------------ src/Drivers/StackTranslate.php | 4 ++-- src/TranslatorManager.php | 4 ++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0249480..6523302 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@

-PHP Version Support +PHP Version Support PHP Version Support -GitHub Workflow Tests Status - - +GitHub Workflow Tests Status + +

# Laravel Polyglot @@ -68,16 +68,15 @@ If you simply need to translate a piece of text, this package provides a few con 'translators' => [ 'stack' => [ 'driver' => 'stack', - 'translators' => ['amazon', 'google', 'gpt35'], + 'translators' => ['amazon', 'google', 'gpt'], 'retries' => 3, 'sleep' => 100, - 'target' => 'it', ], ... ] ``` ```php - > Polyglot::translator('stack')->from('auto')->translate('Hello!'); + > Polyglot::translator('stack')->from('auto')->to('it')->translate('Hello!'); = "Ciao!" ``` @@ -85,7 +84,7 @@ If you simply need to translate a piece of text, this package provides a few con - `Translator::translateBatch` - Translate an array of strings, set target language with `to` method - `Translator::translateBatchTo` - Translate an array of strings to a specific language -- `AbstractTranslator::to`, `from`, `format`, `setSource`, `setTarget`, `setFormat` - Fluent API for setting translator options +- `AbstractTranslator::to`, `from`, `format` - Fluent API for setting translator options - `AbstractTranslator::languages` - Get a list of supported languages, if locale is passed it will return the supported languages for that locale - `sendTranslateRequest` - Some drivers allow you to access the underlying response from the translation service @@ -98,7 +97,7 @@ You can extend polyglot and provide your own translator drivers. To do so, follo 2. Then, in a service provider, call the `Plank\Polyglot\Polyglot::extend` method to register your new driver. ```php - Polyglot::extend('bing', static function (Container $app, array $config) { + Polyglot::extend('azure', static function (Container $app, array $config) { $key = $config['key']; return new AzureTranslator($key); @@ -108,7 +107,7 @@ You can extend polyglot and provide your own translator drivers. To do so, follo ```php return [ - 'default' => env('POLYGLOT_DEFAULT', 'microsoft'), + 'default' => env('POLYGLOT_DEFAULT', 'bing'), 'translators' => [ 'microsoft' => [ 'driver' => 'azure', @@ -121,7 +120,7 @@ You can extend polyglot and provide your own translator drivers. To do so, follo 4. And finally use it in your code: ```php - Polyglot::translator('microsoft')->from('en')->to('fr')->translate('Hello!'); + Polyglot::translator('bing')->from('en')->to('fr')->translate('Hello!'); ``` ## Testing @@ -154,4 +153,4 @@ All security vulnerabilities will be promptly addressed. Plank focuses on impactful solutions that deliver engaging experiences to our clients and their users. We're committed to innovation, inclusivity, and sustainability in the digital space. -[Learn more](https://plank.co/open-source/learn-more-link) about our mission to improve the web. \ No newline at end of file +[Learn more](https://plank.co/open-source/learn-more-link) about our mission to improve the web. diff --git a/src/Drivers/StackTranslate.php b/src/Drivers/StackTranslate.php index 1d8e1fc..75ad6ec 100644 --- a/src/Drivers/StackTranslate.php +++ b/src/Drivers/StackTranslate.php @@ -39,9 +39,9 @@ public function translateBatch(array $strings): array return $this->tryAllClients(fn (Translator $client) => $client->translateBatch($strings)); } - public function translateBatchTo(array $text, string $target, ?string $source = null): array + public function translateBatchTo(array $strings, string $target, ?string $source = null): array { - return $this->tryAllClients(fn (Translator $client) => $client->translateBatchTo($text, $target, $source)); + return $this->tryAllClients(fn (Translator $client) => $client->translateBatchTo($strings, $target, $source)); } protected function tryAllClients($callback): mixed diff --git a/src/TranslatorManager.php b/src/TranslatorManager.php index f37425a..ad2e19e 100644 --- a/src/TranslatorManager.php +++ b/src/TranslatorManager.php @@ -100,7 +100,7 @@ public function stack(...$translators): StackTranslate $config = $this->config->get('polyglot.translators.stack') ?? []; $config['translators'] = $translators; - return $this->drivers[$key] = $this->createStackDriver($config)->to($config['target'] ?? $this->container->getLocale()); + return $this->drivers[$key] = $this->createStackDriver($config); } public function createStackDriver(array $config): StackTranslate @@ -117,7 +117,7 @@ public function createStackDriver(array $config): StackTranslate $translators = array_map(fn ($translator) => $this->translator($translator), $translators); - return new StackTranslate($translators, $config['retries'] ?? null); + return new StackTranslate($translators, $config['retries'] ?? 1, $config['sleep'] ?? 100); } public function createStichozaDriver(array $config): StichozaTranslate