Multi-Language: Import Custom Label In LWC

Learn how to implement multi-language in Lightning Web Components (LWC) using custom labels and how to use them in Apex class for seamless localization

By Dharma Prakash Eswaran
Senior Salesforce Developer

How to import custom labels in Lightning web components (LWC)?

Custom labels should be imported in the js file using the Import statement. Then it can be assigned to a variable and used in HTML. Follow the best practice of Adding All labels to an Array and use values from an array to avoid confusion.

WelcomeComponent.js

Multi-Language Support in LWC

WelcomeComponent.html

Multi-Language Support in LWC

Result

When user language is English

Multi-Language Support lwc

When user language is changed to German

Multi-Language Support lwc

How to use custom labels in Apex Classes?

Custom labels are easily usable in Apex classes With the following syntax

System.label.API_Name_of_label

Multi-Language Support lwc

The above code will return the translation value of the label for the current user language. If the translation is not added for the current user language, it will return the default value in the label.


free-consultation