Skip to main content

Overview

React UI Kit provides multi-language localization to adapt the UI elements based on the user’s preferred language settings. The CometChatLocalize class allows developers to:
  • Automatically detect and apply a language based on browser/device settings.
  • Manually change the UI language.
  • Format date and time based on localization settings.
The v6 React UI Kit expands support for multiple languages and allows developers to define custom translations.
The localization system now includes language JSON files, which store translations, and an improved CometChatLocalize class, which handles language detection and formatting.

Supported Languages

React UI Kit currently supports 19 languages: 🔗 View JSON files for all supported languages in the GitHub repository:
Language JSON Files

CometChatLocalize

The CometChatLocalize class provides methods for managing localization in the UI Kit. 🔗 View full class file in the GitHub repository:
CometChatLocalize

LocalizationSettings

The LocalizationSettings interface defines various localization settings for an application or component. It allows developers to configure the language, translations, time zone, and calendar formatting while providing options for automatic detection and missing key handling.
Example

CalendarObject

The CalendarObject class defines customizable formatting for date and time representation. It allows you to format dates based on whether they are today, yesterday, last week, or other days. It also supports relative time formatting for minutes and hours.
NoticeChanging this format will globally update the date and time representation wherever it is used in the component.
However, if a component-specific CalendarObject is provided, it will take higher precedence over the global settings.

Example

Component Guide

NoteThe translation configurations mentioned in this section are to be defined inside the ComeChat’s init() method callback.

Report Message

To add translations for any flag reason, a key in the form of flag_message_reason_id_{reason_id} is to be defined with the translated strings to be displayed for that reason_id in the UI. The translations for flag_message_reason_id_spam, flag_message_reason_id_sexual, flag_message_reason_id_harassment are present by default. Usage
  • Define translations for custom flag message reasons.
  • The reason name would be displayed when the required translation is not found.
Example

Mention All

To add translations for a custom mentionAllLabel, a key in the form of message_composer_mention_{label} is to be defined with the translated strings to be displayed for that label in the UI. The translations for message_composer_mention_all is present by default. Usage
  • Define translations for custom mentionAllLabel.
  • Helps customize the @all label used in the app while mentioning all group members.
Example

Methods

Initialize CometChatLocalize

This method initializes the localization system with default values and optional configurations. Usage
  • Set the default language, timezone, and fallback settings.
  • Define a custom calendar format if required.
  • Customize how missing keys are handled.
Example

Get Browser Language

This method detects the language set in the user’s browser or device settings. Usage
  • Automatically set the app’s language based on the user’s browser settings.
  • Helps in making the UI multilingual without requiring user input.
Example

Get Localized String

This method fetches localized text based on the current language. Usage
  • Retrieve translations dynamically without hardcoding values in multiple languages.
  • Useful for UI elements, buttons, alerts, and system messages.
Example

Get Current Language

This method returns the currently set language for the UI Kit. Usage
  • Useful to debug and display the currently active language.
  • Helps when dynamically switching between languages.
Example

Get Default Language

This method returns the system-preferred language. Usage
  • If disableAutoDetection is enabled, the method returns the fallback language.
  • If auto-detection is enabled, it returns the browser’s preferred language.
Example

Set Current Language

This method updates the language at runtime without reloading the application. Usage
  • Allow users to change the language via a settings menu.
  • Ensure that UI elements are updated instantly after changing the language.
Example

Add Custom Translations

This method allows you to add custom translations to the existing ones dynamically. It ensures that new translations are merged into the existing localization data. Usage
  • You can define custom translation keys and override the existing translations.
  • You can add new languages to the existing translations.
  • Useful when you want to support additional words or phrases not present in the default language files.
Example

Customisation

CometChat UI Kit provides flexible customization options for date/time format. Users can configure global settings using CometChatLocalize.init() or pass a CalendarObject directly to individual components for component-specific customization.
  • Global Configuration: When settings are provided in CometChatLocalize.init(), all UI components will automatically use the configured date/time formats.
  • Component-Specific Configuration: If a CalendarObject is passed to a component, it overrides the global settings and applies only to that specific instance.
Global Configuration Example To apply a custom date format globally across the whole UI Kit.
Component-Specific Customization Example To apply a custom date format only within a specific component.