liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Shopify `t` filter doesn't allow `default:` filter

Open vfonic opened this issue 3 years ago • 1 comments

I'm not sure where to post this so I'm posting it here.

I'd like to allow for default language to be used or default filter fallback.

Is there any way to achieve this?

I'm trying to build the translation system around product tags. Some of these could be brand names so there's no need to translate those and default fallback would make perfect sense, but I cannot achieve this easily. I need to hack something along these lines:

Instead of:

{{ tag | t | default: tag }}

I have to do something along the lines of:

{% assign translated_tag = tag | t %}
{% if translated_tag contains 'translation missing' %}
  {% assign translated_tag = tag %}
{% endif %}

vfonic avatar Apr 26 '21 18:04 vfonic

I'm running into this same issue. Currently building an app that leans heavily into theme blocks/app blocks and we'd like merchants to use their preferred translation apps so we provide translatable strings. However, we want to check if the translations don't exist and provide some sane defaults, and the only way to do that is to to check for the "translation missing" string each time. It works but it's tedious.

nozzlegear avatar Sep 09 '22 21:09 nozzlegear