N
Novu•2mo ago
Shaun

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:
{
"string-withname": "{name} did one thing",
"string-withname_plural": "{name} did many things"
}
{
"string-withname": "{name} did one thing",
"string-withname_plural": "{name} did many things"
}
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
Ask Inkeep
Ask Inkeep•2mo ago
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:
{
"string-withname": "{name} did one thing",
"string-withname_plural": "{name} did many things"
}
{
"string-withname": "{name} did one thing",
"string-withname_plural": "{name} did many things"
}
And the way you're referencing it is also correct:
{{i18n "group.string-withname" name=name count=step.total_count}}
{{i18n "group.string-withname" name=name count=step.total_count}}
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:
{{i18n "group.string-withname" name=name count=2}}

{{i18n "group.string-withname" name=name count=2}}

Ask Inkeep
Ask Inkeep•2mo ago
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.
Ask Inkeep
Ask Inkeep•2mo ago
Feel free to tag @Ask Inkeep with additional questions.
Shaun
Shaun•2mo ago
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.
Ask Inkeep
Ask Inkeep•2mo ago
Got it. Tagging @Support for additional help.
Shaun
Shaun•2mo ago
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
Pawan Jain•2mo ago
@Shaun As per this doc You will have to use count as well in the i18n file
{
"string-withname": "{{name}} {{count}} did one thing",
"string-withname_plural": "{{name}} {{count}} did many things"
}
{
"string-withname": "{{name}} {{count}} did one thing",
"string-withname_plural": "{{name}} {{count}} did many things"
}
Shaun
Shaun•2mo ago
@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).
Want results from more Discord servers?
Add your server