Replies: 1 comment 3 replies
-
I deep-dived (dove deep?) into this. While this approach you describe is feasible in theory, it quickly falls apart in practice. The only way this works is if you have simple/straightforward/static translation strings. For example: {% assign cart_label = 'labels.cart' | t %}
<!-- outputs 'Cart' -->
{{ cart_label }} This works great! And this is essentially what we're currently doing already, minus the additional <!-- assume 'Hello' is passed to the `cart_label` param -->
{% assign cart_label = cart_label | default: 'labels.cart' | t %}
<!-- outputs 'Translation missing: en.Hello' -->
{{ cart_label }} This doesn't work because the filter So then naturally you extract the translation out of the assign to its own assign: {% assign default_cart_label = 'labels.cart' | t %}
{% assign cart_label = cart_label | default: default_cart_label %}
<!-- outputs 'Hello' if 'cart_label' is passed as a param -->
<!-- outputs 'Cart' if 'cart_label' isn't passed -->
{{ cart_label }} This works! But this only works assuming The problem starts when the translation key doesn't actually exist in the theme, and theme-check will underline the key and say it doesn't have a matching entry (which is fine). But you then think "let's have it fall back gracefully, and we can add a fallback default value in case the translation key doesn't exist in the theme": <!-- assume the 'labels.cart' key doesn't exist in the theme -->
{% assign default_cart_label = 'labels.cart' | t %}
{% assign cart_label = cart_label | default: default_cart_label | default: 'Some default value' %}
<!-- outputs 'Translation missing: en.labels.cart' -->
{{ cart_label }} This fallback system, i.e. the same one we're using for our other params, doesn't work the same way as for other Liquid variables. The translation key, if not found, doesn't return Keep in mind, these problems I'm mentioning are strictly for static translation strings. What happens when we have dynamic translations like this: {{ 'actions.terms_i_agree_html' | t: url: cart_terms_conditions_page.url }} Or even worse, dynamic values within a loop: {% for cart_discount in cart.cart_level_discount_applications %}
{%- assign savings = cart_discount.total_allocated_amount | money -%}
<div class="cart__discount">
{{ 'info.you_save_amount' | t: saved_amount: savings }}
({{ cart_discount.title }})
</div>
{% endfor %} I personally don't see any way we can ever have a dynamic value as a customizable param, especially if it lives inside of a loop, but will give this more thought. My goal here was to outline that your aforementioned proposal isn't cut and dry. |
Beta Was this translation helpful? Give feedback.
-
Context
Our current approach to components has locales as a hard dependency components. At the time of building a collection of components, we scan each component for any locales and then assemble locales files based on the contents of a universal source (archetype-themes/locales).
Problems
Our approach presents both architectural and workflow problems:
Solution
{% render %}
tag and they should have helpful defaults to fallback on. In our case the defaults can be the current locale file key and then finally a static english string. This will remove the need to handle locales for the Component Explorer + Automated Test Fixtures.Beta Was this translation helpful? Give feedback.
All reactions