Black Friday! Use coupon code MONSTER at checkout for a discount!

Chatbot languages: Locale, Strings and translatable texts

On this page

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. 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.

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

MethodReturns
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

MethodReturns
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' );
ArgumentMeaning
typetext or list
groupGroup key; unknown groups are titled from the key (booking → "Booking")
labelField label in the Language Center
defaultDefault value (a string, or a list for list)
translatefalse for names and addresses: Translate with AI skips them. Default true

Filters and actions

HookTypeParametersWhat it is for
qcld_wpbot_chat/localefilterstring $locale, array $contextThe chatbot's language on this request
qcld_wpbot_chat/default_localefilterstring $localeThe default language
qcld_wpbot_chat/languagesfilterstring[] $list, string $defaultThe languages the chatbot offers (Language Center tabs)
qcld_wpbot_chat/locale_is_rtlfilterbool $rtl, string $localeWhether a language is right to left
qcld_wpbot_chat/stringfilter$value, string $key, string $locale, string $matchedA 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_defaultfilter$translated, string $key, $englishA stock text in the visitor's language; return the translation of your own default texts (null when unknown)
qcld_wpbot_chat/register_stringsactionnoneRegister translatable texts with String_Registry::register()
qcld_wpbot_chat/per_language_optionsfilterstring[] $optionsOptions 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_languagefilterbool $per_language, string $keyWhether a text is stored per language (default: when the site has more than one language)
qcld_wpbot_chat/strings_migratedaction$changed, $fromThe texts' storage was updated (a backup was made first)
qcld_wpbot_chat/strings_restoredactionstring $idA Language Center backup was restored

WPBot Pro adds these:

HookTypeParametersWhat it is for
qcld_wpbot_chat/language_dropdownfilterbool $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_snifffilterbool $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/savedactionstring $localeA language's texts were saved in the Language Center
qcld_wpbot_lc/purged_cachesfilterstring[] $doneThe page caches the Language Center cleared after a save; clear your own and add its name
qcld_wpbot_lc/fill_languagefilterstring $message, string $locale, bool $overwriteFill 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).

What WordPress users say.

Customer support is very responsive and professional. The script is awesome and with many features, including A.I. from Dialogflow. High quality.
Newpolaris
CEO, Invision Inc.
I am extremely happy to use WPBOT on my website. Very quick, simple to use, it has the right features and the support is extremely friendly and quick.
Expressionsindia
Store Manager, Walmart Inc
Great plugin. Works very well with DialogueFlow and builds natural conversations. The free plugin it is very good. I adjusted the layout with custom css, which i really liked. And they have a free support service where they reply quickly. Definitly recommend.
Mariedgdg
Store Manager, Walmart Inc

Got more questions?

Contact our ChatBot Support Heroes. They’ll provide you with all the information you need.

Contact us

© 2002- 2026 QuantumCloud

X
Let's chat if you need any help finding the right product or need support.
FAQSend Us Email