views:

35

answers:

1

Hi, I am currently internationalizing my site using PHP and ran into this problem. Some string have multiple links in them so I would like to put the links in wrappers to make it easier for translators to translate (since I'm using gettext). For example:

The <a href="google.com">dog</a>, <a href="bing.com">cat</a>, and <a href="yahoo.com">mouse</a>

would become

The [[dog]], [[cat]], and [[mouse]]

As you can see, each word has a different link associated to it. Now I need some way to convert it back into links. I was initially using

preg_match()

but I was only dealing with one link. Any suggestions on how I would elegantly add each link to the respective word? And also, it should work if the words get mixed up too, for example, in some languages it might be

The [[cat]], [[dog]], and [[mouse]]

Thanks for your time!

A: 

Wrap _() in sprintf() and use positional placeholders.

timdev
Yea I already do that but then it'll be like: sprintf(_("%1\$s, %2\$s, and %3\$s"));which is not very descriptive
Axsuul