Giter VIP home page Giter VIP logo

wp-pot's Introduction

wp-pot

Information

GitHub Workflow Status npm version Average time to resolve an issue Percentage of issues still open

Package wp-pot
Description Generate pot files for WordPress plugins and themes.

Like my work and want to say thanks?

Do it here:
Buy Me A Coffee

Install

npm install --save-dev wp-pot

Example usage

PHP File Parsing

const wpPot = require('wp-pot');

wpPot({
  destFile: 'file.pot',
  domain: 'domain',
  package: 'Example project',
  src: 'src/*.php'
});

JS File Parsing (only js, no jsx for now)

wpPot({
  parser: 'js',
  parserOptions: {
    ecmaVersion: 6,
  },
  src: 'test/fixtures/edge-cases.js'
});

Options

All options is optional

  • bugReport Description: Header with URL for reporting translation bugs. Type: string Default: undefined
  • commentKeyword Description: Keyword to trigger translator comment. Type: string Default: translators:
  • copyrightText Description: Copyright text Type: function|string Default: A function that takes options object as a argument and return the default copyright text.
  • domain Description: Domain to retrieve the translated text. All textdomains is included if undefined. Type: string Default: undefined
  • destFile Description: Filename for template file. Type: string Default: domain.pot or translations.pot if domain is undefined.
  • headers Description: Object containing all default headers. Set to false to not generate the default extra headers for Poedit. Type: object|bool Default: Headers used by Poedit.
  • gettextFunctions Description: Gettext functions used for finding translations. Type: object Default: WordPress translation functions.
  • includePOTCreationDate Description: Auto-populate the POT-Creation-Date header. Type: bool Default: true
  • lastTranslator Description: Name and email address of the last translator (ex: John Doe <[email protected]>). Type: string Default: undefined
  • metadataFile Description: Path to file containing plugin/theme metadata header relative to relativeTo Type: string Default: undefined
  • noFilePaths Description: Do not print out file references in pot file. Type: bool Default: false
  • package Description: Package name. Type: string Default: domain or unnamed project if domain is undefined.
  • parser Description: PHP or JS parser Type: string Default: php
  • parserOptions Description: Options for the JS parser Espree. See here. Type: object Default: { comment: true, loc: true }
  • relativeTo Description: Path to folder that file comments should be relative to. Type: string Default: destFile location or current working directory if destFile is undefined.
  • src Description: Glob or globs to match files Type: string|array Default: **/*.php
  • globOpts Description: node-glob options object to be passed through. Type: Object Default: {}
  • team Description: Name and email address of the translation team (ex: Team <[email protected]>). Type: string Default: undefined
  • writeFile Description: Write pot-file to disk. The function always returns the contents as well. Type: boolean Default: true
  • ignoreTemplateNameHeader Description: Do not extract /* Template Name: String */ headers to POT file. Type: boolean Default: false

Related

License

MIT © Rasmus Bengtsson

wp-pot's People

Contributors

brenoalvs avatar dependabot[bot] avatar fossabot avatar frozzare avatar greenkeeper[bot] avatar greenkeeperio-bot avatar iandelmar avatar intoxstudio avatar marekdedic avatar nlemoine avatar rasmusbe avatar renovate-bot avatar sevenindirecto avatar snyk-bot avatar timelsass avatar tivnet avatar vheemstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wp-pot's Issues

Strings inside ternary operators are not detected

Describe the bug

Strings inside the ternary operators are not detected & extracted.

To Reproduce

const wpPot = require('wp-pot')

wpPot({
	destFile: 'file.pot',
	domain: 'domain',
	package: 'Example project',
	src: 'test.php',
})

Sample PHP file:

<?php

$condition = true;
$output = $condition ? __('Test 1', 'domain') : __('Test 2', 'domain');
$second_output = __('Test 3', 'domain');

Output:

# This file is distributed under the same license as the Example project package.
msgid ""
msgstr ""
"Project-Id-Version: Example project\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: test.php:5
msgid "Test 3"
msgstr ""

Outcome

Only "Test 3" string is in the pot file.

Expected

All 3 strings from the PHP file are in the final POT file.

Module versions

Empty localized strings generates an invalid .pot file

Describe the bug
This is an edge case.
When the source code have a call with an empty string, the generated .pot file creates a block for this string without the msgid.

This turns the .pot file invalid and this issue is carried when you create .po files from it.
If you try to compile the .po to .mo files you'll receive a fatal error.

To Reproduce
Generate a .pot with any empty call e.g. __( '', 'testdomain' );
Grab the generated file and create a .po from it.
Compile to .mo and receive a fatal error.

Module versions

[email protected] /Users/breno-proxio/wp-pot
└── [email protected]

Additional context
WP-CLI make-pot command skips those types of strings.

I was trying to fix this, but it seems more complex than I thought.
May involve some parser setup.

Duplicate translator hint comments

Describe the bug
When a translation string with a placeholder (%s) is used multiple times, the accompanying comment for translators is included as many times in the resulting POT file.

