How to use load_plugin_textdomain from within a theme

It seems there is no easy way to do this as load_plugin_textdomain() won’t work as expected when called from a child theme.

A generic workaround was developed by Marius Vetrici but I’ve found it to be incompatible with Polylang under some circumstances.

The most reliable solution I have found is explicitly loading the translation using the load_textdomain() function which is one level lower than load_plugin_textdomain():

load_textdomain( $textdomain, get_stylesheet_directory().'/languages/'.$textdomain.'-'.get_locale().'.mo' );

The above example implies that you will keep your translation file in the languages folder under your child theme folder, and that it will be named according to the textdomain-lang_COUNTRY.mo scheme (for example: someplugin-en_US.mo).

You will have to pay attention to where to call load_textdomain() from, so that the locale is already available, and your translation is loaded before or after other translations (depending on your needs). If you only want to add new string translations, the order in which the translations are loaded doesn’t matter, but if you want to override an existing translation, make sure that yours is the one loaded first, as (according to the documentation), the translation which was loaded first will be preferred over the one that is loaded later. Translations are typically loaded on the init hook, but in case of Polylang, the pll_language_defined hook is to be used.

Note that it is always a .mo (Machine Object) file that the system actually uses. The .po (Portable Object) files are human readable and are compiled into .mo files on each save. The .pot file is a template for .po files.