-
Notifications
You must be signed in to change notification settings - Fork 823
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
FEAT support variables as second and third argument #11521
base: 5
Are you sure you want to change the base?
Conversation
Please fill in the PR checklist. That checklist is there to help you as the contributor double check you've done everything you need to do. That means that I as the reviewer will then know whether you have done those things which speeds things up a little. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this review is just me asking for clarification, since I haven't worked in this part of the code much before so I need a bit of help understanding what's going on.
@@ -618,15 +618,31 @@ public function collectFromCode($content, $fileName, Module $module) | |||
$potentialClassName = null; | |||
$currentUse = null; | |||
$currentUseAlias = null; | |||
|
|||
$inVar = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "inVar"? Does this just track "something is in a variable"?
It looks like we use it to track only the most recently encountered variable in the entire file, but only until the assignment is finished being parsed and then we stop tracking it. Is that correct?
Might warrant an inline comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inVar is how i've collected $str = 'something' before the _t call is made
this allows $str = 'Lazy loading can increase perceived page performance by slightly delaying media loading. ' .
'Eager loading will load files as soon as possible and can be used if the image is in view as the page ' .
'loads (above or near the fold).';
$titleTipContent = _t('DemoAdmin.LoadingTitleTip', $str);
to work, even when being multiple strings concatenated together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it correctly work for adding to a variable later? e.g.
$x = 'some value';
$x .= ' and some more text';
continue; | ||
} | ||
|
||
// The variable is the second argument or present in the parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "the parameter" in this context? Does that mean it's in the third (or subsequent) argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's when you have _t('key', 'translation', $var) or _t('key', 'translation', 'comments' . $var) => not than this should be ever done anyway, but that can happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you mean it's the third argument (or after the second argument - I guess maybe you mean it could be in the third or later argument?)? If so please change the comment to specify that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure how to phrase that correctly :-)
Please retarget this to the |
Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com>
@GuySartorelli ideally i'd like to make sure there is no regression |
Any change has some chance of regression. There's no known regressions this causes, but because it's code I'm unfamiliar with, there is a chance of regressions that I won't be able to identify. Regardless, as this is adding new functionality, it is better included in a minor release rather than a patch release. |
ok rebased! i don't know if any test or update is needed a unit test would be nice but i didn't go as far as that. i've just tried locally on my project and it seemed to work fine |
I won't have time to test this out myself until at least halfway through next week. |
@GuySartorelli i added the tests and improved how i track strings. i added some comments to make it more clear how it works. the whole test suite is running fine locally |
@@ -733,6 +749,28 @@ public function collectFromCode($content, $fileName, Module $module) | |||
continue; | |||
} | |||
|
|||
// Allow _t(Entity.Key, 'translation', $var) and expand _t(Entity.Key, $var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please respond to these questions.
continue; | ||
} | ||
|
||
// The variable is the second argument or present in the parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you mean it's the third argument (or after the second argument - I guess maybe you mean it could be in the third or later argument?)? If so please change the comment to specify that.
@@ -618,15 +618,55 @@ public function collectFromCode($content, $fileName, Module $module) | |||
$potentialClassName = null; | |||
$currentUse = null; | |||
$currentUseAlias = null; | |||
$inVar = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$inVar = null; | |
$inVar = null; // Tracks the value currently being assigned to a variable |
As per #11521 (comment)
Have I understood that correctly? If not please adjust the comment so it's appropriately indicating the purpose of this variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not tracking the value, it's tracking the name of the variable. the value is stored in inVarText. i've added comments to reflect this
@@ -618,15 +618,31 @@ public function collectFromCode($content, $fileName, Module $module) | |||
$potentialClassName = null; | |||
$currentUse = null; | |||
$currentUseAlias = null; | |||
|
|||
$inVar = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it correctly work for adding to a variable later? e.g.
$x = 'some value';
$x .= ' and some more text';
Co-authored-by: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com>
@GuySartorelli updated the code and added test cases for falsy values and $x = 'test' ; $x .= 'more'; |
Description
This PR upgrades the text collector to support collecting arguments as variables for second and third argument (see examples below).
Manual testing steps
Issues
Pull request checklist