This also concerns the gulp-wp-pot package of course.

To Reproduce
I made a Gist with a minimal example to reproduce.

NB: This Gist also includes a feature that might be nice to include in the main package using an option.

Translator notes not added to generated pot file

Using version 1.1.5, translator notes in my PHP file are not getting added to the generated .pot file as expected.

Source:

<?php
/* translators: PHP date string used by mysql2date function */
$date_string = __( 'j F Y @ g:i a', 'my_textdomain' );
?>

Output:

#: assets/functions/admin.php:56
msgid "j F Y @ g:i a"
msgstr ""

Option to disable comments in result

I'd like to remove all the comments in the resulting .pot file. I don't see an option to do this, so thought I'd reach out for a feature request :-).

An in-range update of eslint-plugin-import is breaking the build 🚨

The devDependency eslint-plugin-import was updated from 2.14.0 to 2.15.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-import is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 34 commits.

  • 767f01a bump to v2.15.0
  • 038d668 bump webpack resolver to v0.11.0
  • 20a8f3b bump utils to v2.3.0
  • 1e4100d changelog note for #1261
  • 548ea02 added support for argv parameter of webpack`s config-as-a-function (#1261)
  • fcf2ce7 Merge pull request #1254 from ljharb/travis
  • 64d9be7 allow_failures for dicey Node/ESLint intersection
  • 73080d0 dep-time-travel: use older versions of dependencies
  • 05c3935 repair no-deprecated for ESLint* 5
  • 10c9811 node 4 fix for test util
  • f165237 ah geez, bumping babel-eslint breaks no-amd/no-cjs
  • acfb6e9 jk, test against eslint 2/3 but skip Typescript tests.
  • b686f9d drop ESLint 2/3 from Travis/Appveyor
  • cf1f6f4 [Deps] update debug, eslint-import-resolver-node, has, lodash, minimatch, resolve
  • d290a87 [Dev Deps] update babylon, coveralls, eslint-import-resolver-typescript, gulp, linklocal, nyc, redux, rimraf, sinon, typescript-eslint-parser

There are 34 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of eslint-config-standard is breaking the build 🚨

The devDependency eslint-config-standard was updated from 14.0.1 to 14.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-config-standard is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: node-v10: Your tests failed on CircleCI (Details).
  • ci/circleci: node-v11: Your tests failed on CircleCI (Details).
  • ci/circleci: node-latest: Your tests failed on CircleCI (Details).
  • ci/circleci: node-v8: Your tests failed on CircleCI (Details).
  • node-multi-build: * node-v8 - Failed

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Support for block.json

I make custom blocks for Wordpress themes/plugins and I would like to also translate the fields like title and description in the block.json file. It has textdomain support, see: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/

The default make-pot command already supports it as far as I know (https://developer.wordpress.org/cli/commands/i18n/make-pot/).

Example block.json:

{
  "name": "my-plugin/button",
  "title": "Button",
  "description": "A custom button block.",
  "category": "my-plugin-blocks",
  "icon": "block-default",
  "keywords": ["my-plugin", "button"],
  "textdomain": "my-plugin",
  "acf": {
    "mode": "preview",
    "renderTemplate": "block.php"
  }
}

Disable defaultHeaders option

Is your feature request related to a problem? Please describe.
I'm getting template names as translatable strings in the pot file, wich I think is unneeded (what's the case for this)?
Describe the solution you'd like
I'd like to not include these strings in the POT file because it is confusing for translators.

Hi there

after a few hours of testing I found an issue.

if translatable file is placed within php's exit function, it will never be translated.

ex:

$a = exit( __( 'Test 1', 'my-theme' ) );
$b = __( 'Test 2', 'my-theme' );

Result.

Copyright (C) 2017 Project

This file is distributed under the same license as the Project package.

msgid ""
msgstr ""
"Project-Id-Version: Project\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;n_noop:1,2;nx:1,2,4c;nx_noop:1,2,3c;x:1,2c;esc_attr;esc_attr_e;esc_attr_x:1,2c;esc_html;esc_html_e;esc_html_x:1,2c\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: project/functions.php:5
msgid "Test 2"
msgstr ""

Strings marked for translation in ternary statements don't get picked up for i18n

Describe the bug
I noticed recently, in wp-pot 1.9.2, that translatable strings inside ternary statements don't get picked up for internationalization.

To Reproduce
In the following statement, I'd expect 'yolo' to appear in the .pot file. It does not.

echo ( $bool_flag ) ? esc_html__( 'yolo', 'my-textdomain' ) : '';

Module versions
Include output of npm ls wp-pot php-parser so I know what versions you are using

than@muspellheim:~/workspace $ npm ls wp-pot php-parser
[email protected] /home/than/workspace
└─┬ [email protected]
  └─┬ [email protected] 
    └── [email protected] 

Additional context
Rewriting these ternaries as if {} statements works to get them picked up for internationalization.

Thanks for your work maintaining this library!

wp-pot : The system cannot find the file specified.

Describe the bug
I am using this boilerplate for plugin development https://github.com/wp-strap/wordpress-plugin-boilerplate.

package.json has this script:

"translate": "wp-pot --src '**/**/**/*.php' --dest-file 'languages/test-plugin.pot' --package 'test-plugin' --domain 'test-plugin' --last-translator 'Test Plugin <[email protected]>' --team 'Test Plugin <[email protected]>' --bug-report 'testplugin.com'"

When i run yarn translate i get the following error:

yarn run v1.22.19
$ wp-pot --src '**/**/**/*.php' --dest-file 'languages/test-plugin.pot' --package 'test-plugin' --domain 'test-plugin' --last-translator 'Test Plugin <[email protected]>' --team 'Test Plugin <[email protected]>' --bug-report 'testplugin.com'
The system cannot find the file specified.
error Command failed with exit code 1.

To Reproduce
run yarn translate (wp-pot)

This will throw the following error:
The system cannot find the file specified.
error Command failed with exit code 1.

Module versions
└─┬ [email protected]
└─┬ [email protected]
└── [email protected]

Additional context
What can cause this issue, can't find anything related to it.

wp_pot ignoring certain i18n locations

Describe the bug
Hi, I've noticed recently (I think version 1.9.0) that some of the places I used the __() functions are getting ignored.

To Reproduce
The following place in the following PR is suddenly getting ignored: https://github.com/skaut/crdm-modern/pull/135/files#diff-59dcbaa970c2ffbf709b8a620272ee44R84

Module versions

$ npm ls wp-pot php-parser
[email protected] /home/user/crdm-modern
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]

Additional context
If you want to fully replicate the issue, clone https://github.com/skaut/crdm-modern/tree/preset-sync, checkout commit fda80d7 and run npm run update-translations. You should see 3 places where the POT file is suddenly missing the translation, even though they are still there, jut moved a bit...

Getting proper method name from `propertylookup` chain (with a solution)

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

I realized that the package goes only one level deep when trying to figure out a prototype call.

So if I have something like

gettextFunctions: [
    {name: '$this->_fs->get_text_inline'},
    {name: '$this->_fs->get_text_x_inline', context: 2},
]

It fails to extract. However the following works:

gettextFunctions: [
    {name: '$fs->get_text_inline'},
    {name: '$fs->get_text_x_inline', context: 2},
]

Here is the diff that solved my problem:

diff --git a/node_modules/wp-pot/src/parsers/php-parser.js b/node_modules/wp-pot/src/parsers/php-parser.js
index c8f411d..319a5da 100644
--- a/node_modules/wp-pot/src/parsers/php-parser.js
+++ b/node_modules/wp-pot/src/parsers/php-parser.js
@@ -220,6 +220,32 @@ class PHPParser {
     return comment;
   }
 
+  /**
+   * Get method name from property lookup, going as deep as necessary.
+   * Example: $this->plugin->text_domain->translate
+   *
+   * @param {object} what
+   * @return {string}
+   * @private
+   */
+  _getMethodNameFromPropertyLookup(what) {
+    let methodName = [];
+
+    while(what) {
+      if (what.kind === 'propertylookup') {
+        methodName.push(what.offset.name);
+        what = what.what;
+      } else if (what.kind === 'variable') {
+        methodName.push(what.name);
+        what = null;
+      } else {
+        what = null;
+      }
+    }
+
+    return `\$${methodName.reverse().join('->')}`;
+  }
+
   /**
    * Check if ast is a valid function call
    *
@@ -231,8 +257,8 @@ class PHPParser {
     if (ast.kind === 'call') {
       let methodName = ast.what.name;
 
-      if (ast.what.kind === 'propertylookup' && ast.what.what.kind === 'variable') {
-        methodName = ['$', ast.what.what.name, '->', ast.what.offset.name].join('');
+      if (ast.what.kind === 'propertylookup') {
+        methodName = this._getMethodNameFromPropertyLookup(ast.what);
       } else if (ast.what.kind === 'name' && ast.what.resolution === 'fqn') {
         methodName = ast.what.name.replace(/^\\/, '');
       }

This will keep on looking down the prototype until it has found the variable and then create the method name.

If you're interested in this kind of solution, please let me know. I will create a PR, with tests. Thank you.

This issue body was partially generated by patch-package.

Unable to parse comments.php

Hi,

If I am trying to run wp-pot I am retrieving the following error:
SyntaxError: Parse Error : syntax error, unexpected 'endif' (T_ENDIF) on line 72 | Unable to parse comments.php

The comments.php file looks as follow: http://pastebin.com/gisRzWdz

Am I doing something wrong?

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 5.15.3 to 5.16.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: node-v10: Your tests failed on CircleCI (Details).
  • ci/circleci: node-v8: Your tests failed on CircleCI (Details).
  • ci/circleci: node-latest: Your tests failed on CircleCI (Details).
  • ci/circleci: node-v11: Your tests failed on CircleCI (Details).
  • node-multi-build: * node-v11 - Failed

Release Notes for v5.16.0
  • dfef227 Build: gensite passes rulesMeta to formatter rendering (#11567) (Kevin Partington)
  • c06d38c Fix: Allow HTML formatter to handle no meta data (#11566) (Ilya Volodin)
  • 87a5c03 Docs: func-style: clarify when allowArrowFunctions is used (#11548) (Oliver Joseph Ash)
  • bc3e427 Update: pass rule meta to formatters RFC 10 (#11551) (Chris Meyer)
  • b452f27 Chore: Update README to pull in reviewer data (#11506) (Nicholas C. Zakas)
  • afe3d25 Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550) (Vernon de Goede)
  • 4fe7eb7 Chore: use nyc instead of istanbul (#11532) (Toru Nagashima)
  • f16af43 Chore: fix formatters/table test (#11534) (Toru Nagashima)
  • 78358a8 Docs: fix duplicate punctuation in CLI docs (#11528) (Teddy Katz)
Commits

The new version differs by 11 commits.

  • ded2f94 5.16.0
  • ea36e13 Build: changelog update for 5.16.0
  • dfef227 Build: gensite passes rulesMeta to formatter rendering (#11567)
  • c06d38c Fix: Allow HTML formatter to handle no meta data (#11566)
  • 87a5c03 Docs: func-style: clarify when allowArrowFunctions is used (#11548)
  • bc3e427 Update: pass rule meta to formatters RFC 10 (#11551)
  • b452f27 Chore: Update README to pull in reviewer data (#11506)
  • afe3d25 Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550)
  • 4fe7eb7 Chore: use nyc instead of istanbul (#11532)
  • f16af43 Chore: fix formatters/table test (#11534)
  • 78358a8 Docs: fix duplicate punctuation in CLI docs (#11528)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add more options for .pot header

Currently certain portions of the header for the generated .pot file are fairly inflexible. Specifically, these items:

https://github.com/rasmusbe/wp-pot/blob/6a15bd29fc8840a60f29ad11921b8a85544a3253/pot-maker.js#L140

https://github.com/rasmusbe/wp-pot/blob/6a15bd29fc8840a60f29ad11921b8a85544a3253/pot-maker.js#L144

For the Copyright line, it would be nice to have the ability to specify a different value than the package name, since the copyright is often for a person or company rather than a project.

For the Project-Id-Version line, there's currently no way to include the version.

Discard translation strings extracted from a variable (or property)

Is your feature request related to a problem? Please describe.
I'm working on a WordPress project that sometime calls the translation functions (like __) passing a variable (or an object's property) as the translatable string, like this:

__( $object->name, 'domain' );

When generating the .pot file (using the gulp wrapper), this PHP code is defined as the translatable string value:

msgid "$object->name"
msgstr ""

Describe the solution you'd like
I'd like some kind of way to tell the POT generator to simply discard those calls to the translation functions.
Maybe using some kind of option parameter, or maybe this should be the default behavior (I don't see a use case where having PHP variables in a .pot file would be useful)

Additional context
I tried (rather quickly, I confess) looking at the source code to see where one would need to update the code to implement this, but couldn't find exactly where the matching would be done.

Translator notes are not added in certain cases

This is similar to #11, but there are a few cases where the translator strings are still missed. Here are a few examples:

Works as expected

/* translators: sprintf test translation */
sprintf( __( 'sprintf translation', 'example-domain' ) );

produces

#. translators: sprintf test translation
#: path/to/file.php:113
msgid "sprintf translation"
msgstr ""

Broken

Case 1

This seems to be an issue when inside an array.

$t = [
	/* translators: sprintf test translation in array */
	sprintf( __( 'sprintf translation in array', 'example-domain' ) ),
];

produces

#: path/to/file.php:117
msgid "sprintf translation in array"
msgstr ""

Case 2

A slightly different example of an issue inside an array.

$t = [
	/* translators: test translation in keyed array */
	'foo' => __( 'translation in keyed array', 'example-domain' ),
];

produces

#: path/to/file.php:120
msgid "translation in keyed array"
msgstr ""

Case 3

this is an issue when inside of a function call.

$message = sprintf(
	/* translators: example inside sprintf */
	__( 'Example inside sprintf', 'example-domain' )
);

produces

#: path/to/file.php:108
msgid "Example inside sprintf"
msgstr ""

An in-range update of mocha is breaking the build 🚨

The devDependency mocha was updated from 6.2.0 to 6.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

mocha is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • Build Failed: Workflow Error
  • Build Failed: Workflow Error

Commits

The new version differs by 11 commits.

  • ef6c820 Release v6.2.1
  • 9524978 updated CHANGELOG for v6.2.1 [ci skip]
  • dfdb8b3 Update yargs to v13.3.0 (#3986)
  • 18ad1c1 treat '--require esm' as Node option (#3983)
  • fcffd5a Update yargs-unparser to v1.6.0 (#3984)
  • ad4860e Remove extraGlobals() (#3970)
  • b269ad0 Clarify effect of .skip() (#3947)
  • 1e6cf3b Add Matomo to website (#3765)
  • 91b3a54 fix style on mochajs.org (#3886)
  • 0e9d8ad tty.getWindowSize is not a function inside a "worker_threads" worker (#3955)
  • 48da42e Remove jsdoc index.html placeholder from eleventy file structure and fix broken link in jsdoc tutorial (#3966)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Improve error handling

Describe the bug
If a PHP file has an error in it, wp-pot causes my entire script to stop. Ideally if a PHP error exists, wp-pot should gracefully fail, rather than completely lock up the remaining scripts.

To Reproduce
Introduce any error in to a PHP file, such as a missing semicolon.

Module versions

Add option to not print file comments?

I am currently running wp-pot in a watch build task, and php-edits are causing noise in the pot files due to line numbers changing. Would you be open to adding an option to surpress generation of the comments? If so I could create a pull request.

Sync *.po files with the original *.pot

Is there a way to sync existing *.po files with the *.pot?

For example, there're new stings in theme files, we generate the new *.pot file with wp-pot, but the existing translation files de_DE.po will not contain the new strings.

Thanks!

Calls to `__` function inside of PHP `match` statements are not added to .pot file.

Describe the bug
When a __ function call is inside of a match statement, the translatable text is not added to the .pot file.

To Reproduce
Add a match statement with a __ function call. Run wp-pot. Confirm that the text is not added to the .pot file.

Module versions
└─┬ [email protected]
└── [email protected]

Additional context
Example of text that doesn't get added to the .pot file:

return match ($product_type) {
	'text' => __( 'Text', 'namspace' )
};

Example of text that does get added to the .pot file:

$types = [
	'text' => __( 'Text', 'namspace' ),
];
return $types[ $product_type ] ?? null;

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 5.12.1 to 5.13.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v5.13.0
  • 91c8884 Chore: use local function to append "s" instead of a package (#11293) (Timo Tijhof)
  • b5143bf Update: for-direction detection false positives/negatives (#11254) (Ruben Bridgewater)
  • 9005e63 Chore: increase camelcase test coverage (#11299) (Redmond Tran)
  • 5b14ad1 Fix: false positive in no-constant-condition (fixes #11306) (#11308) (Pig Fang)
  • 6567c4f Fix: only remove arrow before body in object-shorthand (fixes #11305) (#11307) (Pig Fang)
  • fa2f370 Docs: update rule configuration values in examples (#11323) (Kai Cataldo)
  • 0a3c3ff New: Allow globals to be disabled/configured with strings (fixes #9940) (#11338) (Teddy Katz)
  • dccee63 Chore: avoid hard-coding the list of core rules in eslint:recommended (#11336) (Teddy Katz)
  • c1fd6f5 Chore: remove undocumented Linter#rules property (refs #9161) (#11335) (Teddy Katz)
  • 36e3356 Chore: remove dead code for loading rules (#11334) (Teddy Katz)
  • c464e27 Docs: Rename result -> foo (#11210) (Alexis Tyler)
Commits

The new version differs by 13 commits.

  • 4b267a5 5.13.0
  • 720dce1 Build: changelog update for 5.13.0
  • 91c8884 Chore: use local function to append "s" instead of a package (#11293)
  • b5143bf Update: for-direction detection false positives/negatives (#11254)
  • 9005e63 Chore: increase camelcase test coverage (#11299)
  • 5b14ad1 Fix: false positive in no-constant-condition (fixes #11306) (#11308)
  • 6567c4f Fix: only remove arrow before body in object-shorthand (fixes #11305) (#11307)
  • fa2f370 Docs: update rule configuration values in examples (#11323)
  • 0a3c3ff New: Allow globals to be disabled/configured with strings (fixes #9940) (#11338)
  • dccee63 Chore: avoid hard-coding the list of core rules in eslint:recommended (#11336)
  • c1fd6f5 Chore: remove undocumented Linter#rules property (refs #9161) (#11335)
  • 36e3356 Chore: remove dead code for loading rules (#11334)
  • c464e27 Docs: Rename result -> foo (#11210)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 5.12.0 to 5.12.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v5.12.1
  • eb5c401 Chore: use meta.messages in some rules (2/4) (refs #9870) (#10773) (薛定谔的猫)
  • aa56247 Fix: avoid loading core rules dynamically from FS in Linter (#11278) (Peter Metz)
  • 04450bb Docs: clarify process for adding committers (#11272) (Kai Cataldo)
  • 3ffcf26 Docs: add @g-plane as committer (#11277) (Kai Cataldo)
  • c403445 Fix: warn constant on RHS of || in no-constant-condition (fixes #11181) (#11253) (Merlin Mason)
  • 9194f45 Fix: Manage severity of 1 with TAP reporter (fixes #11110) (#11221) (Gabriel Cousin)
  • 000f495 Docs: fix example for sort-imports ignoreDeclarationSort (#11242) (Remco Haszing)
  • 7c0bf2c Docs: Add npx usage to Getting Started guide (#11249) (eyal0803)
  • da9174e Docs: fixes typo peerDepencies (#11252) (Christian Kühl)
  • 9c31625 Docs: Improve custom formatter docs (#11258) (Nicholas C. Zakas)
Commits

The new version differs by 12 commits.

  • faf3c4e 5.12.1
  • 1010c98 Build: changelog update for 5.12.1
  • eb5c401 Chore: use meta.messages in some rules (2/4) (refs #9870) (#10773)
  • aa56247 Fix: avoid loading core rules dynamically from FS in Linter (#11278)
  • 04450bb Docs: clarify process for adding committers (#11272)
  • 3ffcf26 Docs: add @g-plane as committer (#11277)
  • c403445 Fix: warn constant on RHS of || in no-constant-condition (fixes #11181) (#11253)
  • 9194f45 Fix: Manage severity of 1 with TAP reporter (fixes #11110) (#11221)
  • 000f495 Docs: fix example for sort-imports ignoreDeclarationSort (#11242)
  • 7c0bf2c Docs: Add npx usage to Getting Started guide (#11249)
  • da9174e Docs: fixes typo peerDepencies (#11252)
  • 9c31625 Docs: Improve custom formatter docs (#11258)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

POT Creation date and Revision Date

I'm most probably overlooking something. If so my sincere apologies.

Is there a way to auto-populate the POT-Creation-Date and the PO-Revision-Date headers automatically? I'm using the gulp wrapper and these headers do not get populated by default.

An in-range update of php-parser is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye 👋 and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The dependency php-parser was updated from 3.0.0-prerelease.9 to 3.0.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

php-parser is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • build (13.x): null
  • build (12.x): There are 1 failures, 1 warnings, and 0 notices.
  • build (10.x): null
  • build (8.x): null

Commits

The new version differs by 267 commits.

  • e2a7208 Merge branch 'master' of https://github.com/glayzzle/php-parser
  • 6b7fc5e bump version - release 3.0.0 stable
  • c32890e update headers
  • b6a05e7 add a js test page
  • 918c73b avoid using Buffer.isBuffer - to minimise packed version
  • ea50673 lint
  • cc32972 update lint version + rules
  • 5346b9f Merge pull request #520 from glayzzle/dependabot/npm_and_yarn/acorn-6.4.1
  • 4f62596 Merge pull request #521 from glayzzle/dependabot/npm_and_yarn/jest-25.2.3
  • f0d1ed2 build(deps-dev): bump jest from 25.2.0 to 25.2.3
  • 59009a8 build(deps): [security] bump acorn from 6.1.1 to 6.4.1
  • 3852153 #508 - check issue
  • 262c848 Merge pull request #505 from glayzzle/dependabot/npm_and_yarn/eslint-plugin-jest-23.8.2
  • 497c31b Merge pull request #510 from glayzzle/dependabot/npm_and_yarn/coveralls-3.0.11
  • 8976dca Merge pull request #514 from glayzzle/dependabot/npm_and_yarn/babel-loader-8.1.0

There are 250 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Gulp 4.0 issue

Hello!

My task with wp-pot was broken after update to gulp 4.0.

[16:40:13] The following tasks did not complete: build-translate
[16:40:13] Did you forget to signal async completion?

I use this command for test "gulp build-translate"

image

Add excluded files or folders

Is your feature request related to a problem? Please describe.

If I have vendor folder in my theme, running with config

const wpPot = require('wp-pot');

wpPot({
  destFile: 'src/languages/my-theme.pot',
  domain: 'theme-domain',
  package: 'Theme Name',
  src: ['**/*.php'],
});

the files inside the vendor folder will get picked up, and throw an error (because the packages there don't use translation system like WordPress is).

Describe the solution you'd like

It would be great if there was an option

wpPot({
  src: ['**/*.php'],
  exclude: ['vendor/*.php'],
});

That would exclude this folder from .potfile generation.

String within PHP "catch" are ignored

Hi there,

I found another issue. Texts within "catch" are not generated in .POT file. Please see example:
try{ $a = esc_html__("Text Within Try", "test"); } catch ( Exception $e) { $b = esc_html__("Text Within Catch", "test"); }

And the result of this is:

`# Copyright (C) 2017 Test

