php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
687 stars 134 forks source link

\n in JS files: backslash \ is stripped #200

Closed jakubjo closed 5 years ago

jakubjo commented 5 years ago

Thank you for this awesome package!

I've encountered following issue:

When scanning JavaScript files the backslash of new line sequences is stripped.

gettext("First Line\nSecond Line\nThird Line");

Results in following msgid:

msgid "First LinenSecond LinenThird Line"

When I remove the case in JsFunctionsScanner:39 extracting is working as intended. https://github.com/oscarotero/Gettext/blob/93176b272d61fb58a9767be71c50d19149cb1e48/src/Utils/JsFunctionsScanner.php#L39

I'd submit a PR, but I'm unsure how to fix this properly and do not really understand all whats happening in JsFunctionsScanner.

oscarotero commented 5 years ago

I guess we need to check if the current status is simple-quote or double-quote and make a break if so. Something like this: https://github.com/oscarotero/Gettext/blob/93176b272d61fb58a9767be71c50d19149cb1e48/src/Utils/JsFunctionsScanner.php#L55

Thanks!

jakubjo commented 5 years ago

We use \n also in single quotes in JS. I believe JS does not require double quotes around new line sequences.

I've submitted a PR. In our case the issue is fixed and everything is working as intended. I'm curious what you'll say.