-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add support for pretty-printing PHP files in wp i18n make-php command #396
base: main
Are you sure you want to change the base?
Conversation
…the end of file and improve test with more entries to test plural one
@sovetski FYI: You can run Behat test locally easily using commands like:
This will run behat test of given file and 263 is the line number of your new Scenario. This will be helpful for quick test in local environment. With using |
Thank you, it helped a lot, now the test pass successfully |
src/PhpArrayGenerator.php
Outdated
* | ||
* @param mixed $value The variable you want to export. | ||
* @param int $level The current indentation level. | ||
* @param int $indentation The number of spaces for indentation. Default is 4. |
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.
Can we do tabs 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.
I like using tabs for my own projects, but here as it is something which will be used on other developers IDE, I prefer to use spaces, because tabs configuration depends on the configuration of user. A space will be every time a space, but tab not. Some resources not related to this subject but still on the same issue:
https://medium.com/@peey/what-is-the-inconsistent-use-of-tabs-and-spaces-in-indentation-error-and-why-is-it-caused-f3bbb8b2568b
https://stackoverflow.com/questions/5685406/inconsistent-use-of-tabs-and-spaces-in-indentation
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 prefer to use spaces, because tabs configuration depends on the configuration of user
That's actually an advantage of tabs :-) But I don't wanna start yet another tabs vs spaces discussion here.
I am mainly suggesting using tabs because that's the WordPress coding standard and IMHO we should be consistent with 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.
Great, in this case I will try to change it to tabs to respect the standards, thanks!
src/PhpArrayGenerator.php
Outdated
private static function pretty_export( $values, $indentation = 2 ) { | ||
$result = '[' . PHP_EOL; | ||
$indent = str_repeat( ' ', $indentation ); | ||
|
||
foreach ( $values as $key => $value ) { | ||
$result .= $indent . str_repeat( ' ', $indentation ) . "'$key' => "; | ||
|
||
if ( is_array( $value ) ) { | ||
$result .= self::pretty_export( $value, $indentation + $indentation ); | ||
} elseif ( strpos( $value, "\0" ) !== false ) { | ||
$parts = explode( "\0", $value ); | ||
$result .= "'" . implode( "' . \"\\0\" . '", array_map( 'addslashes', $parts ) ) . "'"; | ||
} else { | ||
$result .= "'$value'"; | ||
} | ||
|
||
$result .= ',' . PHP_EOL; | ||
} | ||
|
||
$result .= $indent . ']'; | ||
return $result; | ||
} |
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 whole function is a bit hard to grasp. What's with the\0
checks here for example, why do we need 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.
Without that, instead of getting
'You have %d new message' => 'Du hast %d neue Nachricht' . "\0" . 'Du hast %d neue Nachrichten',
we will get
'You have %d new message' => 'Du hast %d neue NachrichtDu hast %d neue Nachrichten',
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.
My question is why is it doing this here and why is this not needed for the existing, non-pretty var_export()
method?
I don't understand. The command When I add |
It sounds like it doesn't match exactly. When I manually run the
|
It should resolve this issue: #395