Git Product home page Git Product logo

make-pot's Introduction

Make Pot

make-pot is a Node.js module designed to generate the .pot file for your WordPress plugin or theme. This file serves as the basis for internationalization, allowing translators to localize your plugin or theme into different languages.

Extract strings from your WordPress plugin or theme and generate a .pot file. Works with js, jx, ts, tsx, cjs, mjs, php, blade, txt, json with a custom schema for theme and block.json files.

Installation

You can install make-pot globally via npm:

npm install -g @wp-blocks/make-pot

Usage

npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]

Positional Arguments:

  • sourceDirectory (optional): Specifies the source directory of your plugin or theme. If not provided, the .pot file root will be the source directory.
  • destination (optional): Specifies the destination directory where the .pot file will be generated. If not provided, the .pot file will be created in the source directory.

Options:

  • --version: Displays the version number of make-pot.
  • -h, --help: Displays help information.
  • --slug <slug>: Specifies the plugin or theme slug.
  • --domain <domain>: Specifies the text domain to look for in the source code.
  • --skip-js: Skips JavaScript files during processing.
  • --skip-php: Skips PHP files during processing.
  • --skip-blade: Skips Blade files during processing.
  • --skip-block-json: Skips block.json files during processing.
  • --skip-theme-json: Skips theme.json files during processing.
  • --skip-audit: Skips auditing of strings.
  • --headers <headers>: Specifies additional headers for the .pot file.
  • --file-comment <comment>: Specifies the file comment for the .pot file.
  • --package-name <name>: Specifies the package name.
  • --location: Includes location information in the .pot file.
  • --ignore-domain: Ignores text domain in the processing.
  • --mergePaths <paths>: Merges with existing POT file(s).
  • --subtractPaths <paths>: Subtracts strings from existing POT file(s).
  • --subtractAndMerge: Subtracts and merges strings from existing POT file(s).
  • --include <files>: Includes specific files for processing.
  • --exclude <files>: Excludes specific files from processing.
  • --silent: Suppresses output to stdout.
  • --json: Outputs the JSON gettext data.
  • --output: Outputs the gettext data.

As a build chain step

The make-pot module can be used as a build step in your build chain. To do so, create a build:makepot action in your package.json with the following content (refer to the options for more information):

{
	"build:makepot": "npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]"
}

Credits

This module is heavily inspired by the original makepot command from WP-CLI. Special thanks to the maintainers in particular Swissspidy which has been very helpful with suggestions and tips on how to rebuild make-pot.

Feel free to contribute or report issues on GitHub.

This tool is licensed under the GNU General Public License v3.

make-pot's People

Contributors

erikyo avatar johnhooks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

make-pot's Issues

Plugin Header fix

As @johnhooks noticed some headers in the pot file are missing and the placeholder is shown.

  # Copyright (C) 2024 pluginName
  # This file is distributed under the GPL-2.0-only license.
  msgid ""
  msgstr ""
  "Project-Id-Version: PLUGIN NAME 2.0.3\n"
  "Report-Msgid-Bugs-To: AUTHOR EMAIL **[object Object]**\n"
  "MIME-Version: 1.0\n"
  "Content-Transfer-Encoding: 8bit\n"
  "Content-Type: text/plain; charset=iso-8859-1\n"
  "Plural-Forms: nplurals=2; plural=(n!=1);\n"
  "POT-Creation-Date: 2024-03-16T01:41:57.862Z\n"
  "PO-Revision-Date: 2024-MO-DA HO:MI+ZONE\n"
  "Last-Translator: me <EMAIL>\n"
  "Language-Team: me <EMAIL>\n"
  "X-Generator: @wp-blocks/make-pot 1.0.0\n"
  "Language: LANGUAGE\n"
  "X-Domain: \n"

This is due to the fact that the metadata gathered are not correctly merged with the header data, we have to merge all collected types using a common pattern (eg. package json use the term "name" for the plugin name etc)

Missing `msgctxt`

The message contexts are missing from the output pot file.

The way the current node was matched to the expected translation key was using the array index, which was not kept in count with the actual nodes being examined. Example the , node would increment the index, while caused the following to assign undefined to the currentKey.

const currentKey = translationKeys[index]

Example

A _x function call with these arguments, should have a message context.

_x('None', 'Preload value', 'vinyl')

What would be expected:

#: src/audio/edit.tsx:186
msgctxt "Preload value"
msgid "None"
msgstr ""

Current output:

#: src/audio/edit.tsx:186
msgid "None"
msgstr ""

Paths should use reversed slash

as @plaksherie says the paths should use reversed slashes.

          By the way, the script is incompatible with make-json, it makes the path "\assets\main-C13JnjQB.js:9", but you need "/assets/main-C13JnjQB.js:9" for md5 to work correctly

Originally posted by @plaksherie in #21 (comment)

Wrong domain under some conditions

@erikyo I'm getting some odd output, its labeling as comming from the style.css but I don't have one in my project.

#: style.css
#. Name of the vinyl
msgid "@wp-blocks/vinyl"
msgstr ""

#: style.css
#. Author of the vinyl
msgid "undefined"
msgstr ""

#: style.css
#. Description of the vinyl
msgid "An audio player WordPress block."
msgstr ""

Originally posted by @johnhooks in #10 (comment)

Strings aren't parsed correctly (php)

I faced some missing translations for some php files, probably due to the fact that strings aren't parsed correctly

This is an example:

array(
		"title" => __( 'Zoom', '3d-product-viewer' ),
		"text"  => __( "Use the mouse wheel to zoom in or out on the model", '3d-product-viewer' ),
		"icon"  => 'icon-zoom'
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.