如何使'wp_set_script_translations'功能自动工作?

问题描述 投票:3回答:1

我想让'wp_set_script_translations'与主题结合起来使用。

我已经执行了Wordpress Codex的所有建议。WPML插件会在"\wp-content\languages\wpml "文件夹中生成格式为 "locale-domain-handle.json "的文件。但文件生成时没有翻译,而且域名 "messages "错误,而不是我指定的域名。我也检查了WPML字符串翻译文件,似乎错误的json是由JED函数生成的,JED函数总是设置 "message "域名而忽略客户域名。

{
  "translation-revision-date": "2019-04-23 08:33:37+0000",
  "generator": "WPML String Translation 2.10.2",
  "domain": "messages",
  "locale_data": {
    "messages": {
      "": {
        "domain": "messages",
        "plural-forms": "nplurals=2; plural=n != 1;",
        "lang": "fr_FR"
      }
    }
  }
}

我希望看到文件中包含正确的域名的翻译,或者是不需要手动生成翻译文件的其他自动方法。

php wordpress wpml
1个回答
0
投票

翻译终于得到了正确的开发和记录。https:/developer.wordpress.orgblock-editordevelopersinternationalization。

基本上,你需要。

  1. 使用wp-i18n包来定义你的项目中哪些字符串是可以被翻译的。
  2. 使用WP-CLI (wp i18n make-pot)来创建一个 .pot 文件,就像我们一直使用的WP主题和插件一样。
  3. 生成一个 .po 文件,基于我们之前创建的 .pot 并翻译其内容。
  4. 再次使用WP-CLI (wp i18n make-json)来转换我们的 .po 文件为所需的JSON格式。
  5. 使用 wp_set_script_translations PHP函数来加载翻译文件。

希望这能帮助到大家;)

© www.soinside.com 2019 - 2024. All rights reserved.