WordPress MultiSite中的字符串翻译与I18N不适用于所有站点

时间:2020-06-15 作者:Will Ashworth

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 个回复
SO网友:Naoko Takano

看起来您为其他语言(但不是日语)正确指定了WordPress语言代码。

https://make.wordpress.org/polyglots/teams/日本人mo文件需要命名为themename-ja.mo但您可能使用\'jp\'?

相关推荐

Multisite installation steps?

我启动了Multisite 特色我想在子域中创建一个站点。我有两个问题:在多站点管理仪表板中创建站点之前,还是之后,我必须在服务器上创建子域</如果是,在multisite admindashboard中创建站点之前,还是之后,我必须在此子域中安装WordPress安装我在StackExchange上找到了这个,但它对我没有帮助,或者我就是不明白。Subdomain multisite gives 404 on sub sites谢谢弗朗索瓦