Skip to content

Commit

Permalink
Release 1.3 - update Deepl does not allow GB language iso, so transfo…
Browse files Browse the repository at this point in the history
…rm to EN
  • Loading branch information
vanengers committed Jan 4, 2024
1 parent 1fb805c commit 12357e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/Translate/IsoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,26 @@ public static function isValidLocale(string $locale): bool
*/
public static function getIsoByLocaleDeepL(string $locale, bool $target = false): ?string
{
$deeplTrans = [
$deeplTransLocale = [
'gb' => 'en-gb',
'en' => 'en-us',
'pt' => 'pt-pt'
];

$deeplTransIso = [
'gb' => 'en',
];

$locale = strtolower($locale);

self::loadLanguages();
foreach(self::$languages as $lang) {
if (strtolower($lang->getLocale()) == strtolower($locale)) {
if ($target && array_key_exists($lang->getIso(), $deeplTrans)) {
return $deeplTrans[$lang->getIso()];
if ($target && array_key_exists($lang->getIso(), $deeplTransLocale)) {
return $deeplTransLocale[$lang->getIso()];
}
else if (!$target && array_key_exists($lang->getIso(), $deeplTransIso)) {
return $deeplTransIso[$lang->getIso()];
}
return $lang->getIso();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/IsoFilter/TranslateIsoToLocaleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public function testCanTranslateBritischSource()
$locale = 'en-GB';
$iso = IsoFilter::getIsoByLocaleDeepL($locale);

$this->assertEquals('gb', $iso);
$this->assertEquals('en', $iso);
}

public function testCanTranslateBritischLowerSource()
{
$locale = 'en-gb';
$iso = IsoFilter::getIsoByLocaleDeepL($locale);

$this->assertEquals('gb', $iso);
$this->assertEquals('en', $iso);
}

public function testCanTranslateBritischTarget()
Expand Down

0 comments on commit 12357e8

Please sign in to comment.