Localizing Dawn

Short description of issue

How to add a translatable string when using a theme (Dawn)

Reproduction steps

I created a custom liquid block with the following code:

{%- if product.metafields.custom.origin != blank -%}
{{ 'Origin: ’ | t }}{{ product.metafields.custom.origin }}
{%- endif -%}

The result is ‘Translation missing: fr.origin’
I understand that I need to update the schema of my page (not sure how to) and after that I will need to create an entry in en.json.
But I can’t because this is an auto-generated file.
Is there any work-around to add a translated string string in such a theme

Additional info

If I remove the | t filter, the string is not recognized by Translate and Adapt (I think that custom liquid is not parsed)

What type of topic is this

General discussion

I suggest having a read of these docs:

Thank you but I can’t update the existing locale files (json) as they are auto-generated and I can’t create a new json (ex: en.product.json) because there is a validation error “FileSaveError: The regional settings ‘en’ already exist”.

They are not auto generated, you can edit them.

I have added the following in en.default.json (and the translations in fr.json, de.json):

{

“custom”:{

“tea_properties”:{

“origin”: “Origin”

  }

},…

But {{ ‘Origin’ | t }} is producing the same error: Translation missing

Any hint would be much appreciated

Because you’re not referencing the object correctly, it should be

{{ 'custom.tea_properties.origin' | t }}

As mentioned, I suggest you have a good read of the documentation:

Many thanks Luke, it is working!!!

Are you sure that this content will not be deleted by a subsequent regeneration? Because I see this at the top of the file:
/*


  • IMPORTANT: The contents of this file are auto-generated.

  • This file may be updated by the Shopify admin language editor

  • or related systems. Please exercise caution as any changes

  • made to this file may be overwritten.


*/

I had read the documentation carefully, but I had not put quotation marks around ‘custom.tea_properties.origin’ sorry for that

Hello @Dunabyl,

This auto-generated disclaimer is just here to tell you that the file can be edited via the back-office interface. On a theme, you can access it on the Themes page → Three dots → Edit theme default content. It is the same as editing it via the code so don’t worry as long as you only edit via these two methods :wink:

Thank you very much TeamDijon, I learned something new today!

1 Like