Can I get {{ request.locale.iso_code }} to show the full en_US / en_GB language code?

Can I get {{ request.locale.iso_code }} to show the full en_US / en_GB language code?

Thomas58
Shopify Partner
29 1 11

Hi! 

 

Is there any way to get the {{ request.locale.iso_code }} tag (or any other tag) to show the full language code instead of just the first part ("en_GB" vs only "en")?  

As an example. In our US site i would like the head html to show the lang as "en_US" instead of just "en". But for the life of it I can't figure out why I can't get this info when it's used in the URL and everywhere else. 

 

 

<html class="no-js no-touch" lang="{{ request.locale.iso_code }}">

 

 


We're using Markets and everything works otherwise as it should.

Any help is greatly appreciated! 
- Thomas

Replies 6 (6)

EcomSol
Excursionist
20 3 5

 

the value of {{request.locale.iso_code }}may be determined by the theme's code and can be different from one theme to another. To show the full language code, you'll need to modify the code in the theme.

You can do this by creating a new Liquid variable that stores the full language code and then using that variable in the HTML. Here's an example:

 

 
{% capture full_locale_code %}{{ shop.locale }}{% endcapture %} <html class="no-js no-touch" lang="{{ full_locale_code }}">

In this example, the {{shop.locale}} value is stored in the {{full_locale_code}} variable, which can then be used in the HTML.

this is just an example, and the exact implementation may vary depending on the theme you are using.

I hope this helps! Let me know if you have any further questions.
Best Regards!
Ecom Solutions
Thomas58
Shopify Partner
29 1 11

Thank you for the help! I did not get this to work exactly the way intended, so I had to finally invent a workaround instead.  I just find it curious why the {{request.locale.iso_code }} only retrieves the first part and not the full code. I assume there is a reason for this though, like always

The problem is mostly with apps, which often target languages and countries differently from the Shopify markets. It's a bit of a mess at the moment as it's a mix of different techniques. 

HKR
New Member
17 0 0

Hello, can you Tell me about the method you invented, i meet the same problem, i really need this!

Sandy_1
Shopify Partner
7 0 2

This only returns the language.  Same as "{{ request.locale.iso_code }}"

Sandy_1
Shopify Partner
7 0 2
{{ request.locale.iso_code }}-{{ localization.country.iso_code }}

this should give you - en-gb
HKR
New Member
17 0 0

no, this doesn't work😭