Skip to main content
The CometChatLocalize class manages multi-language localization for the UI Kit. It handles automatic language detection, manual language switching, custom translations, and date/time formatting.

Supported Languages

Language JSON files on GitHub

LocalizationSettings

Configuration interface for CometChatLocalize.init().

CalendarObject

Defines customizable formatting for date and time representation. Supports relative time formatting for minutes and hours.
Changing this format globally updates the date and time representation wherever it is used. If a component-specific CalendarObject is provided, it takes higher precedence over the global settings.

Component Guide

The translation configurations in this section are to be defined inside the CometChat’s init() method callback.

Report Message

To add translations for any flag reason, define a key in the form flag_message_reason_id_{reason_id} with the translated strings. Translations for flag_message_reason_id_spam, flag_message_reason_id_sexual, flag_message_reason_id_harassment are present by default. The reason name is displayed when the required translation is not found.

Mention All

To add translations for a custom mentionAllLabel, define a key in the form message_composer_mention_{label}. The translation for message_composer_mention_all is present by default.

Methods

init

Initializes the localization system with default values and optional configurations.

getBrowserLanguage

Detects the language set in the user’s browser or device settings.

getLocalizedString

Fetches localized text based on the current language.

getCurrentLanguage

Returns the currently set language for the UI Kit.

getDefaultLanguage

Returns the system-preferred language. If disableAutoDetection is enabled, returns the fallback language. Otherwise returns the browser’s preferred language.

setCurrentLanguage

Updates the language at runtime without reloading the application.

addTranslation

Adds custom translations to the existing ones dynamically. New translations are merged into the existing localization data.

formatDate

Formats a Unix timestamp (seconds) based on a CalendarObject configuration. Uses the timezone set via init(). Returns a formatted date string.

getDateLocaleLanguage

Returns the language code used for date localization. If disableDateTimeLocalization is true, returns "en-US". Otherwise returns the current language.

Customization

Global Configuration

Apply a custom date format globally across the whole UI Kit via CometChatLocalize.init():

Component-Specific Configuration

Apply a custom date format only within a specific component. Component-level CalendarObject overrides the global settings.