You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
comment is not added (anymore?) when running wp i18n make-pot
#121 (comment) provides an example where it should exist, but it seems only the plural issue was fixed there, but the "php-format" comment is/was still missing.
Describe how other contributors can replicate this bug
Let us know what environment you are running this on
WP-CLI version: 2.11.0
Provide a possible solution
If there is a placeholder add the php-format comment (like it's already done for the "translators:" anyway, so in those cases + those where we don't have a translators comment)
I don‘t recall ever adding this, so this was never there. It‘s specifically for xgettext/msgfmt. From the docs:
These flags should not be added by a human. Instead only the xgettext program adds them. In an automated PO file processing system as proposed here, the user’s changes would be thrown away again as soon as the xgettext program generates a new template file.
The c-format flag indicates that the untranslated string and the translation are supposed to be C format strings. The no-c-format flag indicates that they are not C format strings, even though the untranslated string happens to look like a C format string (with ‘%’ directives).
From what I can see in the msgfmt code at first glance, it checks whether singular&plurals have the same amount of formats and whether those are valid.
I don’t think we really need this for WordPress translations though… GlotPress doesn‘t use this and has its own validation for things like incorrect number of placeholders.
Using this command here with msgfmt is also unlikely, and I don‘t see us adding similar validation to the make-mo command….
it checks whether singular&plurals have the same amount of formats and whether those are valid.
Exactly that's what it would be useful for. Right now we have a custom post-processor to check those, however it would be much better if translators would get an error in their translation tool right away.
Using this command here with msgfmt is also unlikely
Lots of plugins use that actually instead of the wp-cli commands for po/mo
Hmm okay, well I guess it would be relatively easy to add, so PRs welcome :)
We already have SPRINTF_PLACEHOLDER_REGEX in MakePotCommand, so in PhpFunctionsScanner and JsFunctionsScanner we can check the extracted strings for placeholders and then do $translation->addFlag( 'php-format' ). This should be easy to add tests for too.
This should help with anyone using msgfmt.
Ideally we add some validation logic to make-mo and make-php as well. We already do some validation in make-pot (see audit_strings() method, which we could extract into a reusable trait.
Activity
swissspidy commentedon Feb 4, 2025
I don‘t recall ever adding this, so this was never there. It‘s specifically for xgettext/msgfmt. From the docs:
From what I can see in the msgfmt code at first glance, it checks whether singular&plurals have the same amount of formats and whether those are valid.
I don’t think we really need this for WordPress translations though… GlotPress doesn‘t use this and has its own validation for things like incorrect number of placeholders.
Using this command here with msgfmt is also unlikely, and I don‘t see us adding similar validation to the make-mo command….
Curious to learn about your use case though!
kkmuffme commentedon Feb 4, 2025
Exactly that's what it would be useful for. Right now we have a custom post-processor to check those, however it would be much better if translators would get an error in their translation tool right away.
Lots of plugins use that actually instead of the wp-cli commands for po/mo
swissspidy commentedon Feb 4, 2025
Hmm okay, well I guess it would be relatively easy to add, so PRs welcome :)
We already have
SPRINTF_PLACEHOLDER_REGEXinMakePotCommand, so inPhpFunctionsScannerandJsFunctionsScannerwe can check the extracted strings for placeholders and then do$translation->addFlag( 'php-format' ). This should be easy to add tests for too.This should help with anyone using
msgfmt.Ideally we add some validation logic to
make-moandmake-phpas well. We already do some validation inmake-pot(seeaudit_strings()method, which we could extract into a reusable trait.