AI Integration Quick Reference
AI Integration Quick Reference
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 forCometChatLocalize.init().
CalendarObject
Defines customizable formatting for date and time representation. Supports relative time formatting for minutes and hours.Component Guide
Report Message
To add translations for any flag reason, define a key in the formflag_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 custommentionAllLabel, 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. IfdisableAutoDetection 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 aCalendarObject configuration. Uses the timezone set via init().
Returns a formatted date
string.
getDateLocaleLanguage
Returns the language code used for date localization. IfdisableDateTimeLocalization is true, returns "en-US". Otherwise returns the current language.
Customization
Global Configuration
Apply a custom date format globally across the whole UI Kit viaCometChatLocalize.init():
Component-Specific Configuration
Apply a custom date format only within a specific component. Component-levelCalendarObject overrides the global settings.