Search code examples
salesforcesalesforce-lightningsalesforce-communitieslwc

What's the best practice to implement localization (for strings) in Salesforce's LWC?


I'm new to Salesforce's Lightning Web Components, and I'm trying to figure out what the best way to support localizing labels, messages, and other strings in LWC.

I've learnt about the i18n programmability to localize Date/Time format, Currency format, etc. according to user's locale. However, I couldn't see any out-of-the-box supported way to localize strings.

Let's say my LWC requires a message to be displayed to user on certain scenario; so my html template will have to render that message. I would like for my html to be able to render that message in US English for user with en-US locale and in Japanese for ja-jp locale. What's the salesforce recommended way to develop that functionality?

Potentially I could add locale files (say, a json file each, with all messages for a specific locale) to static resources, and then add a getter each for every message in my LightningElement js that calls a generic method to take a string id and locale and returns the message from my locale file. It sounds like some work, and I just want to ensure there's no built-in, better way of doing it easily. I searched for previous threads on this topic, couldn't find much.

Thanks for the help or any pointers.


Solution

  • I guess what you're looking for is Custom Label. That's the way to handle multiple language in Salesforce.