This file is distributed under the same license as the test package.

msgid ""
msgstr ""
"Project-Id-Version: test\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;n_noop:1,2;nx:1,2,4c;nx_noop:1,2,3c;x:1,2c;esc_attr;esc_attr_e;esc_attr_x:1,2c;esc_html;esc_html_e;esc_html_x:1,2c\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: test-file.php:307
msgid "Text Within Try"
msgstr ""`

Thanks.

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 6.4.0 to 6.5.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • Build Failed: Workflow Error
  • Build Failed: Workflow Error

Release Notes for v6.5.0
  • 73596cb Update: Add enforceForSwitchCase option to use-isnan (#12106) (Milos Djermanovic)
  • d592a24 Fix: exclude \u000d so new line won't convert to text (fixes #12027) (#12031) (zamboney)
  • e85d27a Fix: no-regex-spaces false positives and invalid autofix (fixes #12226) (#12231) (Milos Djermanovic)
  • b349bf7 Fix: prefer-named-capture-group incorrect locations (fixes #12233) (#12247) (Milos Djermanovic)
  • 7dc1ea9 Fix: no-useless-return autofix removes comments (#12292) (Milos Djermanovic)
  • 0e68677 Fix: no-extra-bind autofix removes comments (#12293) (Milos Djermanovic)
  • 6ad7e86 Fix: no-extra-label autofix removes comments (#12298) (Milos Djermanovic)
  • acec201 Fix: no-undef-init autofix removes comments (#12299) (Milos Djermanovic)
  • d89390b Fix: use async reading of stdin in bin/eslint.js (fixes #12212) (#12230) (Barrie Treloar)
  • 334ca7c Update: no-useless-rename also reports default values (fixes #12301) (#12322) (Kai Cataldo)
  • 41bfe91 Update: Fix handling of chained new expressions in new-parens (#12303) (Milos Djermanovic)
  • 160b7c4 Chore: add autofix npm script (#12330) (Kai Cataldo)
  • 04b6adb Chore: enable eslint-plugin-jsdoc (refs #11146) (#12332) (Kai Cataldo)
  • 9b86167 Docs: Add new ES environments to Configuring ESLint (#12289) (Milos Djermanovic)
  • c9aeab2 Docs: Add supported ECMAScript version to README (#12290) (Milos Djermanovic)
  • 8316e7b Fix: no-useless-rename autofix removes comments (#12300) (Milos Djermanovic)
  • 29c12f1 Chore: cache results in runtime-info (#12320) (Kai Cataldo)
  • f5537b2 Fix: prefer-numeric-literals autofix removes comments (#12313) (Milos Djermanovic)
  • 11ae6fc Update: Fix call, new and member expressions in no-extra-parens (#12302) (Milos Djermanovic)
  • a7894eb New: add --env-info flag to CLI (#12270) (Kai Cataldo)
  • 61392ff Sponsors: Sync README with website (ESLint Jenkins)
  • 2c6bf8e Docs: English fix (#12306) (Daniel Nixon)
  • 6f11877 Sponsors: Sync README with website (ESLint Jenkins)
  • 2e202ca Docs: fix links in array-callback-return (#12288) (Milos Djermanovic)
  • e39c631 Docs: add example for CLIEngine#executeOnText 3rd arg (#12286) (Kai Cataldo)
  • d4f9a16 Update: add support for JSXFragments in indent rule (fixes #12208) (#12210) (Kai Cataldo)
  • c6af95f Sponsors: Sync README with website (ESLint Jenkins)
  • 8cadd52 Sponsors: Sync README with website (ESLint Jenkins)
  • f9fc695 Chore: enable default-param-last (#12244) (薛定谔的猫)
  • 9984c3e Docs: Update README team and sponsors (ESLint Jenkins)
Commits

The new version differs by 32 commits.

  • 76fb571 6.5.0
  • 7359a80 Build: changelog update for 6.5.0
  • 73596cb Update: Add enforceForSwitchCase option to use-isnan (#12106)
  • d592a24 Fix: exclude \u000d so new line won't convert to text (fixes #12027) (#12031)
  • e85d27a Fix: no-regex-spaces false positives and invalid autofix (fixes #12226) (#12231)
  • b349bf7 Fix: prefer-named-capture-group incorrect locations (fixes #12233) (#12247)
  • 7dc1ea9 Fix: no-useless-return autofix removes comments (#12292)
  • 0e68677 Fix: no-extra-bind autofix removes comments (#12293)
  • 6ad7e86 Fix: no-extra-label autofix removes comments (#12298)
  • acec201 Fix: no-undef-init autofix removes comments (#12299)
  • d89390b Fix: use async reading of stdin in bin/eslint.js (fixes #12212) (#12230)
  • 334ca7c Update: no-useless-rename also reports default values (fixes #12301) (#12322)
  • 41bfe91 Update: Fix handling of chained new expressions in new-parens (#12303)
  • 160b7c4 Chore: add autofix npm script (#12330)
  • 04b6adb Chore: enable eslint-plugin-jsdoc (refs #11146) (#12332)

There are 32 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add support for Timber

As Timber uses .twig templates for views where gettext functions would be found, and this project uses a PHP parser, it's not currently possible to extract strings when using Timber.

Feature: Line wrapping

Describe the solution you'd like
It would be nice to have 2 new related (optional) features:

  • line wrapping, using an option to set the max length (GNU Gettext uses 79 characters including quotes)
  • reference comments on separate lines instead of comma-seperated on one line (see also the woocommerce.pot file for example)

The first option might auto-enable the second one for clarity in the resulting POT file.

Option to update the existing po files.

Is your feature request related to a problem? Please describe.
We often have po files for different locales. Updating all of them manually when the strings are added/updated is tedious.

Describe the solution you'd like
There should be an option to update the po files as well when generating the pot file. For example grunt-wp-i18n has the option updatePoFiles.

Parsing error

Describe the bug
Hi, I'm developing a GitHub action based on your library.
But I'm receiving a parse error in the following line:

<?php
$custom = new self::$allowed_providers[ $source ]['class']();

Error: Parse Error : syntax error, unexpected '[', expecting ';' on line 131 | Unable to parse ../widgets/proxio-sso-app-widget.php

Module versions

18:17 $ npm ls wp-pot php-parser
[email protected] /Users/breno-proxio/action-wp-pot
└─┬ [email protected] 
  └── [email protected]

An in-range update of eslint-config-standard is breaking the build 🚨

Version 10.2.0 of eslint-config-standard just got published.

Branch Build failing 🚨
Dependency eslint-config-standard
Current Version 10.1.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As eslint-config-standard is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
Commits

The new version differs by 4 commits .

  • 8f36d5a 10.2.0
  • 0497459 use >= in peer dep semver ranges
  • bcdae19 Merge pull request #81 from lpinca/update/eslint-plugin-standard
  • bc37beb Update eslint-plugin-standard to version 3.0.0

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Comments displaying as "undefined"

I've been noticing a lot of instances of #. undefined preceding translations on the generated .pot file and was able to track this down to what seems to be an issue with comment parsing.

I traced this to:

https://github.com/rasmusbe/wp-pot/blob/master/pot-maker.js#L93

If I wrap line 93 in a simple if statement to check comment for a truthy like:

if (comment) {
  output.push(`#. ${comment}`);
}

