The hook_help() API documentation page uses t() incorrectly.
Example:
Every web link, l(), or url() must be replaced with %something and put into the final t() call: $output .= 'A role defines a group of users that have certain privileges as defined in %permission.'; $output = t($output, array('%permission' => l(t('user permissions'), 'admin/user/permission')));
According to t()'s documentation, it should be used like this:
$output .= '<p>'. t('Go to the <a href="@contact-page">contact page</a>.', array('@contact-page' => url('contact'))) .'</p>';
Comments
Comment #1
betz commentedComment #2
todd nienkerk commentedTo be more specific, the
t()function shouldn't contain any HTML in its translatable string. The documentation forhook_help()displays<p>tags inside the strings for all versions (4.6, 4.7, 5.x, 6.x, 7.x).Comment #4
todd nienkerk commentedSeveral misuses of
t()appears in core itself. Check outhelp_help()in 6.x:Not sure how to handle reporting both a core and documentation error.
Comment #5
todd nienkerk commentedPer webchick on IRC, markup is allowed in
t()when the context of the markup is necessary to translate the text. I will open an issue to amend the documentation ont()to reflect this approach.Comment #6
keith.smith commentedRe: #4, are you sure that's the help_help() from Drupal 6?
Drupal 6's actual help_help() function says, as far as I know, says:
Now, the function you quote may be in Drupal 5. A concerted effort was made to move tags out of strings, except where they are necessary to provide context. If any tags like
<p>still exist in HEAD, then please file an issue. Older versions are string-frozen; patching these strings in other versions would break translations.Comment #7
dave reidWow....so I've been doing this all wrong. The documentation for t() itself is wrong as well:
Comment #8
keith.smith commented@Dave Reid: What's wrong with that example? It looks right to me. The paragraph tags are not in t(), and the
atags are, so it's clear what is a link and what's not.Comment #9
dave reidAh, I thought it was being discussed that
<a href="@contact-page">contact page</a>was the mis-use. Nevermind. :)Comment #10
todd nienkerk commented@keith.smith re: #6: It appears the API documentation for
help_help()has changed since I posted #4. (I think this is the case because the API has undergone some significant changes recently.)@Dave Reid: The use of
<a>elements was part of the confusion. The original documentation fort()(on d.o, not in the API) flatly denied the use of markup, yet it specifically said<a>elements should be included inside the translation string. Per #5 above, markup is allowed, so long as it's necessary for context.Comment #11
todd nienkerk commentedHere's the issue I said I'd file in #5 above: #362324: API: t() documentation flatly denies markup