Localize
Overview
CometChat UI Kit provides language localization to adapt to the language of a specific country or region. The CometChatLocalize class allows you to detect the language of your users based on their browser or device settings, and set the language accordingly.
CometChatLocalize is a class that includes methods related to locale. Developers can use these methods to change the language of the UI Kit library.
Presently, the UI Kit supports 17 languages for localization, which are:
- English (en, en-US)
- English-UK (en-GB)
- Chinese (zh, zh-TW)
- Spanish (es)
- Hindi (hi)
- Russian (ru)
- Portuguese (pt)
- Malay (ms)
- French (fr)
- German (de)
- Swedish (sv)
- Lithuanian (lt)
- Hungarian (hu)
- Dutch (nl)
- Japanese (ja)
- Korean (ko)
- Turkish (tr)
How Localization Works
Localization in the SDK is powered by:
- The CometChatLocalize class — for setting and fetching the active locale.
- A String extension method called
.localize
— to fetch localized text dynamically.
Example:
"CHATS".localize
The SDK checks the following bundles in order:
- The app's Localizable.strings (for developer-defined overrides)
- The SDK's built-in localization files
- Fallback to English or the original key if no match is found
Methods
Here are the methods included in the CometChatLocalize class:
Method | Description |
---|---|
set(locale:) | Sets the language using Language enum (.english, .french, etc.) |
getLocale() | Returns the currently active locale. By default, it will return the current language from the device/browser. |
Usage
Here is how you can put these methods into use:
- Swift
// Set Language to French
CometChatLocalize.set(locale: .french)
// Get Current Language
let lang = CometChatLocalize.getLocale()
App-Level Overrides
To customize any text used by the SDK, simply define the same key in your app’s Localizable.strings files.
Example – Localizable.strings (en.lproj):
- Swift
"CHATS" = "Conversations";
"USERS" = "People";
When your app runs, this will override the SDK’s built-in translation for "CHATS" and "USERS" wherever they are used via .localize.
No additional configuration is needed.
How to discover available keys
All localization keys used by the SDK are available in our GitHub repository. This allows you to:
- Know exactly which keys are used
- Provide custom translations for them in your app
- Keep your localization files in sync with SDK updates
By using the CometChatLocalize class, you can provide a user-friendly, localized experience to your users, enhancing the overall user experience within your application.
Customization
CometChatUIKit for iOS allows developers to customize localization values easily. For example, if an English-language app requires the label "Chat" to be shown as "Chats," the developer can simply define the same localization key used in the UIKit inside the app's English localization file and assign it a different value. CometChatUIKit will automatically detect and use the overridden value from the app-level localization.
Steps to Customize Strings
- Identify the String Key
- Check the UIKit source code for the exact key of the string you want to modify. Localization file.
- Navigate to the app level localization file for that same langauge
- Added the same key with the changed vale you whant value.
- Build and Run Your App
- The changes will automatically reflect wherever the key is used.
DateTimeFormatter
This feature allows developers to customize how date and time values are displayed across the CometChat UI Kit components. It introduces the CometChatDateTimeFormatter class, enabling tailored formatting for strings such as "Today", "Yesterday", or time formats like "12:00 PM".
Custom formats can be set based on locale, branding, or user preferences, enhancing localization and UX consistency.
Rather than always showing a static date like "27/04/2025, 3:45 PM", developers can customize how the date is displayed depending on how old the message is — such as:
- "Just now"
- "2 minutes ago"
- "Today, 3:45 PM"
- "Yesterday, 4:20 PM"
- "Last week", etc.
This system uses closures that you can override to provide your own custom strings.
CometChatDateTimeFormatter
CometChatDateTimeFormatter
is a configuration class that exposes customizable closures for various time-related strings. Developers can assign custom behavior to each closure based on their desired formatting logic.
Available closures
Property | Description | Code |
---|---|---|
time | Called to format a timestamp as a standard time (e.g., "12:30 PM"). | CometChatUIKit.dateTimeFormatter.time = { ... } |
today | Called when rendering messages sent today. | CometChatUIKit.dateTimeFormatter.today = { ... } |
yesterday | Called for yesterday's messages. | CometChatUIKit.dateTimeFormatter.yesterday = { ... } |
lastweek | Called for messages within the last week. | CometChatUIKit.dateTimeFormatter.lastweek = { ... } |
otherDay | Called for dates older than last week. | CometChatUIKit.dateTimeFormatter.otherDay = { ... } |
minute | Called when referring to "a minute ago". | CometChatUIKit.dateTimeFormatter.minute = { ... } |
minutes | Called for "x minutes ago". | CometChatUIKit.dateTimeFormatter.minutes = { ... } |
hour | Called for "an hour ago". | CometChatUIKit.dateTimeFormatter.hour = { ... } |
hours | Called for "x hours ago". | CometChatUIKit.dateTimeFormatter.hours = { ... } |
Each closure receives a timestamp (Int, representing UNIX time) and must return a String representing the formatted time.
Integration Options
The formatter can be applied at three levels:
- Global Level: A global formatter is available via
CometChatUIKit.dateTimeFormatter
. Use this to apply formatting across all components in theCometChatUIKit
.
- Swift
CometChatUIKit.dateTimeFormatter.hour = { timestamp in
return "Today"
}
CometChatUIKit.dateTimeFormatter.time = { timestamp in
return "12:00 PM"
}
- Component Global Level: Each component has a static formatter that overrides the global formatter only for that component across all instances.
- Swift
CometChatMessageList.dateTimeFormatter.hour = { timestamp in
return "Today"
}
CometChatMessageList.dateTimeFormatter.time = { timestamp in
return "12:00 PM"
}
- Local Component Level: Components also expose an instance-level formatter for per-instance customization. This provides the highest precedence.
- Swift
let messageList = CometChatMessageList()
messageList.set(user: user)
messageList.dateTimeFormatter.hour = { timestamp in
return "Today"
}
messageList.dateTimeFormatter.time = { timestamp in
return "12:00 PM"
}
Component-Level Date-Time Formatting Options
The following components support dateTimeFormatter:
Each of these components checks the most relevant closure in CometChatDateTimeFormatter based on the timestamp and context.
The CometChatDateTimeFormatter
gives developers fine-grained control over how date and time appear throughout their app. Whether you’re customizing for locale, branding, or clarity, this system ensures your app’s time formatting is as user-friendly and context-aware as possible.