Feature Request: Improved translation pluralisation support
Is your feature request related to a problem? Please describe. The existing translation completions support pluralised translations, which is excellent, but there are a couple of edge cases that haven't yet been addressed.
- The
countvariable is not always rendered inside a translation, but still needed for the pluralisation logic to work. If a pluralised variable is injected,countshould be included with the variables regardless of if it is used inside the rendered string. - It’s possible that pluralised translations use different variables, so all should be accounted for. Currently it looks like only those in the first rule are used for autocompletions.
Describe the solution you'd like
Use case 1:
{
"product": {
"add_product_to_cart": {
"one": "Add product to cart",
"other": "Add products to cart"
}
}
}
In this example the completion should be:
{{ 'product.add_product_to_cart' | t: count: count }}
Despite count not being used in the actual rendered string, it is required for the pluralisation rules to work.
Use case 2:
{
"product": {
"add_count_product_to_cart": {
"one": "Add {{ product }} to cart, {{ test }}",
"other": "Add {{ product }}s to cart, {{ test_2 }}"
}
}
}
In this example the completion should be:
{{ 'product.add_product_to_cart' | t: count: count, product: product, test: test, test_2: test_2 }}
Variables discovered in all options should be completed to ensure the string can always render correctly.
The count variable is not always rendered inside a translation, but still needed for the pluralisation logic to work. If a pluralised variable is injected, count should be included with the variables regardless of if it is used inside the rendered string.
I didn't even know that. 🤦
You made me second guess, so I had to double check on pluralisation this morning. If you don't pass a count variable the object is rendered rather than any of the individual values.
Fwiw I think it is a lesser-known feature, but here are the docs: https://shopify.dev/docs/storefronts/themes/architecture/locales/storefront-locale-files#pluralize-translations