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.
Here is a patch for 3.5 to use this with plugins too.
use wp-content/languages/plugins/textdomain-pt_BR.po
https://core.trac.wordpress.org/attachment/ticket/18200/lp.5.diff
apply this via SSH with: patch -p1 < lp.5.diff
Actually, patch you linked adds language packs support, but won’t load translations for plugins the way it does for themes.
Another patch (made by me!) in that ticket makes what you want:
https://core.trac.wordpress.org/attachment/ticket/18200/no_plugin_overwrite.patch
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.