Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp i18n make-pot: Support PHP8 named parameters #386

Open
lichtmetzger opened this issue Feb 14, 2024 · 1 comment
Open

wp i18n make-pot: Support PHP8 named parameters #386

lichtmetzger opened this issue Feb 14, 2024 · 1 comment

Comments

@lichtmetzger
Copy link

PHP8 has been out since 2020, but the make-pot command still doesn't support named parameters in __() function calls. It would be nice to have this feature so we can write more modern code in our plugins and themes.

This works:
__('Oops! Something went wrong!', 'wp-plugin-textdomain');

This does not work:
__(text: 'Oops! Something went wrong!', domain: 'wp-plugin-textdomain');

@swissspidy
Copy link
Member

This command uses an external library for scanning PHP files and extracting strings from them, see https://github.com/php-gettext/Gettext. Such support would need to be added there first if not already present. At first glance it doesn't seem like it, at least there aren't any tests. So this would require an upstream feature request first.

Second, and probably most important, it is worth noting that WordPress does not officially support named parameters and does not guarantee that parameters won't be renamed. Use at your own risk.

This risk is also relevant for string extraction. Right now the __() function in WordPress has this signature: function __( $text, $domain = 'default' ) {}. We would have to hardcode this signature in our code base. But should WordPress ever change the signature (again, there is no guarantee this won't happen), we would have to update it as well.

Given the lack of support from the WordPress side, and the (possible) limitation from the upstream library side, I don't see us supporting extraction with named parameters anytime soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants