Skip to main content

Better Messages for GTranslate: Multilingual Chat Interface

Compatibility
This guide compatible with Better Messages 2.15.24 or higher

Overview#

GTranslate paid plans serve each language through a Translation Delivery Network — a proxy which mirrors your website under its own sub-domain or sub-directory (for example de.example.com or example.com/de/) and translates the generated HTML. It does not change the WordPress site language, and it cannot translate texts which live inside JavaScript files.

The Better Messages interface is rendered by JavaScript, and all its labels come from Better Messages translation files which follow the WordPress site language. Without integration this means the messenger interface stays in the site default language on every GTranslate language version, even though the rest of the page around it is translated.

Better Messages automatically detects GTranslate and switches the messenger interface language to match the current GTranslate language — the full messenger page, mini chat widgets, chat popups and dialogs all follow the language of the page the visitor is on.

info

The integration is included in both the free and WebSocket versions of Better Messages and activates automatically when GTranslate is detected — no configuration needed

GTranslate plan requirement#

This integration works on GTranslate paid plans with a sub-domain or sub-directory URL structure. On those plans the Translation Delivery Network tells your server which language the visitor is reading, and Better Messages loads the matching interface language.

The free GTranslate version translates the page in the visitor's browser after it has loaded, and the selected language is never sent to your server. Because of this the server cannot know which language to load, and the messenger interface stays in the site default language. This is a limitation of client-side translation, not of Better Messages.

How it works#

  • On translated pages Better Messages loads its own translation for the current GTranslate language, using standard WordPress translation files
  • On original language pages nothing changes
  • Conversation messages are never sent to GTranslate — message content stays private and does not consume your GTranslate quota

Installing languages#

For every GTranslate destination language, the matching WordPress language pack needs to be installed once:

  1. Go to Settings → General → Site Language, select the language and press Save Changes — this installs the language into WordPress
  2. Switch Site Language back to your original language and save again
  3. Repeat for each GTranslate language
  4. Go to Dashboard → Updates and press Update Translations — Better Messages translations for the installed languages will download automatically

English requires no installation — the built-in Better Messages texts are English.

There are three possible results per language:

  • Language pack installed and Better Messages is translated into it — the messenger interface follows the GTranslate language
  • Language pack not installed — the messenger interface stays in the site default language on that GTranslate language version
  • Language pack installed but Better Messages has no translation for it yet — the messenger interface shows the built-in English texts. Translations are community contributed, and a missing language can be translated with Loco Translate

What is translated#

  • Interface texts — buttons, labels, placeholders, dialogs. These come from Better Messages translations and can be customized per language with Loco Translate, including English via an "English (United States)" translation
  • Conversation messages are not translated by this integration. To translate actual messages between users speaking different languages, use AI Message Translation
  • Custom texts entered in Better Messages settings are not part of translation files and stay exactly as entered

Page caching#

The language of a request is known from a request header sent by the Translation Delivery Network. If a caching plugin on your server stores one copy of a page for all languages, every language version can be served the interface language of whichever visitor filled the cache first.

If you use page caching together with GTranslate, exclude the translated versions from caching or configure the cache to vary by language. GTranslate's own documentation covers this for server side language detection in general.

Customization#

GTranslate uses Google language codes while WordPress uses full locales. Better Messages resolves them automatically — exact match first, then the first installed regional variant (for example itit_IT), with special cases built in for codes which would otherwise resolve to the wrong variant or to nothing at all:

enen_US, dede_DE, frfr_FR, nlnl_NL, eses_ES, ptpt_BR, fafa_IR, svsv_SE, dada_DK, nonb_NO, zh-CNzh_CN, zh-TWzh_TW, iwhe_IL, jwjv_ID

A special case is only used when that exact language pack is installed, so a site which has only es_MX installed still gets es_MX for Spanish.

REQUIREMENTS

To be able to implement this guide, you need to learn how to insert PHP snippets to your website.

You can find guide here: WP Beginner

To override the mapping for a specific GTranslate language code:

add_filter( 'better_messages_gtranslate_locales_map', function ( $map ) {
$map['en'] = 'en_GB';

return $map;
} );

For custom multilingual setups without GTranslate, the underlying better_messages_i18n_locale filter controls which language the messenger interface loads on the current page:

add_filter( 'better_messages_i18n_locale', function ( $locale, $script_handle ) {
if ( my_site_is_english_version() ) {
return 'en_US';
}

return $locale;
}, 10, 2 );