Translating Rey theme and Core plugin

Estimated reading time: 3 min

Every text Rey prints on the front end (buttons, labels, notices, the cart panel, the checkout) can be translated into your language, or simply reworded in English. This article covers the three ways to do it: a translation plugin, a multilanguage plugin, or a short code snippet.

One thing to know before you start: Rey Theme is mostly a skeleton and Rey Core is what adds the features, so the large majority of the strings live in the Rey Core plugin, not in the theme. If a string is missing, that is usually where it is.

Translating into one language, with Loco Translate

If your site runs in a single language and you only need Rey’s own texts translated, Loco Translate is the tool we recommend. It edits the translation files straight from the WordPress admin, no software to install locally.

Its Automatic Translate add-on can machine-translate the whole file in one pass. In practice around 80% of the result is usable as is, and the rest needs a human pass, so treat it as a starting point rather than a finished job.

Three places are worth scanning, in this order:

  • Rey Core (plugin) for everything WooCommerce related and for most of Rey’s features;
  • WooCommerce itself, for cart, checkout and account strings;
  • Rey Theme, for the generic blogging strings.

Both Rey Theme and Rey Core ship a template file (rey.pot and rey-core.pot) that Loco Translate reads, so your language starts from a complete list of strings.

Loco Translate's editor open on Rey Core, showing the string list on top and the translation box underneath, with one string translated.

Here is a short screencast of the whole process: translating Rey Core with Loco Translate (video).

Keep the translations from being wiped by an update

This is the one setting worth getting right from the start. When Loco Translate creates a new language file it asks where to save it, and the answer decides whether your work survives the next Rey update.

  • Custom is the one to pick. Files are stored in /wp-content/languages/loco/, outside the theme and the plugin, so nothing overwrites them.
  • Author saves inside the theme’s or plugin’s own folder, which is emptied on every update. Your translation goes with it.

Loco Translate explains the difference in its manual on file locations.

A string you can see on the site is not in the list

Usually this means the string was added to Rey after your language file was last generated, so Loco Translate simply does not know about it yet. Open the translation and click Sync: it re-reads the current version of the theme or plugin and pulls in everything new. Then search again.

The Loco Translate editor toolbar with the Sync button highlighted, and the "N new strings added" message it shows afterwards.

If it is still missing after a sync, the text is probably not Rey’s. Strings printed by WooCommerce, by another plugin, or typed into a page in Elementor all live elsewhere, and the last kind is not a translation at all, it is content you edit directly.

Running the site in several languages

For a site that serves more than one language, you need a multilanguage plugin instead. Rey has built-in support for WPML, Polylang, TranslatePress, GTranslate.

With any of them active, a Language Switcher widget appears in the Elementor editor’s widgets panel, so you can place the language selector inside your header exactly where you want it. That part is covered in Add Language Switcher into Header, and WPML users have a few extra notes in the WPML article.

Changing a single text with a code snippet

When there is just one word to change and you would rather not manage a translation file for it, a filter in your child theme’s functions.php does the job:

add_filter('gettext', function ($translation, $text, $domain) {
	if( $domain === 'rey-core' ){
		$translation = str_replace('Some Text', 'Translated text', $translation);
	}
	return $translation;
}, 10, 3);

Some strings are registered together with a context (the same word can be translated differently in two places), and those go through a different filter:

add_filter('gettext_with_context', function ($translation, $text, $context, $domain) {
	if( $domain === 'rey-core' ){
		$translation = str_replace('Some Text', 'Translated text', $translation);
	}
	return $translation;
}, 10, 4);

Both examples are limited to one text domain, which is what the $domain check does. Use rey-core for strings coming from the plugin and rey for strings coming from the theme. Keeping that check in place matters: without it the replacement runs against every string on the site, from every plugin, on every page load.

Tip: If you already translate with Loco Translate, do it there instead. The snippet runs on every translated string of that domain, a translation file does not.

Show comments and replies (closed)Hide comments and replies

Left here in 2020, when comments were open. The answers were written then and may describe a version of Rey that has changed since.

  1. Julien

    The auto translate plugin is dead .The free IBM api doesn't work and the Yandex API isn't free anymore. Any alternative ?

  2. Julien

    No need to publish. They published today a fix for that.

  3. MariusRey

    Hey Julien,

    Not sure what you meant with "free IBM api". To be honest i'm also interested in an alternative solution to Yandex API which isn't free anymore. I had noted to find automatic translation solutions too. Thanks!

Was this article helpful?