# Chatbot languages: Locale, Strings and translatable texts

> How the chatbot decides the language of a request, how to read its texts in a language, register your own texts in the Language Center, and the filters for languages, fallbacks, right to left, the in-chat language menu and the chat window's texts.

Source: https://www.wpbot.pro/help/dev-chatbot-languages/  
Section: Developers › Hooks  
Updated: 2026-11-28

The chatbot speaks one language per request, decided on the server. Its texts are stored per language and edited in the [Language Center: every chatbot text, in every language](/help/chatbot-language-center/). The classes live in the ChatBot module under the namespace `QuantumCloud\Chatbot\Settings`; their hooks start with `qcld_wpbot_chat/`, like the other [ChatBot hooks](/help/dev-chatbot-hooks/).

## How the language of a request is decided

`Locale::resolve()` takes the first of these that gives a language:

1. An explicit language passed by the caller (a messaging channel's app language, for example).
2. In AJAX and REST requests only: the page language the chat window sends, in the header `X-WPBot-Lang` or the field `wpbot_lang`. It is accepted only when it is one of the site's languages (`Locale::languages()`).
3. Polylang's current language, then WPML's (`wpml_current_language`), then Weglot's.
4. `get_locale()`, which TranslatePress and most other plugins switch.

Then the filter `qcld_wpbot_chat/locale` runs. WPBot Pro hooks into it to apply the **Addresses in this language** rules, on page views only. Nothing reads cookies or the browser, so page caches stay correct per address.

Polylang is checked before WPML because it also answers WPML's filters. With WPML, WPBot uses WPML's documented filters (`wpml_current_language`, `wpml_default_language`, `wpml_active_languages`) and actions.

Tip

Your own AJAX or REST calls that build chatbot texts can send the page's language the same way: add the header `X-WPBot-Lang: fr_FR` (or the field `wpbot_lang`). Page views ignore it; the address decides.

## Locale

| Method | Returns |
| --- | --- |
| `Locale::resolve( array( 'language' => ..., 'channel' => ... ) )` | The locale for this request, for example `fr_FR`. Both keys are optional |
| `Locale::site_default()` | The default language: Polylang's or WPML's default, else the Site Language |
| `Locale::languages()` | The languages the chatbot offers, default first: the translation plugin's languages plus those added in the Language Center |
| `Locale::is_rtl( $locale )` | Whether a locale is written right to left (`''` for this request's) |
| `Locale::normalize( $tag )`, `Locale::base( $locale )` | `fr-fr` → `fr_FR`; `de_DE_formal` → `de` |

## Reading texts

| Method | Returns |
| --- | --- |
| `Strings::get( $key, $locale = '', $with_default = true )` | A text's value in a language: a string, or a list of variants for texts that have them |
| `Strings::text( $key, $locale = '', $fallback = '' )` | One text to show: a random variant, or `$fallback` when empty |
| `Strings::all( $locale = '' )` | Every registered text in a language, key => value |
| `Ui_Texts::get( $slug, ...$args )` | One of the chat window's interface texts in this request's language; `$args` fill `%s` and `%d` like `sprintf()` |

`$key` is the option name of the text (for example `qlcd_wp_chatbot_welcome`). An empty `$locale` means this request's language. The fallback chain is: the exact language → another variant of the same language (`fr_CA` → `fr_FR`) → the default language → any language that has a value → the registered default. A text still at WPBot's English default is shown in the page's language from WPBot's translation files when WordPress runs in that language.

## Register your own texts

Texts you register appear in the Language Center, in a group of their own, with a field per language, and **Translate with AI** drafts them. Register them on `qcld_wpbot_chat/register_strings`:

```
use QuantumCloud\Chatbot\Settings\String_Registry;
use QuantumCloud\Chatbot\Settings\Strings;

add_action( 'qcld_wpbot_chat/register_strings', function () {
	String_Registry::register( 'myplugin_booking_offer', array(
		'type'    => 'list',          // 'text' (one value) or 'list' (variants, one picked at random)
		'group'   => 'booking',       // shown as the group title "Booking"
		'label'   => 'Booking offer',
		'default' => array( 'Would you like to book a table?' ),
	) );
} );

// Later, in the page's language:
$offer = Strings::text( 'myplugin_booking_offer' );
```

| Argument | Meaning |
| --- | --- |
| `type` | `text` or `list` |
| `group` | Group key; unknown groups are titled from the key (`booking` → "Booking") |
| `label` | Field label in the Language Center |
| `default` | Default value (a string, or a list for `list`) |
| `translate` | `false` for names and addresses: **Translate with AI** skips them. Default `true` |

## Filters and actions

| Hook | Type | Parameters | What it is for |
| --- | --- | --- | --- |
| `qcld_wpbot_chat/locale` | filter | `string $locale`, `array $context` | The chatbot's language on this request |
| `qcld_wpbot_chat/default_locale` | filter | `string $locale` | The default language |
| `qcld_wpbot_chat/languages` | filter | `string[] $list`, `string $default` | The languages the chatbot offers (Language Center tabs) |
| `qcld_wpbot_chat/locale_is_rtl` | filter | `bool $rtl`, `string $locale` | Whether a language is right to left |
| `qcld_wpbot_chat/string` | filter | `$value`, `string $key`, `string $locale`, `string $matched` | A text in a language. `$matched` is the stored language the value came from (`''` for the registered default). WPBot Pro uses it for WPML and Polylang String Translation |
| `qcld_wpbot_chat/translated_default` | filter | `$translated`, `string $key`, `$english` | A stock text in the visitor's language; return the translation of your own default texts (`null` when unknown) |
| `qcld_wpbot_chat/register_strings` | action | none | Register translatable texts with `String_Registry::register()` |
| `qcld_wpbot_chat/per_language_options` | filter | `string[] $options` | Options stored per language whose other languages a save must keep. Saving one language never deletes the others for these options and every registered text |
| `qcld_wpbot_chat/strings_per_language` | filter | `bool $per_language`, `string $key` | Whether a text is stored per language (default: when the site has more than one language) |
| `qcld_wpbot_chat/strings_migrated` | action | `$changed`, `$from` | The texts' storage was updated (a backup was made first) |
| `qcld_wpbot_chat/strings_restored` | action | `string $id` | A Language Center backup was restored |

WPBot Pro adds these:

| Hook | Type | Parameters | What it is for |
| --- | --- | --- | --- |
| `qcld_wpbot_chat/language_dropdown` | filter | `bool $enabled` (default `false`) | Show a language list inside the chat window. With it on, the window gets every language's texts and switches in the browser |
| `qcld_wpbot_chat/url_language_sniff` | filter | `bool $sniff` (default `false`) | Let the chat window guess the language from the first part of the address (`/fr/…`), for browser-based translators such as GTranslate |
| `qcld_wpbot_lc/saved` | action | `string $locale` | A language's texts were saved in the Language Center |
| `qcld_wpbot_lc/purged_caches` | filter | `string[] $done` | The page caches the Language Center cleared after a save; clear your own and add its name |
| `qcld_wpbot_lc/fill_language` | filter | `string $message`, `string $locale`, `bool $overwrite` | Fill a language from the default one (WPBot Pro's **Translate with AI** answers here) |

### Example: show the language list in the chat window

```
add_filter( 'qcld_wpbot_chat/language_dropdown', '__return_true' );
```

### Example: clear your own cache after a save

```
add_filter( 'qcld_wpbot_lc/purged_caches', function ( array $done ) {
	my_cdn_purge_all(); // Your CDN's purge function.
	$done[] = 'My CDN';
	return $done;
} );
```

## The chat window's texts in JavaScript

WPBot Pro prints the chat window's interface texts in the page's language as `wp_chatbot_obj.ui` (slug => text), with `wp_chatbot_obj.language`, `wp_chatbot_obj.site_language` and `wp_chatbot_obj.rtl`. Two helpers read them: `wpbotUi( slug, fallback )` returns the text HTML-escaped, `wpbotUiRaw( slug, fallback )` returns it as it is.

## Code written for the Multi-Language module

The Multi-Language module is retired. `qcld_wpbotml()` still answers (`languages`, `lanName()`, `helper->languages()`) on sites with several languages, so code written for the module keeps working. The texts keep the storage format WPBot 15.x reads, so going back to an older version keeps them.

## Availability

`Locale`, `Strings`, `String_Registry`, `Ui_Texts` and the `qcld_wpbot_chat/` hooks are in the ChatBot module, in every edition. The Language Center, the address rules, String Translation, the `qcld_wpbot_lc/` hooks, the language list filters and the JavaScript helpers are in every WPBot Pro edition (Starter, Professional and Master).
