AI Agent Component Spec
AI Agent Component Spec
| Field | Value |
|---|---|
| Package | @cometchat/chat-uikit-react |
| Import | import { CometChatLocalize } from "@cometchat/chat-uikit-react"; |
| Set Language | CometChatLocalize.setCurrentLanguage("fr") |
| Add Translations | CometChatLocalize.addTranslation({ "en-US": { "key": "value" } }) |
| Supported Languages | 19 languages including en-US, fr, de, es, ja, zh, and more |
| Date Formatting | Use CalendarObject for custom date/time patterns |
Overview
This guide shows you how to add multi-language support to your CometChat React app. You’ll learn to set languages, add custom translations, and format dates for different locales. Time estimate: 10 minutes Difficulty: BeginnerPrerequisites
- React.js Integration completed
- CometChat UI Kit initialized
Use Cases
Localization is essential for:- Global apps — Support users in their native language
- Regional compliance — Display dates/times in local formats
- Custom terminology — Replace default UI text with your brand’s language
- Accessibility — Improve comprehension for non-English speakers
Supported Languages
| Language | Code | Language | Code |
|---|---|---|---|
| English (US) | en-US | Japanese | ja |
| English (UK) | en-GB | Korean | ko |
| French | fr | Portuguese | pt |
| German | de | Russian | ru |
| Spanish | es | Chinese | zh |
| Italian | it | Chinese (Traditional) | zh-TW |
| Dutch | nl | Malay | ms |
| Hindi | hi | Swedish | sv |
| Turkish | tr | Lithuanian | lt |
| Hungarian | hu |
Steps
Step 1: Initialize Localization
Configure localization during app initialization:App.tsx
Step 2: Set Language at Runtime
Change the language dynamically without reloading:LanguageSwitcher.tsx
Step 3: Add Custom Translations
Add or override translations for specific keys:CustomTranslations.tsx
Step 4: Customize Date/Time Formatting
UseCalendarObject to customize how dates and times are displayed:
DateFormatting.tsx
Step 5: Component-Specific Date Formats
Override date formats for specific components:MessageHeaderWithCustomDate.tsx
Complete Example
Here’s a full implementation with language switching and custom translations:LocalizedChatApp.tsx
Localization API Reference
Localization API Reference
Methods
| Method | Description |
|---|---|
init(settings) | Initialize with configuration |
setCurrentLanguage(code) | Change language at runtime |
getCurrentLanguage() | Get current language code |
getDefaultLanguage() | Get system/fallback language |
getBrowserLanguage() | Detect browser language |
addTranslation(translations) | Add custom translations |
getLocalizedString(key) | Get translated string by key |
formatDate(timestamp, calendarObject) | Format a Unix timestamp |
LocalizationSettings
| Property | Type | Description |
|---|---|---|
language | string | Language code (e.g., "en-US") |
fallbackLanguage | string | Fallback if primary unavailable |
disableAutoDetection | boolean | Disable browser language detection |
timezone | string | Timezone for dates (e.g., "America/New_York") |
calendarObject | CalendarObject | Custom date/time formats |
missingKeyHandler | (key) => void | Handle missing translation keys |
Special Translation Keys
Special Translation Keys
Common Issues
| Issue | Solution |
|---|---|
| Translations not showing | Ensure addTranslation is called after CometChatUIKit.init() |
| Wrong language detected | Set disableAutoDetection: true and specify language explicitly |
| Date format not changing | Check timezone is set correctly in init config |
| Missing translation key | Use missingKeyHandler to log or handle missing keys |
| Component ignores global format | Component-level CalendarObject overrides global settings |
Next Steps
Theming Guide
Customize UI appearance
Custom Formatters Guide
Create custom text formatters
Messaging Guide
Build the messaging experience
Conversations Guide
Display conversation list