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

PHP format is not aligned to sprintf #9698

Closed
2 tasks done
matzeeable opened this issue Aug 7, 2023 · 5 comments
Closed
2 tasks done

PHP format is not aligned to sprintf #9698

matzeeable opened this issue Aug 7, 2023 · 5 comments
Labels
question This is more a question for the support than an issue.

Comments

@matzeeable
Copy link

Describe the issue

When using the php-format check, it does not work with e.g. escaping.

I already tried

  • I've read and searched the documentation.
  • I've searched for similar issues in this repository.

Steps to reproduce the behavior

The current regular expression does not work with escaped percent characters or spaces: https://regex101.com/r/kbxtub/1

PHP_PRINTF_MATCH = re.compile(
r"""
%( # initial %
(?:(?P<ord>\d+)\$)? # variable order, like %1$s
(?P<fullvar>
[ +#-]* # flags
(?:\d+)? # width
(?:\.\d+)? # precision
(hh|h|l|ll)? # length formatting
(?P<type>[a-zA-Z%]) # type (%s, %d, etc.)
|) # incomplete format string
)""",
re.VERBOSE,
)

Expected behavior

%% and % f should not be found as sprintf placeholder.

Screenshots

image

Exception traceback

No response

How do you run Weblate?

Docker container

Weblate versions

No response

Weblate deploy checks

No response

Additional context

No response

@nijel
Copy link
Member

nijel commented Aug 7, 2023

The check is correct because the ordering of the format strings have changed. Whatever was supposed to be printed as %d will be printed as %s with your translation.

@nijel nijel added the question This is more a question for the support than an issue. label Aug 7, 2023
@github-actions
Copy link

github-actions bot commented Aug 7, 2023

This issue has been marked as a question by a Weblate team member. Why? Because it belongs more to the professional Weblate Care or community Discussions than here. We strive to answer these reasonably fast here, too, but purchasing the support subscription is more responsible and faster for your business. And it makes Weblate stronger as well. Thanks!

In case your question is already answered, making a donation is the right way to say thank you!

@matzeeable
Copy link
Author

Thanks for the prompt response. Changing to %1$s and %2$s seems to resolve the issue. But why is %% marked as variable? %% is an escaped %.

@nijel
Copy link
Member

nijel commented Aug 7, 2023

Because it is token processed by printf. Weblate will not complain if that is the only missing/extra one.

@github-actions
Copy link

github-actions bot commented Aug 7, 2023

The issue you have reported is now resolved. If you don’t feel it’s right, please follow its labels to get a clue for further steps.

  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This is more a question for the support than an issue.
Projects
None yet
Development

No branches or pull requests

2 participants