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 specific user and are personalized using the Salesforce user's language settings. The Slack user's locale is used if the user is not authenticated as a Salesforce org 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 using the Salesforce user's language. Otherwise, the Slack app responds in English. However, direct messages between 2 users and the app also uses 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.

Access the Label

In Apex, use this syntax to access your label.

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

For string substitution, use FORMAT.

Use Custom Labels

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.

Format Dates and Time in Slack

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.

The Apex SDK for Slack has several localization limitations.

The date and time pickers don't currently support multiple time zones. For example, if the field value is stored as 11:00 pm PST on 3/9/2022, the date and time picker displays the date incorrectly as 3/9/2022 for users in EST. The date and time pickers don't display the time zone or convert the date to the local time zone. This limitation also applies to the date picker and the time picker.

Labels that are provided by the Slack client always use your Slack's language setting. These labels aren't localized if your Slack and Salesforce locales are different. For example, these labels are provided by Slack and are displayed based on your Slack's 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.

Enable Channel Localization

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.