WordPress: How to change string translations without a plugin

WordPress: How to change string translations without a plugin

WordPress: How to change string translations without a plugin - Photo / screenshot: T.Bortels/cpu20.com

Often a WordPress installation comes with a variety of different languages you can select from. And with every language you get a language file, that is basically containing the various translated strings. Most of those string translations are rather ok – but you may still want to change some of those string translations. You could of course install a plugin for that – basically WMPL or Loco Translate would let you alter those translated strings – but that may often be just a bit too much, if you just want to adjust a single string. So – here is a quite guide on how to change string translation without a plugin.

In my case I wanted to change the translation of some strings in a WooCommerce powered website: we needed to have “objects” instead of “products” because that shop is basically not selling products – but objects. So instead of related products we needed to have the string say related objects.

change strings without a plugin

To accomplish this, you basically just need to add the following lines of code to the file functions.php of your theme or child theme:

function gb_change_cart_string($translated_text, $text, $domain) {
    $translated_text = str_replace(“related products”, “related objects”, $translated_text);
    return $translated_text; 
} 

add_filter(‘gettext’, ‘gb_change_cart_string’, 100, 3);

In the above code the function gb_change_cart_string will hook into the function gettext and return the altered string. So instead of related products the website will show the string related objects. And actually the website does not have to be translated – this solution will also work even if you don’t use any translation – if you are working with the standard English installation. A simple solution that just works. In most cases.

Change WordPress translations, customize individual terms – with plugin

If you want to change more than just 1-2-3 phrases, you can use the Loco Translate plugin, for example, which you can download and install for free here at wordpress.org.

The Loco Translate plugin allows you to customize all entries in the po and mo language files. This means you can also create complete translations for themes and plugins for which there may not even be a translation yet.

Here is a brief introduction to using the Loco Translate plugin.

Translate WordPress websites and WooCommerce webshops with WPML

The WordPress plugin WPML is quite obviously one of the top dogs in the field of translation tools. With the help of a series of additional plugins, virtually all details can be translated – themes, plugins, strings, URLs, even complex web projects and entire online stores based on WooCommerce are no problem for WPML.

However, the translation plug-in also has its price: on the one hand, WPML is resource-intensive. Multilingual web stores in particular can quickly push a shared hosting account to its limits. Sometimes, however, even a simple multilingual website is enough to generate the dreaded “out of memory” error message. The best thing to do is to switch to a dedicated server, sooner or later.

In addition, WPML is not a free plugin. The cheapest Multilingual Blog license starts at $39 per year – the Multilingual CMS license is available for $99 per year. For web designers and web developers, however, the Multilingual CMS Lifetime license probably makes the most sense. Although this costs a whopping $199, you can use it indefinitely. WPML is therefore a standard plugin, so to speak, for professional users who have a dedicated server with the corresponding computing power ready for their customers anyway.