Skip to main content
Version: v5

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)

Methods

Here are the methods included in the CometChatLocalize class:

  • set(locale: Language): This method is used to set the language in the UI Kit. It takes the enum value from Language enum and sets the value accordingly.

  • getLocale( ): This method is used to get the current language. By default, it will return the current language from the device/browser.

Usage

Here is how you can put these methods into use:

// Set Language
CometChatLocalize().set(locale: .french)

// Get Language
CometChatLocalize().getLocale()

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

  1. Identify the String Key
    • Check the UIKit source code for the exact key of the string you want to modify. Localization file.
  2. Navigate to the app level localization file for that same langauge
    • Added the same key with the changed vale you whant value.
  3. 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

PropertyDescriptionCode
timeCalled to format a timestamp as a standard time (e.g., "12:30 PM").CometChatUIKit.dateTimeFormatter.time = { ... }
todayCalled when rendering messages sent today.CometChatUIKit.dateTimeFormatter.today = { ... }
yesterdayCalled for yesterday's messages.CometChatUIKit.dateTimeFormatter.yesterday = { ... }
lastweekCalled for messages within the last week.CometChatUIKit.dateTimeFormatter.lastweek = { ... }
otherDayCalled for dates older than last week.CometChatUIKit.dateTimeFormatter.otherDay = { ... }
minuteCalled when referring to "a minute ago".CometChatUIKit.dateTimeFormatter.minute = { ... }
minutesCalled for "x minutes ago".CometChatUIKit.dateTimeFormatter.minutes = { ... }
hourCalled for "an hour ago".CometChatUIKit.dateTimeFormatter.hour = { ... }
hoursCalled 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:

  1. Global Level: A global formatter is available via CometChatUIKit.dateTimeFormatter. Use this to apply formatting across all components in the CometChatUIKit.
CometChatUIKit.dateTimeFormatter.hour = { timestamp in
return "Today"
}

CometChatUIKit.dateTimeFormatter.time = { timestamp in
return "12:00 PM"
}
  1. Component Global Level: Each component has a static formatter that overrides the global formatter only for that component across all instances.
CometChatMessageList.dateTimeFormatter.hour = { timestamp in
return "Today"
}

CometChatMessageList.dateTimeFormatter.time = { timestamp in
return "12:00 PM"
}
  1. Local Component Level: Components also expose an instance-level formatter for per-instance customization. This provides the highest precedence.
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.