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.
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.
Property
Type
Description
today
string
Format for dates on the same day. Example: "Today at hh:mm A"
yesterday
string
Format for dates on the previous day. Example: "Yesterday at hh:mm A"
lastWeek
string
Format for dates within the last 7 days. Example: "Last week on dddd"
otherDays
string
Format for dates that do not fit other categories. Example: "DD MMM YYYY, hh:mm A"
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.
import { CometChatLocalize } from "@cometchat/chat-uikit-react";CometChatLocalize.addTranslation({ "en-GB": { "flag_message_reason_id_dislike": "I just don't like it", }, "es": { "flag_message_reason_id_dislike": "Simplemente no me gusta", }});
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.
Returns the system-preferred language. If disableAutoDetection is enabled, returns the fallback language. Otherwise returns the browser’s preferred language.