-
-
Notifications
You must be signed in to change notification settings - Fork 138
Extraction of variables and concatenated strings #98
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
|
Another problem I found is that the extractor fails in this case: |
|
|
Maybe we should do the same as gettext (take the string part before the variable) to be fully compatible. But, on the other hand, if the parameter contains variables, this is an anomaly and this may be notified (for example using an exception: "the id string in the file x, line x and column x contains a variable"). The problem is that depending of the function, the position of the arguments that can contain variables is different. For example this is fine: __('hello %s', $name);but this not: p__('context', 'hello '.$name);The problem to handle this is that the function extraction and manipulation are executed by different functions. So the easiest is to ignore the variables and do the same than gettext. |
Ok. switch ($form) {
case 'short':
$t = 'Hi';
break;
case 'long':
$t = 'Hello';
break;
}
$out = __($t);This is totally legal (and is a very simplified version of what we have in our project). So, I'll implement this behaviour. |
|
Good point 👍 |
|
Everything should be ok (at least in theory - I still have to perform some tests). Travis is failing because it tests the merged version of my pull request, so the error should be fixed when #99 will be merged |
|
If you relaunch https://travis-ci.org/oscarotero/Gettext/builds/110324540 it should pass now |
|
I tested this PR against a project of mine (4300+ strings) and the output is the same as the one of xgettext now 😉 |
Extraction of variables and concatenated strings
|
Good job. Thank you! |
Thanks! It's a bit slower than before, but the results are now really good 😉 |
|
Sensiolab reports this error https://insight.sensiolabs.com/projects/496dc2a6-43be-4046-a283-f8370239dd47/analyses/30 |
|
Whoops, it seems I left there that line I used for debug purposes... |
|
Ok, don't worry. I can remove it as soon I have my computer. |
I run a few tests again a PHP project with ~4300 translatable strings, comparing the results of
xgettextand those of thePhpCodeextractor.I only found two problems:
xgettext(correctly) does not extracts strings like themein__($avoid['me']). I think that the correct solution would be to do not extract strings with variables (since it does not have any sense), but gettext stops as soon as it find a variable (for instance from__('Stop at the variable'.$var.'!')it extractsStop at the variable) - so I'd adopt this same approach for consistency.Consider this example:
xgettext (correctly) extracts
'line1 line2', but thePhpCodeextractor only extracts'line1'.I added some tests here to highlight the above problems.