Skip to main content
Set the CometChat UI Kit language and override UI text so your Android app matches your users’ locale.

When to use this

  • You want the UI Kit to follow the device language.
  • You want to force a specific language regardless of device settings.
  • You need to override default UI Kit labels with brand-specific wording.
  • You want consistent date and time labels across all UI Kit screens.

Prerequisites

  • CometChat UI Kit for Android is installed and initialized. Use Getting Started if needed.
  • You can access an Android Context (Activity or Application) to apply locale changes.
  • You can edit res/values/strings.xml in your app module.

Quick start

  1. Choose a language code from Supported languages.
  2. Add a locale call before you render UI Kit screens. File: app/src/main/java/<your_package>/LocalizeActivity.java or app/src/main/java/<your_package>/LocalizeActivity.kt. Use the code in Implementation > Set and read the UI Kit locale.
  3. Override UI text keys in res/values/strings.xml if you need custom wording.
  4. Rebuild and run the app.
  5. Verify that UI Kit labels render in the selected language and your custom strings appear.

Core concepts

  • CometChatLocalize: Utility class to set and read the UI Kit locale from an Android Context.
  • Language.Code: Constants for supported language codes to use with setLocale.
  • strings.xml: Android string resources that control the visible text in UI Kit components.
  • DateTimeFormatterCallback: Callback interface to control date and time labels like “Today” or “X mins ago”.

CometChatLocalize methods

  • setLocale(Context context, @Language.Code String language): Sets the UI Kit language using a Language.Code value.
  • getLocale(Context context): Returns the current locale country code for the provided context.

Supported languages

UI Kit supports 19 languages for localization:
  • Arabic (ar)
  • Chinese (zh)
  • Chinese (Traditional) (zh-TW)
  • Dutch (nl)
  • English (en)
  • French (fr)
  • German (de)
  • Hindi (hi)
  • Hungarian (hu)
  • Italian (it)
  • Japanese (ja)
  • Korean (ko)
  • Lithuanian (lt)
  • Malay (ms)
  • Portuguese (pt)
  • Russian (ru)
  • Spanish (es)
  • Swedish (sv)
  • Turkish (tr)

Implementation

Set and read the UI Kit locale

What you’re changing: The UI Kit language for your app session.
  • Where to change it: Your Activity or Application class before UI Kit screens are rendered.
  • Applies to: All UI Kit screens.
  • Default behavior: UI Kit uses the device locale.
  • Override: Call CometChatLocalize.setLocale(...) with a Language.Code value.
  • Code:
LocalizeActivity.kt
  • What this does: Sets the UI Kit language to Hindi for the current context and reads the current locale value for later use.
  • Verify: Launch a UI Kit screen and confirm labels display in the selected language.

Override UI Kit strings in strings.xml

What you’re changing: Visible text used by UI Kit components.
  • Where to change it: app/src/main/res/values/strings.xml in your app module.
  • Applies to: All UI Kit components that reference the string key.
  • Default behavior: UI Kit uses its internal strings.xml values.
  • Override: Add the same key to your app’s strings.xml to override the label.
Example reference from UI Kit strings.xml:
strings.xml
  • What this does: Shows the default UI Kit label for the conversations list.
Override the key in your app:
res/values/strings.xml
  • What this does: Replaces the UI Kit label with your custom text.
Why use this approach:
  • No UI Kit source code changes required.
  • Easy localization using Android resources.
  • UI Kit updates do not overwrite your overrides.
  • You can tailor text without affecting behavior.

Customize date and time labels

What you’re changing: Global time and date labels such as “Today”, “Yesterday”, and “X mins ago”.
  • Where to change it: Your UI Kit initialization (where you build UIKitSettings).
  • Applies to: All UI Kit screens that display timestamps.
  • Default behavior: UI Kit uses its built-in formatter.
  • Override: Provide a DateTimeFormatterCallback when building UIKitSettings.
  • Code:
AppInit.kt
  • What this does: Registers a global DateTimeFormatterCallback so all UI Kit timestamps use your formatting rules.
  • Verify: Open a conversation list and confirm labels like “Today” or “X mins ago” match your formatter.
For the full callback reference, see CometChatUIKit methods: DateFormatter.

Customization matrix