-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add trans with syntax #7
Comments
I wonder if the old version https://github.com/twigphp/Twig-extensions was able to do so. |
@Luk1298 Do you have a complete example, please? |
The twig/extensions module have this feature but it supports only Twig 2. It is also archived. I have this example: or with multi line:
|
Mhh well, now I see this message in composer: Maybe I can force the package to be installed. |
I found a way to recognize the "with" tag. $variables = null;
if ($stream->nextIf(Token::NAME_TYPE, 'with')) {
$variables = $this->parser->getExpressionParser()->parseExpression();
} |
I found this in the twig/extensions module. Maybe you saw this too. if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
if ($stream->nextIf('with')) {
$with = $this->parser->getExpressionParser()->parseHashExpression();
} else {
$body = $this->parser->getExpressionParser()->parseExpression();
}
} Maybe you are able to interate over the hash/json and replace everything before you return the value from the function to the template compiler (that replace the tag). It is only a guess. |
I got something to work on. I need to figure out, how to replace the placeholder. $variableArray = null;
if ($stream->nextIf(Token::NAME_TYPE, 'with')) {
$variables = $this->parser->getExpressionParser()->parseExpression()->getKeyValuePairs();
foreach ($variables as $variable){
/** @var \Twig\Node\Expression\ConstantExpression $variable['key'] */
/** @var \Twig\Node\Expression\NameExpression $value['value'] */
$variableArray[
$variable['key']->getAttribute('value')
] = $variable['value']->getAttribute('name');
}
} |
Did you found a solution? Maybe I can help you or we ask somebody else, who can help. |
Hi Luk, |
You may also take a look at issue #6 |
Hi there,
is it possible for you, to add
trans with {'key': value, ...}
syntax for thetrans
tag?So translation first and then the replace of the keys inside the string.
This optional
with
parameter will be very helpful. (for older projects with this syntax)Have a nice day.
The text was updated successfully, but these errors were encountered: