-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] fixed custom domain for translations in php templates #21359
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
Conversation
robinlehrmann
commented
Jan 20, 2017
Q | A |
---|---|
Branch? | 2.7 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #20135 |
License | MIT |
Doc PR |
@@ -37,7 +39,29 @@ class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface | |||
* | |||
* @var array | |||
*/ | |||
protected $sequences = array( | |||
protected static $sequences = array( |
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.
The static
change should be reverted.
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.
Done.
@@ -153,26 +198,38 @@ protected function parseTokens($tokens, MessageCatalogue $catalog) | |||
$tokenIterator = new \ArrayIterator($tokens); | |||
|
|||
for ($key = 0; $key < $tokenIterator->count(); ++$key) { | |||
foreach ($this->sequences as $sequence) { | |||
foreach (self::$sequences as $sequence) { |
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.
Must then be reverted too.
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.
Done
@@ -105,13 +129,34 @@ private function seekToNextRelevantToken(\Iterator $tokenIterator) | |||
} | |||
} | |||
|
|||
private function seekToMessageParamsEnd(\Iterator $tokenIterator) |
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.
maybe better name this seekBehindMessageParams
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.
Done
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 would now rename this too (something like skipMethodArgument()
)
@@ -85,7 +109,7 @@ public function setPrefix($prefix) | |||
*/ | |||
protected function normalizeToken($token) | |||
{ | |||
if (isset($token[1]) && 'b"' !== $token) { | |||
if ('b"' !== $token && isset($token[1])) { |
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.
IMO this should be reverted as it is not part of the bug fix.
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.
Done
*/ | ||
private function getMessage(\Iterator $tokenIterator) | ||
private function provideRawString(\Iterator $tokenIterator) |
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 about getStringValue()
instead?
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.
Done
for (; $tokenIterator->valid(); $tokenIterator->next()) { | ||
$t = $tokenIterator->current(); | ||
|
||
if ('[' === $t[0] || '(' === $t[0]) { |
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.
you should not take account of braces inside a string
->trans('msg', [ 'p' => '[ \'' ], 'not_messages')
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 added this line to my tests too and it passes.
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.
@aitboudad In your example, $t
will be an array consisting of three elements where the value at index 0 is T_CONSTANT_ENCAPSED_STRING
if I am not mistaken.
'(', | ||
self::MESSAGE_TOKEN, | ||
',', | ||
T_LNUMBER, |
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 can be an expression or function call
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 added a new test with array_map function and the tests passes. Can you explain what you mean please :) ?
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.
<?php echo $view['translator']->transChoice('msg', 10 + 1, [], 'not_messages'); ?>
<?php echo $view['translator']->transChoice('msg', intval(4.5), [], 'not_messages'); ?>
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.
Okay, I added this lines and the Tests don't pass. Thank you!
I will fix it asap.
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 guess you can use the same approach here that is already used for skipping the message params.
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 added some tests and it passes.
Hi, @aitboudad @xabbuh |
@@ -24,6 +24,8 @@ | |||
class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface | |||
{ | |||
const MESSAGE_TOKEN = 300; | |||
const MESSAGE_ARGUMENTS_TOKEN = 1000; |
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 would name this METHOD_ARGUMENTS_TOKEN
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.
👍
Status: Reviewed
Thank you @robinlehrmann. |
…php templates (robinlehrmann) This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle] fixed custom domain for translations in php templates | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20135 | License | MIT | Doc PR | Commits ------- 78c0ec5 [FrameworkBundle] fixed custom domain for translations in php templates