Multi language support in community built using LWC (Migration from Visualforce to LWC)

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?

Answer

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

Attribution
Source : Link , Question Author : anoopijt , Answer Author : Emmanuel BRUNO

Leave a Comment