0

I have created a LWR community page where I have my custom LWC components. I used all custom labels from the org which have their own translations in multiple languages. Now, I've hidden the standard Language Selector component, however, I'm experiencing a weird use case issue

Here's the thing. I'm sending a different email template based on a record's language field. Each template has its own unique path add-on which displays the lwc component with correct label translations.

For example, in serbian, there is a /sh added to the URL. First time, everything works fine. However, once you've viewed the Serbian translation LWC component page, next time, when you visit the link in English, it doesn't load (although the link is correct). So, it shows the correct link for 1 second and then changes it to an invalid value that contains /sh (in this case it should be without it as the language was English).

After some digging, I've found out that there is a cookie being saved called PreferredLanguage. If I delete all cookies from my browser, it shows the page as it should. I cannot seem to access this cookie from JS in my LWC. Any ideas on how to solve this?

1

1 Answer 1

0

Two options:

  1. Set a new cookie and expire the default salesforce one. Simply take the exact parameters from what you see generated in your browser cookies. If you have not set or expired cookies, just Google document.cookie.

  2. Add /?redirect=false to your base URL when switching back to the default language.

I have tested both methods and it's working in LWR Enhanced as of 2/3/2023.

Update: Also noticed you are hiding the language picker. There is no functional need for this component. So long as you set your URL values, the page will translate. For example, you can use /?lang=zh-TW OR /zh-TW/

1
  • Yep! I've solved it a while back with the links exactly as you've mentioned in the Updates part. That works.
    – Walker
    Feb 13, 2023 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .