Localization

Salesforce uses custom labels to present text based on a user's language setting. The values on the custom labels can be accessed from your Apex classes and view definitions, enabling you to display localized text in your Slack app.

Your Slack app publishes text across channel messages, ephemeral messages, and modals. You can't localize text in actions like in slash commands or shortcuts, although you can localize the response to those actions.

Ephemeral messages and modals target a Salesforce user and are personalized with that user's language settings. The Slack user's locale is employed if the user isn’t authenticated as a Salesforce user.

Channel messages are displayed in English. Starting in Summer '22, you can enable localization on a channel.

Using the Slack user locale to display a localized label in your Slack app isn't supported. Currently, your Slack locale must match the Salesforce locale for labels to be localized correctly.

A user interacts with the app directly one-on-one via direct conversations on:

  • The app page
  • The app's Messages tab

In this case, the Slack app posts messages with the Salesforce user's language. Otherwise, the Slack app responds in English. But direct messages between two users and the app also use each user's language instead of a common language.

Salesforce supports a number of end-user languages.

To update the user language, from your org's personal settings, go to the Language & Time Zone page. See Edit Your Language and Locale Settings.

Use a custom label to present information in a user's native language. You can access the label from your Apex code or an expression in your view definition.

To add a custom label in your org, from Setup, go to the Custom Labels page and add your labels. See Custom Labels.

In Apex, use this syntax to access your label.

If you're using a namespace, use this syntax.

For string substitution, use FORMAT.

Localized labels are supported for managed and unmanaged packages.

Use {!label.labelName} or {!label.Namespace.labelName} in an expression to reference your custom labels in a view definition.

All expressions in view definitions are case sensitive. For example, {!label.labelName} works but {!Label.labelName} doesn't.

This example uses the c namespace and assumes that you created custom labels in your org with the corresponding label names.

Alternatively, use an Apex data provider or access your label from your Apex code.

In your view, define the property for your custom label.

Define an expression that references the custom label.

Slack formats date and time using a built-in formatter. Your dates and time are dynamically localized to your timezone if you use Slack's date format syntax <!date^timestamp^token_string^optional_link|fallback_text>.

To generate Slack's date format syntax in your expressions, use the FORMATSLACKDATE key.

This example formats a view property using the {date_short} and {time_secs} tokens.

Similarly, you can add the formatting tokens to a string.

Slack supports various tokens to handle date and time formatting. For more information, see Date formatting.

In your view definition, use the mrkdwn component to support date and time formatting.

Dates render in the timezone of the device running the Slack client. We recommend that you use the timezone from your Salesforce org. If you change the timezone of the client device, all timestamps in past messages and in future messages render using the new timezone. To rerender a current message in the Slack client, scroll away and back again to the message.

Labels that the Slack language provides always use your Slack language setting. These labels aren't localized if your Slack and Salesforce locales are different. For example, Slack provides these labels, which appear in the Slack language setting.

  • (optional) label on an optional input field
  • Press 'enter' to submit label for the hint text that appears below an input field
  • Close button label on a modal
  • Only visible to you label on an ephemeral message

To ensure that your labels are localized correctly, change your Slack language to match the Salesforce language.

Slack apps translate messages based on a user's language. However, channel messages use English by default.

To enable your channel messages to use the Slack channel's language, include the following bot token scopes in your app at api.slack.com in the OAuth & Permissions page.

  • users:read
  • channels:read
  • groups:read
  • im:read
  • mpim:read

If your app uses a user token, add the scopes under the user token scopes as well.

Similarly, update your app definition file (YourSlackAppName.slackapp-meta.xml) to include the tokens using the <botScopes> or <userScopes> field.