I don't get these on the pot file.

I tried to figure out a deeper source but I must confess I'm not well-versed enough to understand exactly what is happening prior to this function with the comment and translation parsing.

I considered opening a PR with this above added but I feel like this is a bandaid patch as opposed to an actual solution or possibly I'm doing something wrong that's causing this to happen.

Thanks,

Error after updating the gulp plugin to 2.0.2

TypeError: ast.children[Symbol.iterator] is not a function
    at parseCodeTree (...\node_modules\wp-pot\index.js:271:28)
    at parseCodeTree (...\node_modules\wp-pot\index.js:272:7)
    at parseFile (...\node_modules\wp-pot\index.js:300:3)
    at wpPot (...\node_modules\wp-pot\index.js:479:5)
    at DestroyableTransform._flush (...\node_modules\gulp-wp-pot\index.js:51:25)
    at DestroyableTransform.<anonymous> (...\node_modules\readable-stream\lib\_stream_transform.js:115:49)
    at DestroyableTransform.g (events.js:292:16)
    at emitNone (events.js:86:13)
    at DestroyableTransform.emit (events.js:185:7)
    at prefinish (...\node_modules\readable-stream\lib\_stream_writable.js:503:12)
    at finishMaybe (...\node_modules\readable-stream\lib\_stream_writable.js:511:7)
  • I'm using gulp-wp-pot but seems to me it's wp-pot problem.
  • also on another wp plugin, this update works fine.
  • guess it's about parsing wp noop functions.

