Appearance.default.localizationProvider = { key, table in
Bundle.main.localizedString(forKey: key, value: nil, table: table)
}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.
Adding a New Language
- If you don't have
stringsorstringsdictfiles in your project, add those new files toLocalizable.stringsandLocalizable.stringsdict. - Next add new language to the project.
- Copy the StreamChatSwiftUI localization keys into your
stringsandstringsdictfiles. You can find the latest version here. - Set the
localizationProviderto provide yourBundleinstead of the one provided byStreamChatSwiftUISDK (as early as possible in the App lifecycle, for example in theAppDelegate):
- Now, you're ready to implement your
stringsandstringsdictfiles for different languages.
We recommend naming your strings and stringsdict files: Localizable.strings and Localizable.stringsdict.
Override Existing Languages
Overriding the existing language works in the same as adding a new language.
Override Specific Keys
If you only need to change a few strings without replacing the entire localization file, you can capture the default provider and fall back to it for keys you don't need to customize:
let defaultProvider = Appearance.default.localizationProvider
Appearance.default.localizationProvider = { key, table in
switch key {
case "channel.name.missing":
return Bundle.main.localizedString(forKey: "my-own-channel-name-key", value: nil, table: nil)
default:
return defaultProvider(key, table)
}
}This approach lets you selectively override individual keys while keeping the SDK's default translations for everything else.
Resources
Every string included in StreamChat can be changed and translated to a different language. All strings used by UI components are in these two files: