Skip to content
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

Translation tag/macro/filter should allow returning both string|\Stringable #372

Closed
ksandrj opened this issue Aug 15, 2024 · 0 comments
Closed

Comments

@ksandrj
Copy link

ksandrj commented Aug 15, 2024

Version: 3.0.18

Bug Description

The Nette\Utils\Translator interface allows returning both string|\Stringable.
https://github.com/nette/utils/blob/736c567e257dbe0fcf6ce81b4d6dbe05c6899f96/src/Translator.php#L21

But the Latte's translate filter which is ultimately used when tags {translate} and {_} are compiled forces the return value of type string.

'translate' => fn(Latte\Runtime\FilterInfo $fi, ...$args): string => $this->translator

This causes an error when returning results of translation as an \Nette\Utils\Html objects (related to nette/utils#231).

Possible Solution

public function getFilters(): array
{
	return [
		'translate' => fn(Latte\Runtime\FilterInfo $fi, ...$args): string|\Stringable => $this->translator
			? ($this->translator)(...$args)
			: $args[0],
	];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant