Localization

Introduction

If your app supports multiple languages, the chat SDK has support for localizations. For example, you can add more languages, or you can change translations for the existing texts used throughout the SDK.

The SDK resolves every user-facing string through Appearance.default.localizationProvider. Overriding that provider is the single integration point for customizing strings.

Customizing Localizations

The recommended way to customize the SDK's strings is to capture the default localizationProvider and chain your app's Localizable.strings / Localizable.stringsdict after it. With this pattern you only ship the keys you actually want to customize; the SDK keeps using its bundled translations for everything else, so any new keys introduced in a future SDK release keep working without any changes on your side:

let localizationProvider = Appearance.default.localizationProvider
Appearance.default.localizationProvider = { key, table in
    let defaultString = localizationProvider(key, table)
    let customString = Bundle.main.localizedString(forKey: key, value: nil, table: table)

    return customString != key ? customString : defaultString
}

Set the localizationProvider as early as possible in the app lifecycle (for example, right after initializing StreamChat).

The same pattern works whether you want to override a single string, translate to a new language, or both. Add the keys you want to translate to your app's Localizable.strings / Localizable.stringsdict (per locale, see adding a new language to your project), and the provider above will pick them up automatically.

We recommend naming your strings and stringsdict files: Localizable.strings and Localizable.stringsdict.

We don't recommend replacing the provider with a closure that reads from Bundle.main only. If you do, every key the SDK introduces in a future release that you haven't translated yet will silently render as the raw key (e.g. channel.name.missing), since your bundle is no longer chained to the SDK's defaults.

Resources

Every string used by StreamChatSwiftUI can be overridden through the localizationProvider. The full set of keys (and their default English translations) lives in: