Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Jun 20, 2024
1 parent 0685234 commit a58032d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Services/Grammar/OpenAiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function fixAll(array $texts): array
$content = $response->choices[0]->message->content;
$translations = json_decode($content, true);

return collect($translations)->dot();
return $translations;
})
->toArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Translate/OpenAiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function translateAll(array $texts, string $targetLocale): array
$content = $response->choices[0]->message->content;
$translations = json_decode($content, true);

return collect($translations)->dot();
return $translations;
})
->toArray();
}
Expand Down
13 changes: 8 additions & 5 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function translateTranslations(
): Translations {
$service = $service ?? $this->translateService;

if (! $service) {
if (!$service) {
throw TranslatorServiceException::missingTranslateService();
}

Expand All @@ -143,9 +143,10 @@ function (Translations $translations) use ($referenceLocale, $targetLocale, $nam
$referenceTranslations = $this->getTranslations($referenceLocale, $namespace);

$referenceValues = $referenceTranslations
->toBase()
->dot()
->only($keys)
->filter(fn ($value) => ! blank($value))
->filter(fn ($value) => !blank($value))
->toArray();

$translatedValues = $service->translateAll(
Expand All @@ -170,16 +171,18 @@ public function fixGrammarTranslations(
): Translations {
$service = $service ?? $this->grammarService;

if (! $service) {
if (!$service) {
throw TranslatorServiceException::missingGrammarService();
}

return $this->transformTranslations($locale, $namespace, function (Translations $translations) use ($service, $keys) {

$fixedTranslations = $service->fixAll(
texts: $translations->dot()
texts: $translations
->toBase()
->dot()
->only($keys)
->filter(fn ($value) => ! blank($value))
->filter(fn ($value) => !blank($value))
->toArray()
);

Expand Down

0 comments on commit a58032d

Please sign in to comment.