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

Highlighted
New Member
2 0 0

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 

0 Likes