I have the following code in part html/php:

ITEM1:

Select this link for the  <a href="<?php echo $url; ?>about">about page</a>

Then I have this gettext example using sprintf:

ITEM2:

<?=sprintf(gettext("Your browser says you prefer the %s language."), $_SERVER["HTTP_ACCEPT_LANGUAGE"])?>

I have been trying for the past two hours how to incorporate ITEM1 into ITEM2?

Any help help on this would be great?

    gettext() is not a core php function so what does it do? and when you say incorporate, what do you expect the outcome to be

      I am using the php built in function php-gettext, what I mean is the correct syntax so that poedit interprets the translation and the output for a link is correct on the page

        You would want sprintf to go first, and then put the result from that through gettext:

        <?=gettext(sprintf('Some string with %s string','another'))?>

        Edit: Never-mind I see what your asking, I think you'll need to do the part outside the link separate from the link text.

        <?=_('Select this link for the').' <a href="'. $url .'about">'._('about us').'</a>'?>

        Edit also: for dagon http://us.php.net/manual/en/function.gettext.php

          It may be better to use sprintf here...

          // Translator's note: &#37;s will be replaced with a link to the "About Us" page
          sprintf(_('Select this link for the %s page.'), "<a href=\"$url\">" . _('about us') . "</a>");
          

            Cause you don't have it installed:

            To use these functions you must download and install the GNU gettext package from &#187; http://www.gnu.org/software/gettext/gettext.html

            To include GNU gettext support in your PHP build you must add the option --with-gettext[=DIR] where DIR is the gettext install directory, defaults to /usr/local.

            Shared is also an option, --with-gettext=shared then extension=gettext.so(dll) must also be in the php.ini

              Weedpacket;11003273 wrote:

              It may be better to use sprintf here...

              // Translator's note: %s will be replaced with a link to the "About Us" page
              sprintf(_('Select this link for the %s page.'), "<a href=\"$url\">" . _('about us') . "</a>");
              

              This option does not produce and output for some reason?

              EDIT: Never mind, all fixed and thanks for your help on this one guys 🙂 😉

                Write a Reply...