We have an Identity community which supports more than 50 languages built using visualforce pages. We would like to migrate the community to LWC. For that, main issue we are facing is the language support.

In vf page header we can add language attribute and based on this we can fetch the language from the labels and picklists. We want to do a similar thing. Is this supported in LWC.

Our login and registration page is in guest user mode. And it need to load in all supported language. We are finding language by currently from the browser default language

String langFromBrowser=ApexPages.currentPage().getHeaders().get('Accept-Language');

Or passing the language as a parameter. Is something similar possible?

  • It seems that the "correct" way to support multiple languages in community pages for guest (unauthenticated) users is to add the language selector to the page. However, this doesn't seem to have an analogue in Lightning. – Phil W Jan 30 '20 at 8:30
  • There's a way to implement this, I'll prepare my answer in some time :) – Prashant Kashyap Jan 26 at 4:15

For LWC you can use internationalization properties to get the user language (as it's configured in his Salesforce profile) once he's logged in :

import LANG from '@salesforce/i18n/lang';

Then LANG value will be something like en-US, which you can use to select the correct language.

Before login or even after if you like, you can get the Accept-Language header using javascript, as described in this post : https://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.