WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to localise this string (including html) ?

     echo "<div class='updated'><p>All options are restored successfully.</p></div>" ;

Is this correct?

     echo '<div class="updated"><p>' . __( 'All options are restored successfully.', 'mytextdomain' ) . '</p></div>';

And how to go about this one?

     <p><?php _e( 'On the <a href="' . get_admin_url() . 'import.php">Import</a> page, choose the previously created file and click the <strong>Upload file and import</strong> button.', 'mytextdomain' ); ?></p>
share|improve this question
If you want to return the string, use __(), if you want to echo, use _e(). So, _e() is exactly the same as echo __(). – Max Yudin Feb 12 '13 at 8:46
Had a mistake there, edited, so it's correct now? – drtanz Feb 12 '13 at 8:50
Yes, it is correct. A simple test with a real translation could have told you that. Somehow I don’t see you actual problem? – toscho Feb 12 '13 at 8:55
I know it works, I just wanted to confirm that it's the proper way to do it, and if there is a more elegant solution. – drtanz Feb 12 '13 at 9:13
@drtanz You asked 111(!!) questions so far. You should really know how to do an update of a question and that posting updates as comments in inappropriate. – kaiser Feb 12 '13 at 11:29
up vote 3 down vote accepted

Your example is correct, simply because it works. There are hundreds of ways to localize strings wich are displayed including html, all good and elegant in their own way.

I like to do this as follows:

printf( '<div class="updated">
    __( 'All options are restored successfully.', 'mytextdomain' )

You also could do this like:

$str = __( 'All options are restored successfully.', 'mytextdomain' );
echo "<div class='updated'><p>$str</p></div>";

The most important thing is to maintain readability I guess. There isn't a "correct" way to display localized strings in combination with html.

For your second one, I would use:

_e( sprintf( 'On the <a href="%1$s">Import</a> page, choose the previously created file and click the <strong>Upload file and import</strong> button.', get_admin_url() . 'import.php' ), 'mytextdomain' );

In this case, the URL doesn't have to be translated.

share|improve this answer
Thanks that makes sense, how would you go about the second example I put in the updated question? – drtanz Feb 12 '13 at 13:49
I updated my answer with my opinion on your second example. :-) – Mike Madern Feb 12 '13 at 14:11
Perfect, thanks! – drtanz Feb 15 '13 at 14:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.