'You can now <a href="abc/def/ghi">change the settings</a>.'

the string should be properly translated, including "change the setting":

"You can now change the settings."

This version is no good:

t('You can now !link.', array('!link' => '<a href="abc/def/ghi">change the settings</a>');

because the string "change the settings" must to be translatable.

Or this:

t('You can now !open_tagchange the settings!close_tag', array('!open_tag' => '<a href="abc/def/ghi">', '!close_tag' => '</a>');

This is no good either because the translatable string is very confusing.

How do you do this?

Comments

webkenny’s picture

Unless I am misunderstanding, your best option is to use the l() function and a t() function with concatenation. Like this:

print t('You can now') . l('Change the settings', 'path/to/settings);

Kenny S.
Follow me on Twitter

dww’s picture

A few problems with this:

print t('You can now') . l('Change the settings', 'path/to/settings);

a) you need l(t('Change the settings'), 'path/to/settings') to make 'Change the settings' translatable, even if you use l().

b) In a language that reads right to left ("RTL"), for example Arabic, this makes it impossible to translate correctly since you're forcing "you can now" to come to the left of "change the settings". You need the whole sentence in a single t() call to allow RTL languages to translate it.

So, you need the solution I provided in my other comment:

t('You can now <a href="@settings-url">change the settings</a>.', array('@settings-url' => url('path/to/settings')));

___________________
3281d Consulting

dww’s picture

http://api.drupal.org/api/function/t/6

Here is an example of t() used correctly:

$output .= '<p>'. t('Go to the <a href="@contact-page">contact page</a>.', array('@contact-page' => url('contact'))) .'</p>';

___________________
3281d Consulting

mattyoung’s picture

The t() string:

'Go to the <a href="@contact-page">contact page</a>.'

will confuse my translator friend. They don't know HTML at all. So I will just edit the text to take out the HTML tags, send to translate. Then put the tags back.

Thank you very much.

dww’s picture

Core does it this way, so if you just try to hide this problem from your translator friend, it's just masking the problem. Instead, consider teaching your friend how to translate strings like this.

Alternatively, if you really must, you should do it like this:

t('You can now !change-settings.', array('!change-settings' => l(t('change the settings'), 'path/to/settings')));

but that's more clumsy for RTL languages, and it makes for shorter strings with less context to translate them...

___________________
3281d Consulting

webkenny’s picture

Thanks for the replies to my comment. Now I have a better understanding myself! I do love this community.

Kenny S.
Follow me on Twitter