Localizing a string with html tag with word inside that tag

I have translated many string successfully previously, but this one gives me a headache. This part is used inside my content-related.php file which I use to display related posts

Here is the current string I’m using

<?php echo 'Click <a href="'. esc_url( get_permalink() ) . '">here</a> to go and wacth the video.' ?>

My problem in the localization process is the

<a href="'. esc_url( get_permalink() ) . '">here</a>

part in the middle.

The best I could come up with is

<?php printf(__('Click %s to go and wacth the video.', 'pietergoosen'), '<a href="'. esc_url( get_permalink() ) . '">here</a>'); ?>

OK, I know I can just create a variable for the <a> tag and rather use the variable in the printf() string instead of the whole <a> tag, but that is not the concern now, and that was only done to test the result first.

With the string in its changed order, the string translates, except for the word “here” which is inside the <a> tag. How can I get the string to translate the word “here” as well. I’ve read somewhere, think it was in the Codex, that it is not a good idea breaking up a string into several strings as it may cause problems for certain languages as word order differ in some languages.

Any more suggestions to solve this problem?

4 Answers
4

Possible solution to get everything translatable as one sting.

<?php printf(__('Click <a href="https://wordpress.stackexchange.com/questions/135866/%s">Here</a> to go and wacth the video.', 'pietergoosen'), esc_url( get_permalink() )); ?>

It is usually safe to assume that the translator have enough knowledge of HTML to understand what is going on there.

Leave a Comment