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

Command to add text domains to i18n functions #25

Closed
swissspidy opened this issue Apr 15, 2018 · 10 comments
Closed

Command to add text domains to i18n functions #25

swissspidy opened this issue Apr 15, 2018 · 10 comments

Comments

@swissspidy
Copy link
Member

It might be a good time to think about a wp i18n add-text-domain command.

See #7, #11 for discussions / some background about this.

@swissspidy
Copy link
Member Author

swissspidy commented May 2, 2018

This would mean we need to work with the AST of PHP / JavaScript file.

#26 already uses a JS AST parser.

https://github.com/nikic/PHP-Parser is a popular one for PHP. It would make sense to use that for the make-pot task as well, however it requires PHP 7.

@swissspidy
Copy link
Member Author

After looking at #28 I think this command would need:

  1. An --only-missing option to only add the domain where it's missing
  2. A way to only replace a specific domain with a new one, in case the source folder contains strings with multiple text domains.

@varunsridharan
Copy link

@swissspidy is there any update on this ?

@varunsridharan
Copy link

@swissspidy how can i use add-text-domain cmd in cli to append text domains to wp functions inside my plugin / theme ( __() )

@swissspidy
Copy link
Member Author

@varunsridharan No update I am afraid. add-text-domain does currently not exist.

However, you can achieve this using the WordPress-Coding-Standards PHPCS configuration as long as you set your text domain accordingly.

I think that is probably the best solution for this specific task.

Once you've configured PHPCS with the WordPress coding standards, you can use phpcbf to automatically fix any i18n functions that don't use your required text domain.

@varunsridharan
Copy link

@swissspidy thanks for your faster reply. well i work on quite a lot of projects and i use common rules-set.xl in phpstorm and i dont think that will work for me :-(

@swissspidy
Copy link
Member Author

I think that should still work. You don't have to include all of WPCS in your ruleset, just the text domain sniff is enough. Then, you can even auto-fix things directly in PHPStorm.

@varunsridharan
Copy link

Based on my testing i can say that PHPStorm dose not support multiple ruleset in a single project.

@varunsridharan
Copy link

varunsridharan commented Jul 5, 2019

@swissspidy thanks for your time. i was not able to get this done using PHPStrom / Rule set not sure why may be i was doing something wrong.

and i created a simple composer package which dose this job
Old Link : https://github.com/varunsridharan/wp-cli
New Link : https://github.com/varunsridharan/wp-cli-textdomain

@swissspidy
Copy link
Member Author

Closing for now as this seems better suited for a tool like PHPCS, as mentioned in the discussion above. https://github.com/varunsridharan/wp-cli-textdomain exists for people who want a dedicated command/script.

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