<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Lookup a message in the current domain</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.dngettext.html">dngettext</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ngettext.html">ngettext</a></div> <div class="up"><a href="ref.gettext.html">Gettext Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.gettext" class="refentry"> <div class="refnamediv"> <h1 class="refname">gettext</h1> <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">gettext</span> — <span class="dc-title">Lookup a message in the current domain</span></p> </div> <div class="refsect1 description" id="refsect1-function.gettext-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>gettext</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$message</code></span> )</div> <p class="para rdfs-comment"> Looks up a message in the current domain. </p> </div> <div class="refsect1 parameters" id="refsect1-function.gettext-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">message</code></dt> <dd> <p class="para"> The message being translated. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.gettext-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a translated <span class="type"><a href="language.types.string.html" class="type string">string</a></span> if one is found in the translation table, or the submitted message if not found. </p> </div> <div class="refsect1 examples" id="refsect1-function.gettext-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2975"> <p><strong>Example #1 <span class="function"><strong>gettext()</strong></span>-check</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Set language to German<br /></span><span style="color: #0000BB">putenv</span><span style="color: #007700">(</span><span style="color: #DD0000">'LC_ALL=de_DE'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">, </span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Specify location of translation tables<br /></span><span style="color: #0000BB">bindtextdomain</span><span style="color: #007700">(</span><span style="color: #DD0000">"myPHPApp"</span><span style="color: #007700">, </span><span style="color: #DD0000">"./locale"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Choose domain<br /></span><span style="color: #0000BB">textdomain</span><span style="color: #007700">(</span><span style="color: #DD0000">"myPHPApp"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Translation is looking for in ./locale/de_DE/LC_MESSAGES/myPHPApp.mo now<br /><br />// Print a test message<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">gettext</span><span style="color: #007700">(</span><span style="color: #DD0000">"Welcome to My PHP Application"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Or use the alias _() for gettext()<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">_</span><span style="color: #007700">(</span><span style="color: #DD0000">"Have a nice day"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.gettext-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> You may use the underscore character '_' as an alias to this function. </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Setting a language isn't enough for some systems and the <span class="function"><a href="function.putenv.html" class="function">putenv()</a></span> should be used to define the current locale. </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.gettext-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.setlocale.html" class="function" rel="rdfs-seeAlso">setlocale()</a> - Set locale information</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.dngettext.html">dngettext</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ngettext.html">ngettext</a></div> <div class="up"><a href="ref.gettext.html">Gettext Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>