Multi Language Emails – How to simplify the condition in liquid?

Woolday
New Member
2 0 1

Hi everyone, 

I've set up our transactional emails in two languages, German & English. 

As I want to use this logic for a lot more automated Emails, I wonder if there is a way to reduce the code needed for this? Right now, I use logic like this: 

 

{% if customer_address.country_code == 'DE' or customer_address.country_code == 'AT' or customer_address.country_code == 'CH' %}
   Deutscher Text 
      {% else %} 
   English copy 
{% endif %}

 

What I would love to do is to condense this multiple condition if-control flow. To ideally get something like this:

 

{% if lang_de %}
   Deutscher Text
      {% else %}
   English copy
{% endif %}

 

I've tried several ideas, but none worked because Shopify is not accepting the tag lang_de. This is one option I tried, but it did not work: 

 

{% assign lang_de = customer_address.country_code %}
	{% case lang_de %}
		{% when customer.countrycode = "DE" %} 
			{% assign lang_de = true %}
		{% when customer.countrycode = "AT" %} 
			{% assign lang_de = true %}
		{% when customer.countrycode = "CH" %} 
			{% assign lang_de = true %}	
		{% else %}
			{% assign lang_de = false %}
{% endcase %}

...


<!DOCTYPE html>
<html lang="en">
  <head>
  <title>{{ email_title }}</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" type="text/css" href="/assets/notifications/styles.css">
  <style>... </style>
</head>

  <body> 
<p> 
{% if lang_de %}
	Deutscher Text 
{% else %} 
	English Copy 
{% endif %}
</p>
  </body>
</html>

 

Does anyone know a solution to this and could help me to get this right? 

Thank you very much. 

Cheers, 

Fabian 

Replies 3 (3)
Ober
Excursionist
25 1 6

Hi @Woolday , I have some similar issues and have found a condition but not tried yet. Since I have some other questions I created a new topic under email templates edits & translations: order confirmation, new order notification (multi language) - I have there also the code for the lang-condition. I wish success to all of us with our Shopify. Cheers. 

MehdiY
Tourist
8 0 4

Good news!

You no longer need to use the liquid parameters to show different content per language. Shopify has made it possible to have different email template per store language. Just go to the notifications page, and you'll have the option to insert different content per language.

Shopify Partner | Providing Shopify Solutions for Arab Merchants and eCommere businesses operating in the MENA & Gulf Region.
Ober
Excursionist
25 1 6

Thx for the notification. Some necessary progress for ML. Just did look it up under myshopify.com/admin/settings/notifications