Reputation: 762
I am using Symfony2, Twig and xliff based translations.
Now, I want to show text based on a numerical value which is between [-Inf,Inf]
. To do that, I use transchoice
.
My problem: I want to display 7 days ago
if count=-7
. However, I get -7 days ago
. I can't use twig filters like abs
inside transchoice fields, right? How do I remove the leading minus sign.
Here is my message.en.xliff
...
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>todo.days-difference</source>
<target>{0} today|{1} tommorow|]1,14] %count% days before|]14,Inf] far away|{-1} yesterday|[-14,-1[{{ count }}%count% days after|[-Inf,-14[ long after</target>
</trans-unit>
</body>
</file>
</xliff>
Upvotes: 0
Views: 1355
Reputation: 762
passing the absolute value of the count variable as argument solves the problem:
{{ "todo.days-differences"|transchoice(task.getDueDateDifference(), {'%count_abs%': task.getDueDateDifference()|abs}) }}
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>todo.days-difference</source>
<target>{0} today|{1} tommorow|]1,14] %count_abs% days before|]14,Inf] far away|{-1} yesterday|[-14,-1[ %count_abs% days after|[-Inf,-14[ long after</target>
</trans-unit>
</body>
</file>
</xliff>
Upvotes: 1