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

Add line number references to extracted file header data #65

Open
swissspidy opened this issue Jul 31, 2018 · 3 comments
Open

Add line number references to extracted file header data #65

swissspidy opened this issue Jul 31, 2018 · 3 comments

Comments

@swissspidy
Copy link
Member

This is something I noticed while working on #61 / #64.

When printing warnings for missing / invalid strings I want to print the warning together with the location of where that string is.

For file headers that's currently not possible because they're being extracted using regex. This is mainly because I borrowed that code from https://develop.svn.wordpress.org/trunk/tools/i18n/makepot.php, which has been doing that for years.

However, since we already leverage a powerful gettext extraction library, I wonder if we could add a new extractor just for these file headers.

retrieve_main_file_data(), get_file_data() get_file_headers(), get_file_data_from_string(), and _cleanup_header_comment() would be affected/obsoleted by such a change.

I'm not sure how feasible it is, but it would make for a more robust solution that is more similar to the other extractors and easier to test than some old regex from WordPress core.

Also, we could make sure to get the filename / line references that way.

I guess it's the same argument as regex vs. using a DOM parser to parse some HTML in PHP.


I just saw that the Template Name: extraction already resides in \WP_CLI\I18n\IterableCodeExtractor.

We should probably consolidate this somehow.

@swissspidy
Copy link
Member Author

Another benefit:

For WordPress core we wouldn't need to extract Hello Dolly separately, but simultaneously and with the correct location info.

We'd still need some way to detect whether the project is a plugin, theme, core, or something else.

@swissspidy
Copy link
Member Author

Follow-up: #376

@swissspidy swissspidy reopened this Jan 16, 2024
@swissspidy swissspidy changed the title Use extractor instead of regex to get main file header data Add file references to extracted file header data Jan 16, 2024
@swissspidy swissspidy changed the title Add file references to extracted file header data Add line number references to extracted file header data Jan 16, 2024
@swissspidy
Copy link
Member Author

See #377 (comment) for how this could maybe be achieved with regex.

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

1 participant