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

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.


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

Any help is greatly appreciated!

  • Thomas

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.

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.

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

{{ request.locale.iso_code }}-{{ localization.country.iso_code }}

this should give you - en-gb

2 Likes

no, this doesn’t work :sob:

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