0

Using

  • WordPress Multisite (subdir)
  • Child themes
  • Loco Translate

The Issue

One of our multisite sites isn't string translating (Japanese). We started with non-multisite with just English. Then, converted to multisite and introduced German. The idea was each multisite would serve as a locale. Each multisite site would receive its own theme inheritance from the original theme. String translation seemed to work correctly after some debugging and fine tuning. Later, we added French and Korean and that was a breeze. Now, Japanese isn't working for us. The other languages do, though.

We utilize Loco Translate to handle the translating locally, then commit the generated .po and .mo files in Git before deployment. The translations have already been put into the Japanese side and things just aren't working to replace template strings like the other languages handled it. I've set locale in the dashboard as well; doesn't help.

I've checked everything I can think of, and looped in other developers to no avail. The textdomain matches and the locale is set. The language files for reading in are being correctly created and put in the right places. I'm actually starting to wonder if this is an mbstring thing of some sort; like maybe the regular translation functions in Core aren't handling multibyte characters or something. But I have to imagine they've already thought of that in the __() function, right? That's why we use the textdomain and the files; which need to match up in order to get a text swap. Only, that text swap behavior isn't happening for Japanese. We can put Japanese text into the WYSIWYG textareas content-wise, but it's the theme strings I'm trying to get handled here.

Really running out of ideas on this one. Hoping someone might have some idea of what's going on. 🤷🏼‍♂️

Site Structure

/                (English, multisite parent)
/de/             (German, multisite child)
/fr/             (French, multisite child)
/kr/             (Korean, multisite child)
/jp/             (Japanese, multisite child)

Themes

Each of the sites has a child theme enabled for itself. We have deviating logic for these themes/locales sometimes, depending on the locale and what's going on, so we do have a separate child theme for each "site" within the multisite network. Even the English/root site has a child theme that inherits the parent theme's logic; so they all get the overall parent site.

The themes look like this:

/app/public_html/wp-content/themes/mysite             (parent theme, inherited)
/app/public_html/wp-content/themes/mysite-child       (English, child theme)
/app/public_html/wp-content/themes/mysite-child-de    (German, child theme)
/app/public_html/wp-content/themes/mysite-child-fr    (French, child theme)
/app/public_html/wp-content/themes/mysite-child-kr    (Korean, child theme)
/app/public_html/wp-content/themes/mysite-child-jp    (Japanese, child theme)

Example of the Japanese child theme functions.php file:

<?php
// set the locale to use
add_filter('locale', function () {
    return 'ja_JP';
    // return 'ja';          // tried this as well, no difference :(
});

// load the textdomain for translation
add_action('after_setup_theme', function () {
    $path = get_stylesheet_directory();
    load_child_theme_textdomain('mysite', $path);
});

function mysite_jp_scripts()
{
    // enqueue style
    wp_enqueue_style('master-jp-css', get_stylesheet_directory_uri().'/library/css/master-jp.min.css');
}
add_action('wp_enqueue_scripts', 'mysite_jp_scripts', 12);

Example of syle.css for the child theme:

/*
 Theme Name:   My Site Theme: JP
 Theme URI:    https://example.com
 Description:  My Site Theme: JP
 Author:       Me
 Author URI:   https://example.com
 Template:     mysite
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain:  mysite
*/

Updated 2020-06-14 22:43

The language files in the parent theme look like this:

/app/public_html/wp-content/languages/loco/themes/mysite-de_DE.mo
/app/public_html/wp-content/languages/loco/themes/mysite-de_DE.po
/app/public_html/wp-content/languages/loco/themes/mysite-fr_FR.mo
/app/public_html/wp-content/languages/loco/themes/mysite-fr_FR.po
/app/public_html/wp-content/languages/loco/themes/mysite-ja.mo
/app/public_html/wp-content/languages/loco/themes/mysite-ja.po
/app/public_html/wp-content/languages/loco/themes/mysite-ko_KR.mo
/app/public_html/wp-content/languages/loco/themes/mysite-ko_KR.po
1
  • // return 'ja'; // tried this as well, no difference :( - are you 100% sure? Because the translation files (PO/MO) need to match the locale (e.g. mysite-ja.mo). But as Naoko said, try regenerating the translation files.
    – Sally CJ
    Commented Jun 16, 2020 at 0:53

1 Answer 1

0

Looks like you correctly specified WordPress language code for other languages but not Japanese.

https://make.wordpress.org/polyglots/teams/ Japanese .mo files need to be named themename-ja.mo but you are probably naming them using 'jp'?

2
  • Interesting idea! I don't think it's that, because of how they're currently named. I've updated the post with new info at the bottom, which includes a file listing of the existing language files to show how they're named. Commented Jun 15, 2020 at 5:48
  • The language file name looks correct indeed! On the site set in Japanese, does Twenty Twenty default theme work ok? The other thing that may be a possible cause is that the MO file is not correctly generated/updated or corrupted. Try saving it with just one string and test it? You probably tried all of these, but just in case: localise.biz/help/wordpress/loading-translations Commented Jun 15, 2020 at 6:56

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.