Translating discount message with Input.locale in Shopify Scripts

Brecht
Shopify Partner
11 0 1

Hi,

 

I would like to translate the discount message in a Shopify Script.
Therefore I was thinking to make use of the Input.locale string.
Does anyone have an example of how to use this?

 

The locale can end with the country code so I wanted to take the first characters of the string, but this gets an undefined method []:

 

input_locale = Input.locale[0,2]

message_discount = "Free Coffee Gift"
if input_locale == "fr"
  message_discount = "Cadeau de café gratuit"
end

 

 

The message doesn't even change when I change the code by a regular equation:

 

message_discount = "Cadeau de café gratuit"
if Input.locale == "en"
  message_discount = "Free Coffee Gift"
end

 

 

Replies 0 (0)