Skip to main content
FieldValue
Package@cometchat/chat-uikit-react
Importimport { CometChatLocalize } from "@cometchat/chat-uikit-react";
Set languageCometChatLocalize.setCurrentLanguage("fr")
Init with configCometChatLocalize.init({ language: "es", fallbackLanguage: "en-US", disableAutoDetection: false })
Add translationsCometChatLocalize.addTranslation({ "en-US": { "welcome_message": "Welcome!" } })
Supported languages19: en-US, en-GB, nl, fr, de, hi, it, ja, ko, pt, ru, es, tr, zh, zh-TW, ms, sv, lt, hu
Date formattingUse CalendarObject for custom date/time patterns
SourceGitHub
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

LanguageCode
English (United States)en-US
English (United Kingdom)en-GB
Dutchnl
Frenchfr
Germande
Hindihi
Italianit
Japaneseja
Koreanko
Portuguesept
Russianru
Spanishes
Turkishtr
Chinesezh
Chinese (Traditional)zh-TW
Malayms
Swedishsv
Lithuanianlt
Hungarianhu
Language JSON files on GitHub

LocalizationSettings

Configuration interface for CometChatLocalize.init().
PropertyTypeDescription
languagestringLanguage code (e.g., "en", "fr") for the current localization
translationsForLanguage{ [key: string]: any }Key-value pairs for translations in the current language
disableAutoDetectionbooleanDisables automatic language detection based on browser/device settings
fallbackLanguagestringFallback language code if the primary language is not available
disableDateTimeLocalizationbooleanDisables localization for date and time values, forcing the default format
timezonestringTimezone for date and time formatting (e.g., "America/New_York", "Europe/London")
calendarObjectCalendarObjectCustom calendar format for localized date and time formatting
missingKeyHandler(key: string) => voidHandles missing translation keys with custom error handling or fallbacks

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.
PropertyTypeDescription
todaystringFormat for dates on the same day. Example: "Today at hh:mm A"
yesterdaystringFormat for dates on the previous day. Example: "Yesterday at hh:mm A"
lastWeekstringFormat for dates within the last 7 days. Example: "Last week on dddd"
otherDaysstringFormat for dates that do not fit other categories. Example: "DD MMM YYYY, hh:mm A"
relativeTimeobjectCustom formatting for relative time expressions
relativeTime.minutestringSingle minute format. Example: "%d minute ago"
relativeTime.minutesstringMultiple minutes format. Example: "%d minutes ago"
relativeTime.hourstringSingle hour format. Example: "%d hour ago"
relativeTime.hoursstringMultiple hours format. Example: "%d hours ago"

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().
ParameterTypeDescription
timestampnumberUnix timestamp in seconds
calendarObjectCalendarObjectCalendar configuration for formatting
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.