AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Goal | Add multi-language support with automatic device language detection |
| Provider | CometChatI18nProvider — wrap app to enable localization |
| Import | import { CometChatI18nProvider } from "@cometchat/chat-uikit-react-native"; |
| Auto-detect | <CometChatI18nProvider autoDetectLanguage={true}> |
| Set language | selectedLanguage="fr" — manually set language code |
| Override strings | translations={{ "en-US": { CHATS: "My Chats" } }} |
| Add language | translations={{ "custom": { CHATS: "Welcome" } }} with selectedLanguage="custom" |
| Use in components | const { t } = useCometChatTranslation(); t("CHATS") |
| Supported languages | 19: en-US, en-GB, zh, zh-TW, es, hi, ru, pt, ms, fr, de, sv, lt, hu, it, ko, ja, nl, tr |
| Dependency | Requires react-native-localize package for auto-detection |
CometChatI18nProvider manages multi-language localization for the UI Kit. It handles automatic language detection, manual language switching, and custom translations.
Supported Languages
| Language | Code |
|---|---|
| English (United States) | en-US |
| English (United Kingdom) | en-GB |
| Chinese | zh |
| Chinese (Traditional) | zh-TW |
| Spanish | es |
| Hindi | hi |
| Russian | ru |
| Portuguese | pt |
| Malay | ms |
| French | fr |
| German | de |
| Swedish | sv |
| Lithuanian | lt |
| Hungarian | hu |
| Italian | it |
| Korean | ko |
| Japanese | ja |
| Dutch | nl |
| Turkish | tr |
Provider Props
| Prop | Type | Description |
|---|---|---|
selectedLanguage | string | Language code to use. Defaults to device language or English |
autoDetectLanguage | boolean | Auto-detect device language. Default: true |
translations | object | Custom translation overrides per language |
fallbackLanguage | string | Fallback language if selected is unavailable |
Prerequisites
To enable localization features in your React Native application, you need to install thereact-native-localize package. This package provides native device locale detection and is required for the automatic language detection functionality.
Installation
Install the required dependency:Usage
Here is how you can implement custom localization:Basic Usage (System Language Detection)
- TypeScript
Overriding Translations
- TypeScript
Using Translations in Custom Components
- TypeScript
useCometChatTranslation hook to access translations within components, which can be used when developing custom components.
Methods
useCometChatTranslation
Hook to access translations within components.Customization Capabilities
Below are the things which the developer can customize:- Set a supported language (
selectedLanguage): The developer can set a language out of the 19 supported languages. - Customize default localization strings (
translations): The developer can customize default localization strings for a particular language. - Add custom strings (
translations): A developer can add custom strings in the localization for a particular language. - Add a new language (
translations): The developer can add completely new languages. - Disable auto detection (
autoDetectLanguage): The developer can disable auto detection of device language. - Handle missing keys: The developer can handle missing localization keys.
- Set fallback language (
fallbackLanguage): The developer can set a fallback language.
CometChatI18nProvider component and useCometChatTranslation hook, you can provide a user-friendly, localized experience to your users, enhancing the overall user experience within your application.