1

We have a multisite solution, inside this solution there are two WooCommerce shops. Both are in Dutch.

The way they approach people is different so they want to use different translations. Hoe can this be achieved?

We already tried manual translating and with Loco Translations the plugin. But if you change something on 1 site it will also be changed on the other site.

| improve this question | | | | |
1

You can use WordPress hooks to load site-specific files, but it requires some work.

In this example, we'll keep a common Dutch language file at a system location. This can contain any strings that work for both sites. Then we'll override the common strings in two files using the site ID. So we have three files in total:

  1. wp-content/languages/plugins/woocommerce-nl_NL.mo
  2. wp-content/languages/my-site-1/woocommerce-nl_NL.mo
  3. wp-content/languages/my-site-2/woocommerce-nl_NL.mo

In the last two files you only need translate strings you want to differ from the first one.

To load the right file according to the site, put the following code somewhere so it runs early. A must-use plugin is usually easiest:

<?php
/*
 Plugin Name: Multisite translation loader
 Description: Loads site-specific translations on top of default
*/

function on_multisite_load_textdomain( $domain, $mopath ){
    static $lock;
    if( ! $lock ){
        $mopath = sprintf('%s/my-site-%u/%s', 
          WP_LANG_DIR, 
          get_current_blog_id(), 
          basename($mopath)
        );
        $lock = true;
        load_textdomain( $domain, $mopath );
        $lock = false;
    }
}

if( is_multisite() ){
    add_action('load_textdomain','on_multisite_load_textdomain',1,2);
}

If you want to use Loco Translate to manage these files, you'll have to configure each site with an extra Domain Path. Go into each site's admin area and open the Advanced tab for the bundle configuration. Add relative paths like "../../languages/site1" and "../../languages/site2" to the domain path field and save the configurations.

Note that each site maintains separate plugin settings, because they are saved as site options in the WordPress database.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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