Author: Alexander Buzmakov
When creating a multilingual website in Oxygen, the question of choosing the optimal plugin for content translation always arises. I have been using the Polylang plugin on several multilingual sites for over a year now and it has worked well.
Today I want to share with you a way that allows you not to create a bunch of different templates in Oxygen for each language. To do this, I register a custom condition to show or hide an elements based on the Polylang locale.
Let's say your site has content in two languages - English and German. You have already installed the Polylang plugin and made basic settings.
1. Register a custom condition with Oxygen
Add this code snippet (as is, unchanged) to your own plugin, or use the Code Snippets or Advanced Scripts plugin:
if( function_exists('oxygen_vsb_register_condition') && function_exists('pll_languages_list') ) {
$lang_list = pll_languages_list();
oxygen_vsb_register_condition(
//Condition Name
'Locale',
//Values
array(
'options' => $lang_list,
'custom' => false
),
//Operators
array('==', '!='),
//Callback Function
'polylang_callback',
//Condition Category
'Polylang'
);
function polylang_callback($value, $operator) {
$my_lang = pll_current_language();
global $OxygenConditions;
return $OxygenConditions->eval_string($my_lang, $value, $operator);
}
}
I usually use Code Snippets and this is how it looks:
This completes the work with the code and then we move on to the Oxygen editor.
2. Setting the display of elements based on the language locale in the Oxygen editor
Suppose you have a main template and now you can create two different headings in the same template by applying the appropriate language condition for each heading. Thus, one heading will only be shown on the English version of the page, and the other heading will be shown on the German version of the page.
You can use this condition for entire sections or for any number of separate page elements.
I hope this method will help you in creating a multilingual website.