Skip to content

Commit d45cff6

Browse files
authored
Merge pull request #3 from Jade-GG
Replace null strings with empty strings & fix wrong locale function
2 parents 1e8d57a + 990ce51 commit d45cff6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Translators/DeeplTranslator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ public function translate(Entry $source, Collection $localisableFields, Site $si
2323
});
2424

2525
$keys = $dotted->keys()->values();
26-
$texts = $dotted->values()->all();
26+
$texts = $dotted->values()
27+
->map(fn ($text) => $text ?? '')
28+
->all();
2729

28-
$results = $deeplClient->translateText($texts, $source->locale(), $this->mapLanguageForDeepL((string) $site->shortLocale()));
30+
$results = $deeplClient->translateText(
31+
$texts,
32+
$this->mapLanguageForDeepL((string) $source->site()->shortLocale()),
33+
$this->mapLanguageForDeepL((string) $site->shortLocale())
34+
);
2935

3036
$translatedTexts = collect($results)
3137
->map(fn ($result) => $result->text)

tests/Translators/DeeplTranslatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function it_translates_data(): void
3939
->once()
4040
->with(
4141
['foo'],
42-
'en',
42+
'en-US',
4343
'en-US'
4444
)->andReturn([(object) ['text' => 'bar']]);
4545
});

0 commit comments

Comments
 (0)