Meta Box - Polylang integration
You can translate both values and labels of many objects, including post types, taxonomies, custom fields, and settings pages. This integration works smoothly whether you're using Polylang or Polylang Pro.
Configuration
After installing Polylang on your site, the setup wizard is automatically launched with all the necessary steps to configure easily a multilingual website.
In there, two of the most essential setup steps are the site languages and the menus.
Site languages
In the case that you skip the setup wizard, go to Languages > Setup to add the languages for your site. Then, you should define at least one language by choosing from a list of over 90 predefined languages or creating a custom one. The first language you add becomes the default language of your multilingual website.
On this screen, you also can configure media, content, and homepage in the next steps. Click on the Continue button to set them up.
Menus
This focuses on displaying and customizing the switch language button on the frontend.
Go to Appearance > Menus, then follow these steps:
- Click on the Screen option button to enable the Language switcher option.
- Select the position of the menu or create a new menu
- In the Add menu items section, navigate to the Language switcher tab, check the box, and click on the Add to menu button.
- In the Languages tab, check the appropriate options to configure the language switcher and its interface.
Note that the language switcher will display a language only if at least one post or one page has been published in this language.
If you haven’t seen the switcher on the frontend, save your change in the Manage Locations tab.
Overview
Each Meta Box object includes the value (data) and label (configuration). Meta Box - Polylang integration allows you to translate both of them.
In terms of labels, you can input translations directly without any additional configuration. They are strings in the Translations table already. For convenience, Meta Box provides filters based on objects along with their name, as you can see below:
So, you can translate labels of post types, taxonomies, fields/field groups, and settings page. You should use them to avoid missing any labels instead of using the search bar.
To translate values, depending on the object you want to translate, there will be corresponding translation methods:
- Values of post types (posts) and taxonomy (terms): Activate languages in the Settings submenu, then input translation directly in the post editor and taxonomy admin.
- Field values: Create a wpml-config.xml file that defines the translation action and field ID you need to translate.
- Settings page field values: Simply switch the language on the top bar and enter the translation without any settings.
To display translation on the fontend, you can use MB Views, a page builder or code.
Custom post types
For example, I created a post type named Events. Now, our goal is to translate its labels and posts.
Post type labels
Go to Languages > Translations. Then, find the Meta Box Post Type option with the name you want from the dropdown list, and click Filter to have all the labels of that post type. Simply enter the translations one by one.
After saving the changes, the translation updated immediately.
Post type values
First, you need to activate languages and translations for the custom post type.
Go to Languages > Settings. Then, click on the Settings button in the Custom post types and Taxonomies option to activate the translations feature for it.
After that, go to the post editor to enter the translation for posts. There is a section named Languages on the right panel. You can enter the title translation into the box, or click on the “+” button to switch to the post in the corresponding language and input the translation of the title and description of the post.
The icon will be changed to Edit when that language has the translation version.
Now, in the post type admin, that translation is displayed when you switch the language.
Custom taxonomies
Translating custom taxonomy labels and values is the same as translating post types.
To translate terms of taxonomy, you need to activate languages and translations of that taxonomy and the post type that the taxonomy is assigned to.
They are all located in the Custom post types and Taxonomies option.
Then, in the taxonomy admin, you have two positions to add translations for the term like this:
Taxonomy labels
In the Translation submenu, filter strings by Meta Box Taxonomy. Then, just switch the language in the top bar and enter translation for labels one by one.
After saving translations, you can see they are output like this:
Custom fields
Field labels
Meta Box - Polylang integration allows you to translate labels easily, including field group name, field label
, label description
, input description
, default value
, placeholder
, and adding more text
of cloneable field/group.
Assuming that we need to translate these labels:
Navigate to Languages > Translations. In the list of filters, you can see Meta Box Field Group. In this case, I set the language as Show all languages to fill in the translations for all languages at the same time.
Go to the post editor, you can see the translation of field labels.
Field values
Meta Box field values are defined as strings, and Polylang hasn’t supported interface to translate them directly. So, we’ll use a wpml-config.xml file to add these values as string translations.
Create a new file following path /wp-content/themes/your-theme/wpml-config.xml
:
<wpml-config>
<custom-fields>
<custom-field action="translate">{field_id}</custom-field>
</custom-fields>
</wpml-config>
For custom fields, Polylang supports three actions for translation:
ignore
: no action from Polylang.translate
: the custom field is copied from the source post but may be modified.copy
: the field value is copied from the source post and synchronized across translations.
In my case, the code will be like this:
The field is recognized as strings now. Just go to the post editor to check the result. I use the translate
action. So, when I switched the language, the field value is copied, and I can change it.
Settings page
Settings page labels
Similar to translating labels of other objects, this integration helps you filter and translate the settings page labels quickly.
Go to the Translation submenu, then filter strings by Meta Box Settings Page:
Even when you have custom fields on the settings page, the Meta Box - Polylang integration works well for translating field labels. Also, filter by Meta Box Field Group to enter translations for them.
In the settings page, all the labels are switched to the corresponding language seamlessly.
Settings page field values
Translating field values in the settings page is simplest since you can enter the translation directly without any additional configuration.
Besides, you can still filter strings by MB Settings Page in the Translation table as other labels.
When you delete a value from one language on the settings page, the values from other languages are auto-deleted. It happens with not only the Meta Box settings page but also WordPress settings (For instance, site title or site description in General settings)