views:

95

answers:

1

My current implementation, which is array based stores keys and values in a dictionary, example:

$arr = array(
    'message' => 'Paste a <a href="http://flickr.com/"&gt;flickr&lt;/a&gt; URL below.',
);

I realize that it was probably a bad idea storing html inside of a string such as this, but if I'm using gettext then in my .mo/.po files how should I handle storing a similar string? Should I just store words, such as 'Paste a' and 'URL below' and 'flickr' separately?

+2  A: 

You should store something like

"Paste a %1 URL below"

and replace all 'vars' using something simple like str_replace('%1', $link, $message);

$link can also be translatable

"<a href="http://flickr.com/"&gt;%1&lt;/a&gt;"

although that might be overkill (does flickr translate between languages?)

rationale behind this is that different languages have different grammatical structures and the ordering of the words wont always be the same.

Janek
`sprintf()` is made for these circumstances.
chelmertz