How to Avoid Overwriting of WordPress Theme Translations

If you are using WordPress in language other than English, you’ve experienced this painful process:

  • plugin/theme doesn’t include translations and you need to manually upload it
  • you download translation or translate it on your own, and upload it
  • new version of plugin/theme appears, you use automatic upgrader
  • translation files get deleted and you need to start from beginning

Although there was workaround that included using WordPress filters to point to different location for translations, WordPress 3.5 includes built-in solution that is, unfortunately, limited to themes only.

From now on, you can place your theme’s translation outside of theme’s directory in a themes subdirectory of your languages directory (WP_LANG_DIR). So, if your languages directory is default wp-content/languages, directory you should use is wp-content/languages/themes.

Another thing worth noting is that you need to change filename of translation if you use above solution. Theme translations files use only language codes as their names, for example sr_RS.mo. If you put translation in a WP_LANG_DIR/themes, you need to prefix this filename with theme’s textdomain. This textdomain is usually same as theme’s directory name, though you can confirm this by searching theme’s function.php file (or file included from over there) for load_theme_textdomain() function.

For example, translation of Twenty Twelve theme should be named twentytwelve-sr_RS.mo, for Hybrid theme hybrid-sr_RS.mo, for Responsive theme responsive-sr_RS.mo etc.

To summarize everything, instead of having your translation like
wp-content/themes/hybrid/languages/sr_RS.mo
move to
wp-content/languages/themes/hybrid-sr_RS.mo

Hopefully, WordPress 3.6 will include support for plugins as well, or, even better, full language packs support. If you are one that have need for it, beg WordPress developers to do something about that.

4 thoughts on “How to Avoid Overwriting of WordPress Theme Translations


      1. I’vve enjoyed very much your patch, Milan.
        Congratulations, i hope they release this soon!

        Would be nice to see a function that move/copy the files to wp-content folder from plugins and themes.

Leave a Reply to Milan Dinić Cancel reply

Comment Guidelines:
  • Your email address will not be published
  • Fields marked with * are required
  • If you want your picture next to comment, open an account at Gravatar
  • If you want to know if someone replied to your comment, check “Notify me of followup comments via e-mail”
  • You can use these HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>