I'm using Codestyling Localization and I want to translate a plugin and I want the translation files to be saved in the translation directory in the theme I'm building and not in the plugins directory.

Is this possible?

I have tried load_plugin_textdomain and load_textdomain but that doesn't seem to work.

// Add localization
load_theme_textdomain( 'my_theme', $translation_directory );

$domain = 'other_plugin';
$locale = apply_filters('plugin_locale', get_locale(), $domain);
load_textdomain( $domain, WP_LANG_DIR.'/'.$domain.'/languages/'.$domain.'-'.$locale.'.mo');
load_plugin_textdomain( $domain, FALSE, $translation_directory );

1 Answer 1


First of all, I'd strongly recommend against storing translations for a plug-in in your theme. It has no reason to be there, and you'll loose the translations when you change/update the theme.

The correct place to store translations is wp-content/languages/plugins/.

This code does that, and targets the domain 'other_plugin':

function wpse159536_override_mofile_path( $mofile, $domain ){
    if( 'other_plugin' == $domain ){
         $mofile = WP_LANG_DIR . '/plugins/' . basename( $mofile );
    return $mofile;
add_filter( 'load_textdomain_mofile', 'wpse159536_override_mofile_path', 10, 2 );

Of course, an even better solution would be to send the translation file to the developer to include in the next release (if this is appropriate).

  • Yes placing the files in wp-content is better. This code only changes the url for the file when it's loaded right? Do you know if it's possible to get this to work with Codestyling so things can be translated there?
    – Patrik
    Commented Aug 29, 2014 at 16:56
  • It changes where WordPress looks for the translation. I'm not sure how Codestyling Localisation works, but if you can download a copy of the .mo file, then you can put it in the appropriate directory. Commented Aug 29, 2014 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.