Active
Project:
Coder Tough Love
Version:
6.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Aug 2010 at 07:24 UTC
Updated:
28 Jan 2012 at 02:23 UTC
http://api.drupal.org/api/function/t says: "HTML markup within translation strings is allowed, but should be avoided if possible. The exception are embedded links; link titles add a context for translators, so should be kept in the main string."
But using the code form the example:
$output = t('Go to the <a href="@contact-page">contact page</a>.', array('@contact-page' => url('contact')));
Returns in this error:
Line 20: Use the matching Drupal theme functions, not raw HTML.
$output = t('Go to the <a href="@contact-page">contact page</a>.', array('@contact-page' => url('contact')));
Cheers
Comments
Comment #1
morbus iffThe answer for this one is: it depends. Some people prefer the above. Some people prefer:
You'd be fine if you labeled it a false positive and moved on.
Comment #2
morbus iffComment #3
bartezz commentedWell erm... if this module is about applying finely aged and obsessively anal wisdom from years of Drupal development and persnickety quality control and thus sticking to the docs then it's not about what people prefer IMHO but about what's in the docs... :)
http://api.drupal.org/api/function/t
Not trying to be a smartass but just giving ya some tough love :p
Cheers
Comment #4
morbus iffI won't be fixing this; it's too infrequent for my tastes and slightly prohibitive (turning a simple regexp comparison into a full-blown callback that can know when embedded links are used within a t(), and yelling at anything else). To throw the same documentation in your face as you did to me: "You should expect some false positives with Coder Tough Love, but I'd still want you to report them as bugs so I can continue to tighten the analysis." You've done so, thanks. My prerogative here is to /keep/ it as a known false positive, one that I've known of for quite some time.
Thanks for the report.
Comment #5
morbus iffHrm. Should be plausible by moving A into its own regexp with a "t(" lookahead.
Comment #6
bartezz commentedCool! Though throwing docs into faces sounds a bit harsh... like i said, showing you some tough love :)
I wish I could help ya by supplying a patch, yet regular expressions aren't my thing.
Somehow can't get my head around those...
Cheers
Comment #7
danepowell commentedAlso seeing this false positive. I know it seems like a trivial point, but if that's what's in the docs then I think Coder Tough Love should abide by it... that's kind of the whole point, right? ;)
Comment #8
hass commentedCode style in #1 is not allowed per drupal code style rules. The reason is that the link name cannot translated context sensitive. It's not people personal preference it's an i18n bug.
The complaining rule is incorrect and need to be fixed. Also have this issue, see #1390036: Use the matching Drupal theme functions, not raw HTML.
Comment #9
hass commentedLike #1390592: D7: statements should probably be wrapped in db_rewrite_sql() this issue also requires to know that D7+ is tested. We have the context sensitive translation strings since D7 and the current rule is for D6 and may only acceptable for D6, however bad it is.
Comment #10
hass commentedStill the most false detections in review on d.o.
Comment #11
xjmComment #12
hefox commentedRan coder_tough_love.module through coder review, and this issue is preventing it from passing coder tough love's review (*teehee*).
Comment #13
bartezz commentedHehehe!
Comment #14
Jorrit commented#1 is not going to work as
@contact-pagewill escape the HTML tag generated byl(). If the @ is replaced by an !, the "Potential problem: form_set_error() and form_error() only accept filtered text..." or "Potential problem: drupal_set_message() only accepts filtered text" error may be triggered when using these functions.Comment #15
hass commented@jorrit: the string in #1 is not correct and can be seen as a bug, not only because of "!". Using l() is a bug.