Skip to main content
Version: v5

Localize

Overview

CometChat UI Kit provides language localization to adapt to the language of a specific country or region. The CometChatLocalize class allows you to detect the language of your users based on their browser or device settings, and set the language accordingly.

CometChatLocalize is a class that includes methods related to locale. Developers can use these methods to change the language of the UI Kit library.

Presently, the UI Kit supports 12 languages for localization, which are:

  • English (en, en-US, en-GB)
  • Chinese (zh, zh-TW)
  • Spanish (es)
  • Hindi (hi)
  • Russian (ru)
  • Portuguese (pt)
  • Malay (ms)
  • French (fr)
  • German (de)
  • Swedish (sv)
  • Lithuanian (lt)
  • Hungarian (hu)

Methods

Here are the methods included in the CometChatLocalize class:

  • setLocale(Activity activity, @Language.Code String language): This method is used to set the language in the UI Kit. It will take the constant value from the Language class and set the value accordingly.

  • getLocale(): This method is used to get the current language. By default, it will return the current language from the device/browser.

Usage

Here is how you can put these methods into use:

CometChatLocalize.setLocale(getActivity(), Language.Code.hi);

String currentLanguage = CometChatLocalize.getLocale();

By using the CometChatLocalize class, you can provide a user-friendly, localized experience to your users, enhancing the overall user experience within your application.

Customization

CometChat UIKit for Android provides a set of predefined text strings used across various UI components. These strings are stored in the strings.xml resource file. To customize these strings, you can override them in your application's strings.xml file. This allows you to tailor the text displayed in different components to better fit your application's language, branding, or terminology.

Steps to Customize Strings

  1. Identify the String Key
    • Check the UIKit documentation or source code for the exact key of the string you want to modify. String attributes file.
  2. Override the String in Your App
    • Add the key-value pair in your app’s res/values/strings.xml file.
  3. Build and Run Your App
    • The changes will automatically reflect wherever the key is used.
  4. Test Your Changes
    • Ensure the updated text appears correctly in all relevant components.

How It Works

Each UI component in the UIKit references specific string resource keys from the strings.xml file. By redefining these keys in your application's strings.xml, you can change how they appear in the UIKit components.

Example:

Image

In CometChat UIKit, a string resource is defined as:

strings.xml
<resources>
<string name="cometchat_chats" translatable="true">Chats</string>
....
</resources>

This string is used in the CometChatConversations component to label the chat list. Customizing the String To change this text to "Conversations", add the following line in your app’s res/values/strings.xml file:

strings.xml
<resources>
<string name="cometchat_chats" translatable="true">Conversations</string>
....
</resources>

Now, wherever cometchat_chats is referenced in UIKit, it will display "Conversations" instead of the default "Chats". String attributes file for more such customization.

Why Use This Approach?

  1. No Code Modification Required - You don’t need to modify the UIKit source code.
  2. Easy Localization - You can translate strings into different languages using strings.xml.
  3. Seamless UIKit Updates - Updates to UIKit won’t override your customizations.
  4. Flexible Customization - You can tailor the UI text without affecting functionality.