Cache WordPress translations

I answered a similar question on Stack Overflow recently.

Don’t forget that the profiler itself adds a big overhead. If your page loads are still really slow with XDebug disabled then I don’t think your problems are limited to translation files and you should look at caching entire pages.

You can eliminate MO file loading as a problem by preventing the loading of all translation files. This is easy with just one line:

add_filter('override_load_textdomain', '__return_true');

If this doesn’t speed things up then a caching plugin won’t either. Caching the MO files will save only the overhead of reading the MO files from disk, and in my experience this is rarely a bottleneck. MO files are binary and so parsing them is fast.

If the parsing really makes a difference (with xdebug off) then perhaps you have slow disk reads and need to look at boosting your hardware. Otherwise the caching plugin already given in the comments would let you use a fast memory cache.

Regardless of how the strings are pulled into memory (or not) every call to the internal translate function via __ and friends will still be executed and do work. There is no way to skip this from happening in the WordPress core or in other plugins where you can’t hard code the text.

Leave a Comment