Skip to content

Fix return type and implement getCatalogues() #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Tests/Unit/Translator/EditInPlaceTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public function testDisabled(): void
$activator = new FakeActivator(false);
$service = new EditInPlaceTranslator($symfonyTranslator, $activator, $requestStack);

$this->assertNull(
$service->trans('key', [])
);
$this->assertEmpty($service->trans('key', []));
}

public function testHtmlTranslation(): void
Expand Down
18 changes: 15 additions & 3 deletions Translator/EditInPlaceTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,34 @@ public function __construct($translator, ActivatorInterface $activator, RequestS
}

/**
* @see Translator::getCatalogue
* @see Translator::getCatalogue()
*/
public function getCatalogue($locale = null): MessageCatalogueInterface
{
return $this->translator->getCatalogue($locale);
}

/**
* @see Translator::getCatalogues()
*/
public function getCatalogues(): array
{
if (!\method_exists($this->translator, 'getCatalogues')) {
throw new \Exception(\sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__));
}

return $this->translator->getCatalogues();
}

/**
* @see Translator::trans
*/
public function trans($id, array $parameters = [], $domain = null, $locale = null): ?string
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
{
$original = $this->translator->trans($id, $parameters, $domain, $locale);
$request = LegacyHelper::getMainRequest($this->requestStack);
if (!$this->activator->checkRequest($request)) {
return $original;
return (string) $original;
}

$plain = $this->translator->trans($id, [], $domain, $locale);
Expand Down
9 changes: 9 additions & 0 deletions Translator/FallbackTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ public function getCatalogue($locale = null): MessageCatalogueInterface
return $this->symfonyTranslator->getCatalogue($locale);
}

public function getCatalogues(): array
{
if (!\method_exists($this->symfonyTranslator, 'getCatalogues')) {
throw new \Exception(\sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__));
}

return $this->symfonyTranslator->getCatalogues();
}

/**
* Passes through all unknown calls onto the translator object.
*/
Expand Down