块编辑器开发文档

@wordpress/babel-plugin-makepot

💡 云策文档标注

概述

@wordpress/babel-plugin-makepot 是一个 Babel 插件,用于扫描 JavaScript 文件中的本地化函数调用,并生成 gettext POT 格式的翻译模板文件。默认输出到项目根目录的 gettext.pot,可通过配置选项自定义输出路径。

关键要点

  • 插件功能:扫描 JS 文件中的本地化函数,生成 POT 翻译模板。
  • 默认输出:gettext.pot 文件位于项目根目录。
  • 配置选项:支持通过 "output" 选项覆盖输出文件路径。
  • 安装方式:使用 npm install @wordpress/babel-plugin-makepot --save-dev 安装。
  • 环境要求:需要 Node.js 长期支持版本,不兼容旧版本。
  • 项目背景:作为 Gutenberg 项目的一部分,采用 monorepo 结构,包发布到 npm 供 WordPress 等使用。

代码示例

{
    "plugins": [
        [
            "@wordpress/babel-plugin-makepot",
            { "output": "languages/myplugin.pot" }
        ]
    ]
}

注意事项

  • 安装时需使用 --save-dev 作为开发依赖。
  • 确保 Node.js 版本符合长期支持要求,避免兼容性问题。
  • 贡献指南请参考 Gutenberg 项目的主贡献者文档。

📄 原文内容

Babel plugin used to scan JavaScript files for use of localization functions. It then compiles these into a gettext POT formatted file as a template for translation. By default the output file will be written to gettext.pot of the root project directory. This can be overridden using the "output" option of the plugin.

{
    "plugins": [
        [
            "@wordpress/babel-plugin-makepot",
            { "output": "languages/myplugin.pot" }
        ]
    ]
}

Installation

Install the module:

npm install @wordpress/babel-plugin-makepot --save-dev

Note: This package requires Node.js version with long-term support status (check Active LTS or Maintenance LTS releases). It is not compatible with older versions.

Contributing to this package

This is an individual package that’s part of the Gutenberg project. The project is organized as a monorepo. It’s made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to npm and used by WordPress as well as other software projects.

To find out more about contributing to this package or Gutenberg as a whole, please read the project’s main contributor guide.