Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Tracker and Action module calling t() or format_plural() inside watchdog() function call, but this is not necessary since watchog() process translation strings internally.
First I found bug in tracker and after that I create this regex: /watchdog\([^,]+, ?(t\(|format_plural\()/
and found one more bug in Action module.
Comment | File | Size | Author |
---|---|---|---|
d7_watchdog_action_tracker.patch | 1.46 KB | wojtha | |
Comments
Comment #1
meba CreditAttribution: meba commentedSounds fine to me
Comment #2
wojtha CreditAttribution: wojtha commentedThe bug in action.inc affects also D6 branch (Drupal 6.19, action.inc:358).
Comment #3
Dries CreditAttribution: Dries commentedI don't understand the format_plural() change. AFAIK, watchdog() doesn't call format_plural(). In other words, this is likely to introduce a regression for translators.
Comment #4
webchickComment #5
tstoecklerI couldn't find where it says that, otherwise I would have posted a link, but we currently don't support format_plural() in watchdog(). You send a plain old string (with replacement variables) to watchdog(). Period.
Comment #6
meba CreditAttribution: meba commentedYes, calls to watchdog shouldn't include t(), because they are translated on display. And since format_plural automatically calls t(), we shouldn't format_plural in watchdog.
Comment #7
wojtha CreditAttribution: wojtha commented@Dries
I though that using t() or format_plural() in watchdog is not necessary in general and it is not good practice.
If you are not against using format_plural() in watchdog(), there are some places in Drupal core which should use format_plural for watchdog() but don't. This was the only usage of format_plural inside watchdog call in whole core and maybe also in all Drupal contribs (as I tested also Drupal 6 with around 100 most used modules installed).
Comment #8
wojtha CreditAttribution: wojtha commentedChanged status accidentally.
@meba, @tstoeckler: Yes, I think too. Format plural is not supported in watchdog. And I don't think it will be useful at all. It is "only" logging tool, not something which appears on a frontpage or on a node edit form.
Comment #9
Dries CreditAttribution: Dries commentedThanks for the follow-up comments. That helped me realize I was mistaken. Committed to CVS HEAD.
Comment #10
Eric_A CreditAttribution: Eric_A commentedThe real issue with the first watchdog() call was that it was passed both a translated string *and* an array of replacement variables instead of NULL. It worked because format_plural wasn't passed $args.
The real fix should have been to move the replacement variables to the format_plural() $args and that watchdog should have been passed NULL for $variables.
This would have prevented the regression for translators from RC1.
I cannot bring myself to change the issue status but really, this should have been discussed even if most of us don't care about a watchdog string (freeze) and even if it is a very, very good idea to stay away from format_plural() for watchdog strings.
Comment #11
wojtha CreditAttribution: wojtha commented@Erik_A no, the real issue is what meba describes in #6: Watchdog strings are (and have to be) translated when they are going to be displayed.
If you store translated string (with tokens replaced with real values - which is what both t() and format_plural() do) in the db, you can't translate it than to the appropriate language when the watchdog message is going to be displayed to the user...
Comment #12
Eric_A CreditAttribution: Eric_A commented@#11, Yes, of course, that, too.
So in order to fix the translating bug without a regression for translators is to check $count, set the message that goes with $count and do a watchdog(). Of course this is very ugly and is not the recommended pattern, but my point is that after string freeze ugly fixes need to be discussed. I'll see if I can come with a patch for discussions sake.
Comment #13
Eric_A CreditAttribution: Eric_A commentedWhile doing that tiny patch I realized that no strings were changed or added (that is, for the one watchdog() call discussed now). One was removed.
Which makes all the difference in the world, here. Sorry! Carry on, please...