Web training courses

Develop your digital skill set

Share

How to make a custom wordpress theme multilingual

When looking to make a Wordpress site multilingual it can be hard to know where to begin. I encountered this scenario when tasked with making http://mapp.media/ available in Spanish and decided to use Polylang to translate the main bulk of the content, as it allows translating of custom fields through either Advanced Custom Fields, or Custom Field Suite in my case (which Polylang doesn’t explicitly support but seems to function correctly regardless).
However, then comes the issue of hardcoded strings, such as copyright text or input field placeholders, which cannot be translated by Polylang. For these I opted to use a plugin called Loco Translate which lets users translate hardcoded strings from within Wordpress admin. To set this up you will need to edit all your hardcoded strings so that they can be identified as translatable strings by the plugin. For example, a placeholder for an email input would go from:

 

placeholder=”email”

 

to

 

placeholder="<?php _e('email', 'YOUR THEME NAME') ?>"

 

When you have updated all your hardcoded strings you will need to create a ‘languages’ folder in the root of your theme folder and download a blank .pot file from https://goo.gl/KbBbFQ and place this file within the languages folder. You will then need to open this file using a PO editor (poedit was my choice) and change the source to your theme folder and update from sources. This should then list all your translated strings and you can now save the file and open with Loco Translate. You should then be able to enter translations for the strings which will then update when you change language with the Polylang language switcher.

Jon
by Jon

Would you like to give your digital knowledge a boost? Join our mailing list.