---
schema_version: "1"
id: 7346aa29a2653434bcca1292d58eb2cab0b2246eee8e4e712d14ba001bfb3744
title: Localization
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-slack-sdk/apex-slack-sdk/guides/localization.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/localization.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 97ae4fe43c6403c23c2a9d8ef29892fdd986243a783b8f2d0e55511841eb7c77
products:
  - Apex SDK for Slack (Beta)
---
# 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 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.

Channel messages are shown in English. Starting in Summer '22, you can [enable localization on a channel](#enable-channel-localization).

**note:** 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.

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.

## Update the User Language

Salesforce supports various [end-user languages](https://help.salesforce.com/s/articleView?id=xcloud.faq_getstart_what_languages_does.htm&type=5).

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](https://help.salesforce.com/s/articleView?id=xcloud.usersetup_lang_time_zone.htm&type=5).

## Work with Custom Labels

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](https://help.salesforce.com/s/articleView?id=platform.cl_about.htm&type=5).

### Access the Label

In Apex, use this syntax to access your label.

```java
System.Label.LabelName
```

If you're using a namespace, use this syntax.

```java
System.Label.Namespace.LabelName
```

For string substitution, use `FORMAT`.

```yaml
{ !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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/build/expressions.md) to reference your custom labels in a view definition.

**important:** 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.

```yaml
description: "A context block with custom labels"
components:
  - definition: context
    name: "context_block"
    components:
      - definition: image
        properties:
          url: "https://via.placeholder.com/150"
          altText: "{!label.c.AltTextLabel}"
      - definition: text
        properties:
          text:
            type: "mrkdwn"
            text: "{!label.c.MarkdownLabel}"
  - definition: context
    components:
      - definition: text
        properties:
          text: "{!label.c.TextLabel}"
```

Alternatively, use an Apex data provider or access your label from your Apex code.

```java
// Apex data provider
String myLabel = Label.LabelName; // Define the custom label
Slack.ViewReference viewReference = Slack.View.myviewname.get(); // Get the view
viewReference.setParameter('labelValue', myLabel); // Assign the label to the view property
```

In your view, define the property for your custom label.

```yaml
schema:
  properties:
    labelValue:
      type: string
      defaultValue: "Display custom label here"
```

Define an expression that references the custom label.

```yaml
- definition: section
  properties:
    text: "{!view.properties.labelValue}"
```

### Format Dates and Time in Slack

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](https://api.slack.com/reference/surfaces/formatting#date-formatting) `<!date^timestamp^token_string^optional_link|fallback_text>`.

To generate Slack's date format syntax in your expressions, use the `FORMATSLACKDATE` key.

```java
{!FORMATSLACKDATE(epochSeconds, string_including_dateFormat)}
```

This example formats a view property by using the `{date_short}` and `{time_secs}` tokens.

```java
"{!FORMATSLACKDATE(view.properties.epochSeconds,'{date_short} {time_secs}')}"
```

Similarly, you can add the formatting tokens to a string.

```java
"{!FORMATSLACKDATE(view.properties.recordCreateDate, 'Your record was created on {date_long} at {time_secs} in your timezone.')}"
```

**tip:** Slack supports various tokens to handle date and time formatting. For more information, see [Date formatting](https://api.slack.com/reference/surfaces/formatting#date-formatting).

In your view definition, use the [`mrkdwn` component](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/components/composition.md#mrkdwn) to support date and time formatting.

```yaml
components:
  - definition: section
    properties:
      text:
        text: "{!FORMATSLACKDATE(view.properties.epochSeconds,label.help.dateTimeToken)}\n Here are the available commands for this app"
        type: "mrkdwn"
        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](https://api.slack.com/apps) 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](https://developer.salesforce.com/docs/platform/salesforce-slack-sdk/guide/api_meta/meta_slackapp.md) (`YourSlackAppName.slackapp-meta.xml`) to include the tokens by using the `<botScopes>` or `<userScopes>` field.

## See Also

- [Localizing Your Slack apps](https://api.slack.com/start/designing/localizing)
- [Translate Custom Labels](https://help.salesforce.com/s/articleView?id=platform.cl_translate_edit.htm&type=5)
