When creating multilingual sites, Polylang is my plugin of choice. The way it handles translations of pages and the functionality it has in the free version is very impressive, and the Pro version even more so. I haven't tried competitor plugins like WPML, because Polylang has always done the job well for me.
When it comes to using Polylang with Oxygen, there are two ways to go about translating your templates:
If you'd like to use option #2, but don't have the time or technical know-how to code it yourself, you can now use our very own Strings Registration for Polylang plugin!
Option 1 is the method that most Polylang users will be familiar with. Simply, you need to enable the translation of templates using the following option under Languages > Settings:
Once you've done this and saved changes, go to your template. You'll see a new metabox containing the Language options for the page. Click the plus icon to create another version of the template, which you can then edit as required. If you've already created the alternative template, you can search for it in the empty white box:
However, this approach has a couple of major issues:
For these reasons, I prefer Option 2.
For this, you can use our no code solution: Strings Registration for Polylang plugin.
Or, continue with the tutorial below:
The free version of Polylang comes with a translation string module included. It enables you to specify strings of texts that are used in your templates, and then dynamically display the correct translation depending on the locale that is being viewed.
The translation strings module looks like this:
If you have plugins with translatable elements installed (e.g. Rank Math, Cookie Notice, etc), then you can filter the strings to show only the ones specific to these plugins. Just click View All Groups and choose the appropriate option.
Before adding translatable strings in your template, you'll need to register them so that they appear among the Polylang strings translations.
From here on in, we'll be relying on some PHP functions outlined in the excellent Polylang function reference document.
add_action('init', function() {
if( function_exists('pll_register_string') ) { // only run if function exists
pll_register_string('Test String', 'Test String US', 'test-group', false);
pll_register_string('Test String 2', 'Test String USA', 'test-group', false);
}
});
As we can see on the Polylang documentation, the function pll_register_string takes 4 arguments:
pll_register_string($name, $string, $group, $multiline);
<?php
if( function_exists('pll_e') ) { // only run if function exists
pll_e('Test String US');
}
?>
The function 'pll_e' will echo (i.e. output) the string in the language the visitor is using, assuming that the string has been already registered and translated as in the previous steps.
Get in touch by emailing alex (at) smoothwebsites.net if you need assistance with setting up a Polylang website with Oxygen.
All features shown in this article are available in the free Polylang plugin found in the WordPress plugin repository. However I would still recommend Polylang Pro for the extra features it provides, such as content synchronization and sharing URL slugs between languages - although the latter is provided by this plugin (not tested).