Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Feb 3, 2017
Merged

[FrameworkBundle] fixed custom domain for translations in php templates #21359

merged 1 commit into from
Feb 3, 2017

Conversation

robinlehrmann
Copy link

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(
Copy link
Member

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.

Copy link
Author

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) {
Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

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])) {
Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

What about getStringValue() instead?

Copy link
Author

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]) {
Copy link
Contributor

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')

Copy link
Author

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.

Copy link
Member

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,
Copy link
Contributor

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

Copy link
Author

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 :) ?

Copy link
Contributor

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'); ?>

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

@robinlehrmann robinlehrmann left a 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.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jan 24, 2017
@robinlehrmann
Copy link
Author

Hi, @aitboudad @xabbuh
I've fixed the issue and added some tests for it. Could you review my changes please ?

@@ -24,6 +24,8 @@
class PhpExtractor extends AbstractFileExtractor implements ExtractorInterface
{
const MESSAGE_TOKEN = 300;
const MESSAGE_ARGUMENTS_TOKEN = 1000;
Copy link
Member

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

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

👍

Status: Reviewed

@fabpot
Copy link
Member

fabpot commented Feb 3, 2017

Thank you @robinlehrmann.

@fabpot fabpot merged commit 78c0ec5 into symfony:2.7 Feb 3, 2017
fabpot added a commit that referenced this pull request Feb 3, 2017
…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
This was referenced Feb 6, 2017
@robinlehrmann robinlehrmann deleted the issue-20135 branch February 6, 2017 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants