Redirect to order status page (order_status_url) with specific locale

I’m using the order status page as the track shipment updates page on our website and in email notifications and I’m having difficulties being able to set the specific locale that the order status page should be displayed. Our store (actually 2 stores) supports 7 locales, so it’s kind of important to be able to use this ability.

I found when visiting the URL in {{ order.order_status_url }} (or just {{ order_status_url }} when customising emails) that if I replace the domain with one that has the locale code as the first folder path following the domain, it doesn’t work:

{% assign tracking_url = order.order_status_url %}
{% if request.locale.iso_code != "en" %}
  {% assign shop_domain_with_locale = shop.domain | append: "/" | append: request.locale.iso_code %}
  {% assign tracking_url = tracking_url | replace: shop.domain, shop_domain_with_locale %}
{% endif %}

For example, if my shop.domain is example.com and the customer was viewing the website in French (fr), then the above would replace with example.com/fr

That didn’t seem to work, but then I found after the page is loaded that if I used ?locale=fr in the URL for the order status page, it does change the language to French.

So then I tried this:

{% assign tracking_url = order.order_status_url %}
{% if request.locale.iso_code != "en" %}
  {% assign tracking_url = tracking_url | append: "&locale=" | append: request.locale.iso_code %}
{% endif %}

Since the order_status_url page has an ?authenticate=... in the URL, that’s why I add &locale=... at the end.

This doesn’t seem to work though, as it redirects to the order_status_url without any URL params – &locale=... is missing and the order status page is displayed in the default locale.

Am I missing something here? Has anyone else gotten this to work?

EDIT: actually, after switching language to FR (example.com/fr) on the website I notice that the order_status_url now has example.com/fr in the URL, however after clicking it always takes me to a 404 page. Seems like the locale code in the URL is added by default and then equally not supported by Shopify.

Hello, I have the exact same problem.

Anyone knows a way around this?

Hi @Shop2000 ,

I managed to solve this issue using custom code on the checkout JS scripts. Since we store the customer’s preferred language as a tag on their customer record (e.g. “language:fr”), I could create a script to redirect to the customer’s preferred locale when they view the order status page (after authorisation):

{% comment %}
  Check if the customer has a different preferred language and redirect
  to the order status page with the correct locale selected
{% endcomment %}
{% unless first_time_accessed %}
  {% assign languageCode = request.locale.iso_code %}
  {% assign customerTags = customer.tags %}

  {% if languageCode == "en" or languageCode == nil %}
    {% for tag in customerTags %}
      {% if tag contains "language:" %}
        {% assign languageCode = tag | remove: "language:" %}
        {% break %}
      {% endif %}
    {% endfor %}
  {% endif %}

  {% if languageCode != "en" %}
  
  {% endif %}
{% endunless %}

Thanks, how did you manage to avoid th 404 issue with "example.com/fr` in the generated URLs?

@Shop2000 Sorry, I forgot that part! Here’s my liquid code for displaying a link to the order status page in the theme code:

{% assign tracking_url = order.order_status_url %}
{% if request.locale.iso_code != "en" %}
  {% assign shop_domain_with_locale = shop.domain | append: "/" | append: request.locale.iso_code %}
  {% assign tracking_url = tracking_url | replace: shop_domain_with_locale, shop.domain %}
{% endif %}
Track shipment

I had to add data-ly-locked to the element to prevent Langify from automatically adding the /{{ request.locale.iso_code }}. I also remove the shop domain with locale code from the URL and just replace it with the shop domain as a backup.

Hello, thanks. Great find with the langify attribute.

Now I can at least redirect customers to the status page without a 404 even if it is just one language.

Thanks