An in-range update of eslint-plugin-node is breaking the build 🚨

Version 7.0.1 of eslint-plugin-node was just published.

Branch Build failing 🚨
Dependency eslint-plugin-node
Current Version 7.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v7.0.1

Bug fixes

  • It fixed false positive that the node/no-unsupported-features/node-builtins reports the process.emitWarning method on Node.js >=6 <8. It was supported since Node.js 6.0.0.
Commits

The new version differs by 3 commits.

  • a4a7ad2 7.0.1
  • 44b57ed Fix: false positive 'no-unsupported-features/node-builtins'
  • cde4c82 Docs: update README.md

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Ignore textdomains other than specified

Always disturbs when your POT file includes strings that do not belong to your domain.

__('My text', 'my-domain') -- include
__('Something', 'woocommerce') -- not mine, ignore.
__('Save') -- not textdomain, ignore (a standard WP message?)

An in-range update of eslint-plugin-import is breaking the build 🚨

Version 2.4.0 of eslint-plugin-import just got published.

Branch Build failing 🚨
Dependency eslint-plugin-import
Current Version 2.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As eslint-plugin-import is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 10 commits.

  • 44ca158 update utils changelog
  • a3728d7 bump eslint-module-utils to v2.1.0
  • 3e29169 bump v2.4.0
  • ea9c92c Merge pull request #737 from kevin940726/master
  • 8f9b403 fix typos, enforce type of array of strings in allow option
  • 95315e0 update CHANGELOG.md
  • 28e1623 eslint-module-utils: filePath in parserOptions (#840)
  • 2f690b4 update CI to build on Node 6+7 (#846)
  • 7d41745 write doc, add two more tests
  • dedfb11 add allow glob for rule no-unassigned-import, fix #671

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

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.