Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Translation] Fix InvalidArgumentException when using untranslated plural forms from .po files#24594

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
BjornTwachtmann wants to merge2 commits intosymfony:3.3fromBjornTwachtmann:translation_fix_po_untranslated
Closed

[Translation] Fix InvalidArgumentException when using untranslated plural forms from .po files#24594

BjornTwachtmann wants to merge2 commits intosymfony:3.3fromBjornTwachtmann:translation_fix_po_untranslated

Conversation

@BjornTwachtmann
Copy link
Contributor

@BjornTwachtmannBjornTwachtmann commentedOct 17, 2017
edited by javiereguiluz
Loading

QA
Branch?3.2
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#24593
LicenseMIT

This PR fixes the bug in#24593. It's not the absolutely ideal way to address the issue, but I don't see how else to handle it without either dropping support for pips in translation strings, or rearchitecting the code that feeds translations to the MessageSelector as pipe separated in the first place.

preg_match_all('/(?:\|\||[^\|])++/',$message,$parts);
$parts =array();
if (preg_match('/^\|+$/',$message)) {
$parts =explode('|',$message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this is broken if previous parts of the message have escaped pipes in them

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@stof ,sorry, but I don't understand. What do you mean by "previous parts of the message"? Is this function called recursively, or on partial strings?

As far as I can see the regex matches any $message which has only pipes in it. My assumtion is that this means the message itself is empty. Could you explain if this is incorrect, I'm not that familiar with Translate internals.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I can confirm this fix the issue I have reported previously#24359

When for example a translation has 3 empty plurals then the value of $message is "||" becausePoFileLoader.php use pipes as a concatenator. This PR fix the cases where the messages are empty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What if onlysome of the plurals are empty ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If only some of the plurals are empty,$message should contain characters other than | , and the /^|+$/ regex will not match. Execution should then proceed into the elseif block and behaviour will be exactly the same as the current code.

I appreciate that my patch doesn't fix the case you describe. However it doesn't break that case any further, and I cannot figure out how to fix that case at this stage in the program's execution. As I mentioned in the linked ticket, I could only fix that by revisiting the idea of representing multiple translations as a pipe separated string, and I'm not familiar enough with all of the use cases for Translate to attempt that.

This does fix the most common case in PO files, that's all I'm attempting to do. It would make sense for somebody with more knowledge of translate to address the edge cases you describe, but until that can be done this will at least prevent a lot of problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ah, I missed the fact that it was anchored on both ends

@javiereguiluzjaviereguiluz changed the title[Translation][transChoice] Fix InvalidArgumentException when using un…[Translation] Fix InvalidArgumentException when using untranslated plural forms from .po filesOct 18, 2017
@nicolas-grekasnicolas-grekas added this to the3.3 milestoneOct 18, 2017
{
preg_match_all('/(?:\|\||[^\|])++/',$message,$parts);
$parts =array();
if (preg_match('/^\|+$/',$message)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

please change the regex to^\|++$ to avoid useless backtracking (which could cause issues with long strings). Backtracking will never allow to find a match in a different way for this regex.

@BjornTwachtmann
Copy link
ContributorAuthor

@stof , changes made as requested :)

@nicolas-grekasnicolas-grekas changed the base branch from3.2 to3.3November 5, 2017 15:31
@nicolas-grekas
Copy link
Member

But tests are failing.

@BjornTwachtmann
Copy link
ContributorAuthor

@nicolas-grekas I've rebased the branch on 3.3 and all tests pass now. I think there were some failing tests in the 3.2 branch

@BjornTwachtmann
Copy link
ContributorAuthor

@nicolas-grekas@stof tests are passing, is this okay to merge now?

@Tasiobg
Copy link

This has been rebased on 3.3 and tests are passing. Can this be merged please?

@xabbuh
Copy link
Member

Are 2.7 and 2.8 not affected?

@BPScott
Copy link
Contributor

@xabbuh the escaping code that this touches was added in v3.2 in#17662

xabbuh reacted with thumbs up emoji

@fabpot
Copy link
Member

Thank you@BjornTwachtmann.

fabpot added a commit that referenced this pull requestDec 11, 2017
…anslated plural forms from .po files (BjornTwachtmann)This PR was squashed before being merged into the 3.3 branch (closes#24594).Discussion----------[Translation] Fix InvalidArgumentException when using untranslated plural forms from .po files| Q             | A| ------------- | ---| Branch?       | 3.2| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#24593| License       | MITThis PR fixes the bug in#24593. It's not the absolutely ideal way to address the issue, but I don't see how else to handle it without either dropping support for pips in translation strings, or rearchitecting the code that feeds translations to the MessageSelector as pipe separated in the first place.Commits-------fea815b [Translation] Fix InvalidArgumentException when using untranslated plural forms from .po files
@fabpotfabpot closed thisDec 11, 2017
This was referencedDec 15, 2017
@fabpotfabpot mentioned this pull requestJan 5, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof requested changes

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@TasiobgTasiobgTasiobg approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

8 participants

@BjornTwachtmann@nicolas-grekas@Tasiobg@xabbuh@BPScott@fabpot@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp