theme-tools icon indicating copy to clipboard operation
theme-tools copied to clipboard

Feature Request: Improved translation pluralisation support

Open david-w-shopify opened this issue 1 year ago • 2 comments

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.

  1. 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.
  2. 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.

david-w-shopify avatar Oct 22 '24 10:10 david-w-shopify

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. 🤦

charlespwd avatar Oct 23 '24 17:10 charlespwd

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.

Image

Image

Image

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

david-w-shopify avatar Oct 24 '24 08:10 david-w-shopify