Skip to main content
FieldValue
Package@cometchat/chat-uikit-react (replaces v5 packages)
New init patternUIKitSettingsBuilder + CometChatUIKit.init()
ThemingCSS variables replace inline style objects. See Theming
LocalizationCometChatLocalize.init(settings) — language codes changed (e.g., enen-US), new CalendarObject for date formatting
Key changessetLocalesetCurrentLanguage, localizegetLocalizedString, datePatternCalendarObject-based props
The CometChat v6 React UI Kit introduces a revamped localization system with enhanced support for language management, date formatting, and missing key handling. This guide outlines the key differences and provides a step-by-step migration process from v5 to v6.

Overview of Changes

Featurev5v6
InitializationUsed init(language, resources) with separate params.Uses init(settings: LocalizationSettings) with a configuration object.
Translation ManagementManually updated translations using resources.Uses translationsForLanguage in init() and addTranslation().
Language CodesUsed shorthand codes (e.g., en, fr).Uses full language-region codes (e.g., en-US, fr).
Date & Time LocalizationNot configurable.Supports CalendarObject for date formatting.
Timezone HandlingNot available.Introduced timezone setting.
Missing Key HandlerNot available.Introduced missingKeyHandler to handle missing translations.

CometChatLocalize

Initialization

In CometChat v5 UI Kit, the CometChatLocalize.init() accepts 2 parameters: language & resources
V5 UI Kit
CometChatLocalize.init("en", {
  CHATS: "Chats",
});
In CometChat v6 UI Kit, the CometChatLocalize.init() method accepts a localization setting instead of individual parameters.
V6 UI Kit
CometChatLocalize.init({
  language: "en-US",
  translationsForLanguage: {
    "en-US": { conversation_chat_title: "Chats" },
  },
  disableAutoDetection: false,
  disableDateTimeLocalization: false,
  timezone: "Europe/Madrid",
  calendarObject: new CalendarObject({
    today: "hh:mm A",
    yesterday: "[Yesterday]",
    otherDays: "DD MMM YYYY, hh:mm A",
    relativeTime: {
      minute: "%d minute ago",
      minutes: "%d minutes ago",
      hour: "%d hour ago",
      hours: "%d hours ago",
    },
  }),
  missingKeyHandler: (key) => `Missing translation: ${key}`,
});

Language Code Changes

In CometChat v5 UI Kit, the language code for English was en. In CometChat v6 UI Kit, the language codes have been expanded to distinguish between regional variants:
  • en-US for American English
  • en-GB for British English
There are no changes for any other languages.

Managing Translations

In CometChat v5 UI Kit, the only way to add or override translations was by passing them in the init() method.
V5 UI Kit
CometChatLocalize.init("en", {
  CHATS: "Chats",
});
In CometChat v6 UI Kit, translations can be added or overridden using the init() method or the addTranslation() method.
V6 UI Kit
CometChatLocalize.addTranslation({
  "en-US": { conversation_chat_title: "Chats" },
});

Handling Date & Time Localization

CometChat v5 UI Kit lacked support for date formatting, but CometChat v6 UI Kit introduces the CalendarObject for date and time formatting.
V6 UI Kit
const formattedDate = new CalendarObject({
  today: "[Today at] hh:mm A",
  yesterday: "[Yesterday at] hh:mm A",
  otherDays: "DD MMM YYYY, hh:mm A",
});
CometChatLocalize.init({
  calendarObject: formattedDate,
});

Handling Missing Translation Keys

CometChat v5 UI Kit did not handle missing translation keys, whereas CometChat v6 UI Kit introduces a missingKeyHandler for better control.
V6 UI Kit
CometChatLocalize.init({
  missingKeyHandler: (key) => `Missing translation: ${key}`,
});

Migrating JSON Translation Files

In CometChat v5 UI Kit, the language code for English was en.
V5 UI Kit
{
  "en": {
    "CHATS": "Chats"
  }
}
In CometChat v6 UI Kit, the language codes have been expanded to distinguish between regional variants: en-US & en-GB.
V6 UI Kit
{
  "en-US": {
    "conversation": "conversation_chat_title"
  }
}
Make sure your JSON translation files follow the new format.

Additional Resources


Property Changes

In CometChat v6 UI Kit, several props and methods in components and the CometChatLocalize class have been updated. Below is a detailed reference of renamed, added, and removed properties and methods.

Conversations

New Properties

NameTypeDescription
lastMessageDateTimeFormatCalendarObjectFormat for displaying the timestamp of the last message in the conversations list.

Removed Properties

NameTypeDescription
datePatternDatePatternsFormat for displaying the timestamp of the last message in the conversations list.

Message Header

New Properties

NameTypeDescription
lastActiveAtDateTimeFormatCalendarObjectFormat for displaying the “last active” timestamp in the message header.

Message List

New Properties

NameTypeDescription
separatorDateTimeFormatCalendarObjectFormat for the date separators in the message list.
stickyDateTimeFormatCalendarObjectFormat for sticky date headers displayed in the message list.
messageSentAtDateTimeFormatCalendarObjectFormat for the timestamp displayed next to messages.
messageInfoDateTimeFormatCalendarObjectFormat for timestamps displayed in message details (e.g., delivery or read time).

Removed Properties

NameTypeDescription
datePatternDatePatternsFormat for the date separators & sticky date in the message list.
timePatternDatePatternsFormat for the timestamp displayed next to messages.

Thread Header

New Properties

NameTypeDescription
separatorDateTimeFormatCalendarObjectFormat for the date separators.
messageSentAtDateTimeFormatCalendarObjectFormat for the timestamp displayed next to messages.

Call Logs

New Properties

NameTypeDescription
callInitiatedDateTimeFormatCalendarObjectFormat for displaying the call initiation time in call logs.

Removed Properties

NameTypeDescription
datePatternDatePatternsFormat for rendering dates in the call logs.

CometChatLocalize Class

New Methods

NameDescription
addTranslationAdds custom translations to the default translations.
getDefaultLanguageReturns the default language.
getDateLocaleLanguageReturns the language used for date localization.
formatDateFormats a timestamp based on the provided calendar configuration.

Renamed Methods

NameDescriptionOld Name
getCurrentLanguageGets the current language.getLocale
setCurrentLanguageSets the current language.setLocale
getLocalizedStringLocalizes the given string based on the active language.localize

Removed Methods

NameDescription
getLanguageCodeReturns the language code of current language.
setDefaultLanguageSets the default language if no language is passed in init method.
isRTLReturns true if the active language is rtl otherwise return false.
getDirReturns rtl or ltr based on the active language.

Next Steps