Skip to main content

Localization

ChatUI SDK ships built-in strings for two locales: en_US and zh_CN. If you do not set language explicitly, ChatUI uses en_US. If you pass an unknown language id, ChatUI logs an error and keeps the current language.

In the examples below, en_US is the default UI locale. Where we show custom language packs or a second locale next to en_US, we use en_UK as the pack id so it is clearly distinct from en_US. API reference links in this site use the .../apidoc/nexconnchatui-web/latest/en_US/... path.

Set the default language

Pass language when calling the static initialize method on NCChatUIApplication:

TypeScript
import { NCChatUIApplication } from '@nexconn/chatui';

const app = NCChatUIApplication.initialize({
hooks: { /* ... */ },
language: 'en_US',
});
if (!app) throw new Error('init failed');

Switch language

After ready(), use setLanguage:

JavaScript
app.setLanguage('en_US');

Read the active locale:

JavaScript
const language = app.getLanguage();

Custom language packs

tip

Register custom packs before calling ready().

  • cloneLanguageEntries: copy the built-in strings for a locale so you can patch entries. It returns null if the locale is not registered.
  • registerLanguagePack: register a new locale or override an existing one. The optional third argument sets text direction (ltr by default, or rtl).

Example: clone the built-in en_US table, tweak a key, and register it under en_UK (a separate locale id from en_US):

JavaScript
const entries = app.cloneLanguageEntries('en_US');
if (!entries) throw new Error('Language pack not found');

entries['alert.send.message.maxcount'] =
'Content exceeds {0} characters. Remove some text and try again.';
app.registerLanguagePack('en_UK', entries);

In TypeScript, LanguagePackEntries lists the built-in keys. registerLanguagePack also accepts the string map returned by cloneLanguageEntries:

TypeScript
import type { LanguagePackEntries } from '@nexconn/chatui';

const entries = app.cloneLanguageEntries('en_US');
if (!entries) throw new Error('Language pack not found');

const key: keyof LanguagePackEntries = 'message.menu.item.reply';
entries[key] = 'Quote';

app.registerLanguagePack('en_UK', entries, 'ltr');

List registered languages

JavaScript
const list = app.getSupportedLanguages();

This returns the built-in pack ids plus any packs you registered with registerLanguagePack.