Title: load_textdomain_mofile
Last modified: August 22, 2016

---

# load_textdomain_mofile

 *  [patrikelfstrom](https://wordpress.org/support/users/rcane/)
 * (@rcane)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/)
 * I need to override the jetpack mofile with load_textdomain_mofile so I can use
   my own translation but jetpack doesn’t show up in that filter is there a workaround?
 * [https://wordpress.org/plugins/jetpack/](https://wordpress.org/plugins/jetpack/)

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277174)
 * Could you paste the function you used to try to overwrite Jetpack’s translations
   with `load_textdomain_mofile`?
 * Thanks!
 *  Thread Starter [patrikelfstrom](https://wordpress.org/support/users/rcane/)
 * (@rcane)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277268)
 *     ```
       function override_translation( $mofile, $domain ){
           $plugins_to_move = array('jetpack');
   
           if( in_array($domain, $plugins_to_move) ){
               $mofile = WP_LANG_DIR . '/plugins/' . basename( $mofile );
           }
   
           return $mofile;
       }
       add_filter( 'load_textdomain_mofile', 'override_translation', 10, 2 );
       ```
   
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277286)
 * Could you test and see what `WP_LANG_DIR . '/plugins/' . basename( $mofile );`
   returns? Does it lead to your custom Jetpack translation file?
 * Thanks!
 *  Thread Starter [patrikelfstrom](https://wordpress.org/support/users/rcane/)
 * (@rcane)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277296)
 * $domain never contains jetpack
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277298)
 * This might have something to do with load order, and the priority of the `load_textdomain_mofile`
   filter. You might be trying to retrieve the `jetpack` textdomain before Jetpack
   adds that textdomain.
 * Jepack’s textdomain is added to `plugins_loaded`, as recommended here:
    [https://codex.wordpress.org/Function_Reference/load_plugin_textdomain](https://codex.wordpress.org/Function_Reference/load_plugin_textdomain)
 * I’m not too familiar with `load_textdomain_mofile` though, so I’m not entirely
   sure about what’s going on here.
 * I know David Decker (@daveshine) has done some work on this in his Jetpack add-
   on [Jetpack German (de_DE)](http://wordpress.org/plugins/jetpack-de/), and he
   chose to do things differently:
    [https://plugins.trac.wordpress.org/browser/jetpack-de/tags/1.7.0/jetpack-de.php#L327](https://plugins.trac.wordpress.org/browser/jetpack-de/tags/1.7.0/jetpack-de.php#L327)
 * He might be able to shed some light on the issue. I’ll ask him to jump in this
   thread!
 *  [David Decker](https://wordpress.org/support/users/daveshine/)
 * (@daveshine)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277299)
 * Hi there!
 * Thanks for the info! Yes, I used that filter/function formerly in my plugin. 
   It worked a long time very well. However, one day Jetpack was changing something
   so the filter didn’t override the original (packaged) file, but rather load the
   original plus mine. You never knew which was loaded first, and if ever, both 
   files were merged.
 * So, I decided to switch the structure and essential base of my plugin to use “
   load_textdomain()” which then loads my custom translations before the original.
   However, this current approach in my plugin leads to this, that translations 
   are loaded for Jetpack are loaded more than one time. Sounds strange but that
   is the case. For WordPress (and PHP’s Gettext in general wich is the base of 
   all WordPress translations) this is no problem at all. Users won’t note a difference.
   But it could – must not automatically, but it could – lead to some performance
   issues based on your server/hosting.
 * Based on my experience also with other plugins than Jetpack, sometimes it is 
   necessary to load your own, custom translations very early, or very late. Best
   companion for that is the base function “load_textdomain()”. When used for very
   early loading it will be the primary translation loaded. If you missed any strings
   in that for translation those will be filled then by a packaged translation (
   originally from the plugin), this is the so-called merging. This is a great behavior
   of WordPress core and works wonders, but you should be aware of this if you are
   debugging loading/displaying of translations.
 *  [David Decker](https://wordpress.org/support/users/daveshine/)
 * (@daveshine)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277301)
 * Here you’ll find an article about the differences/use cases of these various 
   filters and functions:
 * [http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way](http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way)
 *  [David Decker](https://wordpress.org/support/users/daveshine/)
 * (@daveshine)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277302)
 * And last info for now:
    here’s a plugin “Debug Translations” which will print
   after the admin footer in WP Admin all loaded translations from which source 
   and hook etc. [http://marketpress.de/product/debug-translations/](http://marketpress.de/product/debug-translations/)(
   sorry site only in German, no English available, try Google translate) direct
   download of Zip: [http://marketpress.de/mp-download/free/debug-translations/mp](http://marketpress.de/mp-download/free/debug-translations/mp)—
   > questions for this debug plugin point to Thomas Scholz aka “@toscho” at Twitter,
   he developed it 🙂
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277303)
 * [@daveshine](https://wordpress.org/support/users/daveshine/) Thanks for jumping
   in!
 * > one day Jetpack was changing something so the filter didn’t override the original(
   > packaged) file, but rather load the original plus mine. You never knew which
   > was loaded first, and if ever, both files were merged.
 * That most likely happened when we changed the priority of when `plugin_textdomain`
   was loaded, in [c4fe30](https://github.com/Automattic/jetpack/commit/c4fe3054857a4279aee5ab1e3db020237edb9bd1).
   This allowed language plugins like [xili-language](https://wordpress.org/plugins/xili-language/)
   or [WP Native Dashboard](https://wordpress.org/plugins/wp-native-dashboard/) 
   to alter the way language files were loaded. You can find out more in the related
   tickets:
    - [https://plugins.trac.wordpress.org/ticket/1764](https://plugins.trac.wordpress.org/ticket/1764)
    - [https://github.com/Automattic/jetpack/pull/113](https://github.com/Automattic/jetpack/pull/113)
 * I could revert that change to allow the use of `load_textdomain_mofile`, but 
   that would cause issues with the plugins I mentioned above.
 * I’ll run some tests using the Debug plugin you mentioned, David, and see if I
   can find a solution.
 *  [fuxia](https://wordpress.org/support/users/thefuxia/)
 * (@thefuxia)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277305)
 * The English page for the plugin Debug Translations is available per language 
   switcher: [http://marketpress.com/product/debug-translations/](http://marketpress.com/product/debug-translations/)
 *  [David Decker](https://wordpress.org/support/users/daveshine/)
 * (@daveshine)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277306)
 * [@toscho](https://wordpress.org/support/users/toscho/):
    Thanks! I assumed so
   but somehow I got instantly redirected to the German version, don’t know why…
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277307)
 * @patrikelfstrom I tested your code snippet on 2 different sites of mine (one 
   in a Multisite network, the other is a single install), and it worked every time,
   with the latest version of WP and Jetpack.
 * I’m not sure why things don’t work on your site.
 *  [Piyush5767](https://wordpress.org/support/users/piyush5767/)
 * (@piyush5767)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277519)
 * Use This Custom Plugin to overwrite any anguage files whether it is plugin or
   any theme language files
 * class Textdomain_Overwrite {
 *  // used to store the current locale e.g. “de_DE”
    private $locale;
 *  // used to store the folder with the overwrite files
    private $overwrite_folder;
 *  // flag to check if running a multisite environment
    private $is_multisite;
 *  // used to store the multisite blog_id
    private $current_blog_id;
 *  function __construct() {
 *  // get current locale
    $this->locale = get_locale();
 *  // set folder for overwrites
    $this->overwrite_folder = WP_LANG_DIR . ‘/overwrites/’;
 *  // check if multisite
    $this->is_multisite = is_multisite();
 *  // if it is a multisite, get the current blog_id
    if ( $this->is_multisite ){
   $this->current_blog_id = get_current_blog_id(); }
 *  // register action that is triggered, whenever a textdomain is loaded
    add_action(‘
   override_load_textdomain’, array( $this, ‘overwrite_textdomain’ ), 10, 3 ); }
 *  /*
    * Overwriting strings from all loaded textdomains, no matter if they are
   used in Core, Plugins or Themes * * The .mo file has to be named [domain]-[locale].
   mo * e.g. for the plugin Jetpack with the textdomain “jetpack” * and the locale“
   de_DE” is has to be jetpack-de_DE.mo */ function overwrite_textdomain( $override,
   $domain, $mofile ) {
 *  // if the filter was not called with an overwrite mofile, return false which
   will proceed with the mofile given and prevents an endless recursion
    if ( strpos(
   $mofile, $this->overwrite_folder ) !== false ) { return false; }
 *  // if an overwrite file exists, load it to overwrite the original strings
    $
   overwrite_mofile = $domain . ‘-‘ . $this->locale . ‘.mo’;
 *  // check if a global overwrite mofile exists and load it
    $global_overwrite_file
   = $this->overwrite_folder . $overwrite_mofile;
 *  if ( file_exists( $global_overwrite_file ) ) {
    load_textdomain( $domain, $global_overwrite_file);}
 *  // check if a overwrite mofile for the current multisite blog exists and load
   it
    if ( $this->is_multisite ) { $current_blog_overwrite_file = $this->overwrite_folder.‘
   blogs.dir/’ . $this->current_blog_id . ‘/’ . $overwrite_mofile;
 *  if ( file_exists( $current_blog_overwrite_file ) ) {
    load_textdomain( $domain,
   $current_blog_overwrite_file ); } }
 *  return false;
    }
 * }
 * new Textdomain_Overwrite;
 * Cheers —-:)

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘load_textdomain_mofile’ is closed to new replies.

 * ![](https://ps.w.org/jetpack/assets/icon.svg?rev=2819237)
 * [Jetpack - WP Security, Backup, Speed, & Growth](https://wordpress.org/plugins/jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack/reviews/)

 * 13 replies
 * 5 participants
 * Last reply from: [Piyush5767](https://wordpress.org/support/users/piyush5767/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/load_textdomain_mofile/#post-5277519)
 * Status: not resolved