Pluralization and variable filling
Hi there! I am running into an issue when trying to supply a variable to be put into a localized translation string while also trying to pluralize form digestion. In this case I have:
Then I am referencing it like
{{i18n "group.string-withname" name=name count=step.total_count}}
Each time I digest multiple items, I still get the non-pluralized version.
Does anyone see an issue with this? Curious if filling a variable and using count is not supported? Thanks!8 Replies
Hi @Shaun, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question.
-----------------------------
While I generate an answer, here are some sources that might be helpful:
* Workflow Editor
* Translations
* Digest Action Step
* Collect multiple events to a single message with the Digest Engine
-----------------------------
Answer
Based on the documentation, your approach for pluralization and variable filling in translations is correct. (1) The issue you're experiencing might be related to how the
count
variable is being passed or interpreted. Let's break down the correct usage and some potential issues:
Correct Usage:
The format you're using for pluralization is correct:
And the way you're referencing it is also correct:
Potential Issues:
1. Digest Step Total Count: Make sure that step.total_count
is actually returning the correct number of digested events. You might want to double-check the digest step configuration. (2)
2. Variable Passing: Ensure that both name
and step.total_count
are being passed correctly to the template. You can verify this by checking the payload in the activity feed. (3)
3. Translation Group: Confirm that the translation group (in your case, "group") is correctly set up and contains the pluralization keys. (4)
4. Locale Setting: Verify that the subscriber's locale is set correctly, as this affects how translations are applied. Troubleshooting Steps:
1. Try using a hardcoded number for the count to see if pluralization works:
If this works, the issue might be with how
step.total_count
is being passed or calculated.
2. Check the activity feed to see what values are actually being passed to the template. (5)
3. Verify that the translation files are uploaded correctly and the keys match exactly what you're using in the template. (6)
If you're still experiencing issues after checking these points, I suggest clicking on the "Ask for help" button to tag a team member for further assistance, as there might be a specific configuration or edge case causing this behavior.Feel free to tag @Ask Inkeep with additional questions.
Adding a note here, I had to end up adding a conditional to switch between keys as
step.total_count
does not seem accessible from within a {{#each step.events}}
loop.Got it. Tagging @Support for additional help.
So in my case, I was attempting to use
step.total_count
from within a loop iterating through digest events. I needed to access an element of a payload item while also determining how many items were digested. Seems like a usecase that others might run into 🙂@Pawan Jain Interesting. But if I just wanted to change the wording ("you have one thing" vs "you have many things")without referencing the actual count, is that not valid?
From my testing, I did follow the bots suggestion and when I put count=2 directly, the plural key was chosen. So I believe the issue is isolated to trying to reference
step.total_count
while already in an each loop (looping over the digested steps).