• Home/
  • Blog/
  • How to Implement Multi-Language Support in (LWC)?

How to Implement Multi-Language Support inLightning Web Components (LWC)?

In this blog, we will learn how to set up Service Appointments and assign them to the right people to get the job done.

How to Implement Multi-Language Support in Lightning Web Components (LWC)?

How to create custom labels and translations?

Custom labels can be created from the setup page and apex code.

Create custom labels from the setup page

Go to setup → Search for Custom Labels and Select Custom Labels.

Multi-Language Support in LWC
  • Click the New Custom Label button. Fill in the Label Name, and value details and Click Save.

Multi-Language Support in LWC Multi-Language Support in LWC

Open the newly created label and click “New” in the Translation section. Select language, add translation value, and save.

Create custom labels from Apex

Custom Labels are records of the standard object called External String and translations are stored in its child object named externalStringLocalisation. Both can be accessed from the Tooling API.

Create a Custom Label by using Tooling API

Endpoint

URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v57.0/tooling/sobjects/ExternalString'

    Sample Request Body:

  • {
  • "Name" : "Welcome",
  • "MasterLabel" : "Welcome",
  • "Value" : "Welcome",
  • "IsProtected" : false,
  • "Category" : null,
  • "Language" : "en_US"
  • }

    Sample Response Body:

  • response.getBody() will return the following response with custom label Id.
  • {
  • "id" : "xxxxxxxxxxxxxxxxx",
  • "success" : true,
  • "errors" : [ ],
  • "warnings" : [ ],
  • "infos" : [ ]
  • }

Create Translation by using Tooling API

Endpoint

URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v57.0/tooling/sobjects/ExternalStringLocalization’

    Sample Request Body

  • {
  • "ExternalStringId" : "xxxxxxxxxxxxxxxxx",
  • "Value" : "Willkommen",
  • "Language" : "de"
  • }

Another salesforce standard Functionality Translation workbench can be used for providing translations for Custom fields, Actions, Lightning page Tabs, Picklist values, etc...

Now you have learned about how to create custom labels. Use the link below to Know about next step of How to import custom labels in Lightning web components