Skip to content

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

@ksandrj

Description

@ksandrj

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],
	];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions