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.
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.
Share Improve this question asked Nov 14, 2018 at 9:59 RoyRoy 556 bronze badges1 Answer
Reset to default 1You 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:
- wp-content/languages/plugins/woocommerce-nl_NL.mo
- wp-content/languages/my-site-1/woocommerce-nl_NL.mo
- 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.