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 show localized text in your Slack app.
Slack and Salesforce User Locales
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.
Using the Slack user locale to show 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.
Note
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.
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.
1System.Label.LabelName
If you’re using a namespace, use this syntax.
1System.Label.Namespace.LabelName
For string substitution, use FORMAT.
1{!FORMAT(label.LabelName , args)}
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.
Important
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.
1// Apex data provider2String myLabel = Label.LabelName; // Define the custom label3Slack.ViewReference viewReference = Slack.View.myviewname.get(); // Get the view4viewReference.setParameter('labelValue', myLabel); // Assign the label to the view property
In your view, define the property for your custom label.
Slack formats date and time by using a built-in formatter. Your dates and time are dynamically localized to your time zone 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.
Similarly, you can add the formatting tokens to a string.
1"{!FORMATSLACKDATE(view.properties.recordCreateDate, 'Your record was created on {date_long} at {time_secs} in your timezone.')}"
Slack supports various tokens to handle date and time formatting. For more information, see Date formatting.
Tip
In your view definition, use the mrkdwn component to support date and time formatting.
1components:2 - definition: section3 properties:4 text:5 text: "{!FORMATSLACKDATE(view.properties.epochSeconds,label.help.dateTimeToken)}\n Here are the available commands for this app"6 type: "mrkdwn"7 disableEncoding: true
Dates render in the time zone of the device running the Slack client. We recommend that you use the time zone from your Salesforce org. If you change the time zone of the client device, all timestamps in past messages and in future messages render by using the new time zone. To rerender a current message in the Slack client, scroll away and back again to the message.
Considerations and Limitations
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.
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 these 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 by using the <botScopes> or <userScopes> field.
This feature is not generally available. It is not part of your purchased Services. This feature is subject to change, may be discontinued with no notice at any time in SFDC’s sole discretion, and SFDC may never make this feature generally available. Make your purchase decisions only on the basis of generally available products and features. This feature is made available on an AS IS basis and use of this feature is at your sole risk.