Hi,
I'm running the potx coder review on a number of modules and am getting a lot of "Invalid marker content" errors. I was wondering if you could provide a more detailed error message because it won't always be clear to the developer what needs to be changed in their code.
Also, I too am not totally clear on the different situations where "invalid marker content" could arise. Take for example:
$message = "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: !htaccess";
$repl = array('%directory' => $directory, '!htaccess' => '<br />'. nl2br(check_plain($htaccess_lines)));
form_set_error($form_item, t($message, $repl));
watchdog('security', $message, $repl, WATCHDOG_ERROR);
The above code looks okay to me. The $message string is correctly formatted and the variables are provided in an array in $repl. Is the "invalid marker content" error received just because we're passing t() the $message variable rather than the string directly?
Also, does this error signify that potx was unable to extract the string? If so, does it mean the string can't be translated?
Doug and I are putting together an internationalization review for coder (see http://groups.drupal.org/node/15230) so if this is something coder could check for, let us know. Or if you have any additional ideas for checks, send them on too! :)
Cheers,
Stella
| Comment | File | Size | Author |
|---|---|---|---|
| #39 | Lines-after.jpg | 103.29 KB | gábor hojtsy |
| #39 | Lines-before.jpg | 96.55 KB | gábor hojtsy |
| #32 | potx_312523_2.patch | 7.46 KB | gábor hojtsy |
| #17 | potx_312523_1.patch | 4.33 KB | gábor hojtsy |
| #16 | potx_312523.patch | 4.4 KB | stella |
Comments
Comment #1
gábor hojtsyI think it is best if you suggest people to use the potx coder review to those who would like to do localization code checks and develop additional review items in coder or elsewhere. Since this code is and will be used for extraction and it already knows about the error conditions, it is best not to develop another review tool separately, while the potx tool itself can be used to do the review, so there is no question that it is up to date to the latest parsing modes, it is not required to keep two tools in sync :) I admit we can make the error messages better, we can put in more hints for coder to display, etc, I am totally open to these things!
As far as the actual error cited goes, t() needs the string literally, not through a variable. Marker errors are basically anything but a literal string used inside of t().
Since http://drupal.org/node/309875 is already about making the code review inside potx better (please do help out there!), let's make this an issue on better error messages from potx. I've made up a quick patch against the Drupal 5.x.-1.x branch. Since this module runs on four branches, this would need to be ported to four places, so it would be good to check whether this would be useful for your needs and then I can port the changes over. Although you could not try this patch out given the Drupal 5 branch does not have coder integration, I am hopeful you can review and provide feedback on the patch as-is.
Comment #2
gábor hojtsyPart of the feedback I am looking for is whether we should separate the error message itself and its explanation, so coder can report the error and provide the explanation on demand.
Comment #3
gábor hojtsyOk, it was not hard to apply the same changes to the Drupal 6.2 version, so you can actually try it out with coder. Also fixed a style error, so now _potx_marker_error() generates the same all-on-one-line string as the other explanations. Note that http://drupal.org/node/309875 fixes coder integration issues due to the updated coder, so you might need to test the two in tandem.
I am eager for feedback.
Comment #4
gábor hojtsyDoh, already found an omission. _potx_find_t_calls() is used to catch $t(), st(), and in Drupal 5 even watchdog() calls, since these have the same rules as t(). So better use the $function_name used at that moment in the error message as well. Updated the error to reflect this. Should be good for review now.
Comment #5
stella commentedThere are some things I think the potx review can't check for (assuming it just parses the strings), for example missing calls to t(). It's not intended to replace or duplicate any of the potx reviews. See http://groups.drupal.org/node/15230 for the current list of checks done or planned. Though perhaps these two reviews should be merged.
Will try out your patch now. :)
Cheers,
Stella
Comment #6
gábor hojtsyYeah, two of the already implemented checks at the page you linked to are duplicates of what potx already does. Commented on it at http://groups.drupal.org/node/15230#comment-51218
Checking t() in format_plural(), an issue you opened would again be a duplicate, so commented on it at http://drupal.org/node/312510#comment-1027254
I agree code reviews for missing t() calls is not done in potx (and it might even be a good idea to do it right here), but bogus calls to locale functionality is checked and reported.
Comment #7
stella commentedNo afraid this doesn't work. I get "please report this" error. See attached screenshot.
I'm used the latest version of coder and potx from CVS. It doesn't happen for any of the other reviews.
Cheers,
Stella
Comment #8
gábor hojtsyHave you also applied http://drupal.org/node/309875 as I've suggested (I am looking for some fixing of the patch there, but it should work on an English site with Garland)?
Comment #9
stella commentedNo, I missed that bit.
So I installed a new version from CVS again. Applied the patch from #309875 - it succeeded but with one offset:
Then applied the patch from this issue and it failed (applies successfully without the other patch):
I looked at the patches, and removing the 1st change from the 309875.patch fixes the issue. Both patches modified the same line in much the same way.
However, I am still faced with the same issue. I did run update.php and cleared the cache tables too (just to be sure!) but to no avail. :(
Oh, I am using Garland theme and running coder while viewing the site in English.
Comment #10
gábor hojtsyHm, well, I've used the potx coder review successfully with coder quite a few times before. I did not find good docs on how to write custom code reviews, so reverse engineered to find out how should I plug in to there. I think you might be more qualified to look into remaining issues with the integration. This bug is definitely tracked at http://drupal.org/node/309875 and should be fixed to go forward. That might also mark current potx to be useable only with older coder versions while post-commit with newer coder versions (or I did bad reverse engineering and the new stuff will work with both old and new).
Comment #11
stella commentedOk, it's working now, don't ask me why cos I didn't change anything! I think it might be that coder's new cache_coder table isn't getting cleared. Will look into it.
The error messages are definitely more helpful now. However, they do seem slightly long. I think it might be better to shorten them and then add a link to point the user at the more detailed explanation. Look at any of the coder/includes/coder_6x.inc reviews for examples on how to do that. First, however, we need a documentation to point them to. I would be in favour of adding a page to the coding standards area of the handbook with "dos and don'ts" for internationalization handling in modules. (As the expert in this, I don't suppose you want to volunteer? ;) )
I would also change the wording on some of the messages a bit. The attached patch does that for most of the messages. I think the message in relation to hook_perm() also needs to be changed but not sure what to.
Do you really need to specify the file name, line number and function for each error? Coder handles all of that, so there's no need for it in a coder review, but I realise this information may be needed if these errors are also printed when using potx to extract a file.
Comment #12
stella commentedAlso, if we can, I'd remove the
Invalid marker content t($rule['#warning'])from the coder review messages. Coder already includes the snippet of code, so that's not really needed. "Invalid marker content" means nothing to me, but maybe it makes sense to leave it in, not sure.Comment #13
gábor hojtsyYay, great! We might be able to make the errors shorter with some text rework (some great modifications you have already done. We can omit the "invalid marker content" part and focus on more tailored concrete error messages. We can also do some refactoring here to not transfer file name and line number in the error message to coder, but only as meta info, which would lead to some refactoring of potx_status().
When used outside of coder module, we still need the file and line number for errors. When potx is used form the command line, we print errors to the command line, when potx is used under l10n_server, the l10n_server logs the errors in the database, when potx is used from the web interface, the errors are printed as drupal error messages. So there are at least three other options where we need the line number. This file name / line number refacoring could very well be part of http://drupal.org/node/309875 where this is sort of happening already although via reverse engineering the error message :)
Comment #14
stella commentedExcellent! Well I can help out with reviewing / testing of the updated #309875 patch whenever it's available.
Comment #15
gábor hojtsyOk, refactoring patch up on http://drupal.org/node/309875
Comment #16
stella commentedOk rerolled patch due to changes in #309875. There were 4 conflicts (hunks 2, 6, 7, 8), so there's no harm in reviewing those again more closely.
Cheers,
Stella
Comment #17
gábor hojtsyOk, more to the point messages in this patch. The generic "Invalid localization code" part is now removed. Also, for the JS checks, we could know if t or formatPlural is the culprit, so we can split and use the right error message instead of a long one. This also has better error message for _perm() hooks, using the hook implementation function name found instead of the generic error.
Let's get this tested and reviewed.
Comment #18
stella commentedI think we need to work on this slightly more. All of the error messages have the code snippet still attached. So when you run this in coder you get the snippet twice, for example:
However, the changes to the error messages themselves are much better and clearer. It also applies cleanly and works.
Comment #19
stella commentedCoder review of the patch throws up 2 styling issues. Neither of them are in the modified lines, but rather these styling issues were present in the original code:
Cheers,
Stella
Comment #20
gábor hojtsyYeah, well, my assumption with including the code snippet in the error is that there might be multiple t() calls on one line, eg:
and in this case, it might help to have the exact bogus call at hand, so you don't need to dig up the line. Granted, lines should be short and all, so we might as well skip the concrete error to another structured item in the array and not pass that to coder. What do you think?
Comment #21
stella commentedI still think it's useful to have in other situations, just not when using coder. So yeah, that sounds good.
Comment #22
gábor hojtsyOk, will try to find some time to work on this soon. I am making a note that http://drupal.org/node/194962 is open to add a developer page which we could point to for more explanation on "how to write translatable source code" in the coder error messages. That page is still to be written.
Comment #23
hass commentedsub
Comment #24
hass commentedPlease, add periods to sentences. An also often ignored and possibly unwritten rule...
Comment #25
stella commentedPeriods at the end of sentences might be a better rule to have in coder's internationalization checks rather than in potx's I think.
Comment #26
hass commentedWell, but I wrote the above as I saw missing periods in the above patch. So "patch needs work" is correct.
Comment #27
gábor hojtsyHass, periods are already at the end of all sentences in all messages produced by this patch. Just run the patch and you will see.
Comment #28
hass commentedThis is incorrect. Here is only one example from the patch (3 or 4 of this bugs are inside):
Wrong:
Correct:
Comment #29
gábor hojtsyHass, let me repeat: Just run the patch and you will see. We are adding up the token information at the end of the message. We could of course just add a placeholder in the message and and it in ': %error_found.', but stella already requested to remove this from the message, so we are heading to where you think this patch should have been already. The messages when running out of coder module will be slightly longer this way though.
Comment #30
hass commentedYou may be correct that there comes a period in the output, but then we may have a context sensitive bug. If the period of a sentence written inside t() is outside of t() we have a context sensitive bug. I haven't read all the above... only taken a look to the patch and this one seems to have context sensitive bugs. No need to run the patch to find such bugs :-).
Comment #31
gábor hojtsyAnyway, here is a new patch, which to coder's need introduces the concept of the code excerpt. The code excerpt is now rendered outside of the helpful error message, so complete sentences for helpful error messages are a given now. The location info may contain the excerpt now if available. There are four different combination possibilities for location information details, so all have their t() strings and compositions, and the information ends up at the end of the string in 3 of the four modes. The structured mode stores the excerpt info, but the coder code throws it away, since it does not need that.
@stella, what do you think of this one?
Ps. I did find some code style issues in the module otherwise as well. Let's clean them up after we improved the coder integration!
Comment #32
gábor hojtsyDoh, the patch.
Comment #33
stella commentedI've tested the patch both via the coder review and by extracting some strings at admin/build/translate/extract and it works well in both scenarios. I think this one is good to go! :)
Cheers,
Stella
Comment #34
gábor hojtsyOnce I fixed a glitch in line numbering and committed a follow up to http://drupal.org/node/309875 (see that issue), this looked great to me as well. :) Committed to 6.x-2.x.
Inspired by your above comments, I've also fixed coder errors on this branch: http://drupal.org/node/313789
Once we have docs page on best practices, we can expand on this by adding a read more link to the docs.
Comment #35
gábor hojtsyComment #36
stella commentedI'm not sure that line numbering patch for the coder module is correct. For example, if I run the coder internationalization, upgrade to D6 and potx reviews for the invite module, I get:
The line number for the result returned by the potx review is incorrect.
Cheers,
Stella
Comment #37
gábor hojtsyWell, I was checking the code excerpt, not the line number. The code excerpt was one off since it used the line number as an array index. So should coder get a $lineno which starts from 1, but its array for the source code lines should be indexed from 0?
Comment #38
gábor hojtsyWhat do you think Stella?
Comment #39
gábor hojtsyDouble checked this. I've added two artificial hook_menu() errors to l10n_client module and then looked for potx coder review and built in coder review output. Looks like coder and potx reporting errors on the same line. Coder says t() should not be in hook_menu(), while potx says it should be a literal string. Both errors reported on the same line. I consider this works right with the current code.
Screenshots attached.
Comment #40
stella commentedWhich version of coder are you using out of interest? I'm using the 2.x-dev version, maybe this is caused by a coder change. Will need to get Doug to check.
Comment #41
gábor hojtsySince 5.x is not maintained, moving back to fixed. If the lines happen to be an actual problem, we can open a separate issue to fix. I remember checking line numbers with the 7.x port with coder, and that worked right.