How do you use gettext when you have a link to the translated text?

I am using gettext to translate my website.

It would be nice to have a link in a text translation, but I do not want to write html tags in gettext files, because these translations can be used elsewhere.

I could only create text for a website (with links) and text for all purposes.
I will need to support 2 versions .: - (

I could also write my own parser to embed links in the text, but that seems superfluous, and I'm afraid The Danger of Naïveté

For those who had the same problem, how did you deal with this?

+5
source share
4 answers

. <a> -tag . Please see %s this link %s for more information. % s , </a>.

, . , , ", ", . , , , , .

+3

- HTML ( bbCode, textile, markdown ..) . URL , ?

, URL- .

, .

+1

, :

printf( __( 'Please see %s this link %s for more information.', 'text-domain' ), '<a href="http://yolo.io" title="yolo">', '</a>' );
+1

: https://zargony.com/2008/01/24/links-in-gettext-translated-strings.

{curly brackets} . :

_("Please click {here} or {here}")

linkify, .

linkify(
    _("Please click {here} or {here}"),
    "</a>",
    "<a href='www.example1.com'>", 
    "<a href='www.example2.com'>"
)

Definition in PHP:

function linkify($string, $closingTag) {
    $arguments = func_get_args();
    return preg_replace_callback(
        '/{(.*?)}/', // Ungreedy (*?)
        function($matches) use ($arguments, $closingTag) {
            static $i = 1; 
            $i++;
            return $arguments[$i] . $matches[1] . $closingTag;
        },
        $string
    );
}

PS: You can also easily replace {} for [], as I noticed that in curly brackets in POEdit they give warnings to translators and recommend not translating them.

+1
source

All Articles