man-pages/man3/Locale::gettext.3pm.html
2021-03-31 01:06:50 +01:00

201 lines
6.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of gettext</TITLE>
</HEAD><BODY>
<H1>gettext</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-10-27<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Locale::gettext - message handling functions
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use Locale::gettext;
use POSIX; # Needed for setlocale()
setlocale(LC_MESSAGES, &quot;&quot;);
# OO interface
my $d = Locale::gettext-&gt;domain(&quot;my_program&quot;);
print $d-&gt;get(&quot;Welcome to my program&quot;), &quot;\n&quot;;
# (printed in the local language)
# Direct access to C functions
textdomain(&quot;my_program&quot;);
print gettext(&quot;Welcome to my program&quot;), &quot;\n&quot;;
# (printed in the local language)
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The gettext module permits access from perl to the <B>gettext()</B> family of
functions for retrieving message strings from databases constructed
to internationalize software.
<DL COMPACT>
<DT id="1">$d = Locale::gettext-&gt;domain(<FONT SIZE="-1">DOMAIN</FONT>)<DD>
<DT id="2">$d = Locale::gettext-&gt;domain_raw(<FONT SIZE="-1">DOMAIN</FONT>)<DD>
Creates a new object for retrieving strings in the domain <B></B><FONT SIZE="-1"><B>DOMAIN</B></FONT><B></B>
and returns it. <TT>&quot;domain&quot;</TT> requests that strings be returned as
Perl strings (possibly with wide characters) if possible while
<TT>&quot;domain_raw&quot;</TT> requests that octet strings directly from functions
like <TT>&quot;dgettext()&quot;</TT>.
<DT id="3">$d-&gt;get(<FONT SIZE="-1">MSGID</FONT>)<DD>
Calls <TT>&quot;dgettext()&quot;</TT> to return the translated string for the given
<B></B><FONT SIZE="-1"><B>MSGID</B></FONT><B></B>.
<DT id="4">$d-&gt;cget(<FONT SIZE="-1">MSGID, CATEGORY</FONT>)<DD>
Calls <TT>&quot;dcgettext()&quot;</TT> to return the translated string for the given
<B></B><FONT SIZE="-1"><B>MSGID</B></FONT><B></B> in the given <B></B><FONT SIZE="-1"><B>CATEGORY</B></FONT><B></B>.
<DT id="5">$d-&gt;nget(<FONT SIZE="-1">MSGID, MSGID_PLURAL, N</FONT>)<DD>
Calls <TT>&quot;dngettext()&quot;</TT> to return the translated string for the given
<B></B><FONT SIZE="-1"><B>MSGID</B></FONT><B></B> or <B></B><FONT SIZE="-1"><B>MSGID_PLURAL</B></FONT><B></B> depending on <B>N</B>.
<DT id="6">$d-&gt;ncget(<FONT SIZE="-1">MSGID, MSGID_PLURAL, N, CATEGORY</FONT>)<DD>
Calls <TT>&quot;dngettext()&quot;</TT> to return the translated string for the given
<B></B><FONT SIZE="-1"><B>MSGID</B></FONT><B></B> or <B></B><FONT SIZE="-1"><B>MSGID_PLURAL</B></FONT><B></B> depending on <B>N</B> in the given
<B></B><FONT SIZE="-1"><B>CATEGORY</B></FONT><B></B>.
<DT id="7">$d-&gt;dir([<FONT SIZE="-1">NEWDIR</FONT>])<DD>
If <B></B><FONT SIZE="-1"><B>NEWDIR</B></FONT><B></B> is given, calls <TT>&quot;bindtextdomain&quot;</TT> to set the
name of the directory where messages for the domain
represented by <TT>$d</TT> are found. Returns the (possibly changed)
current directory name.
<DT id="8">$d-&gt;codeset([<FONT SIZE="-1">NEWCODE</FONT>])<DD>
For instances created with <TT>&quot;Locale::gettext-&gt;domain_raw&quot;</TT>, manuiplates
the character set of the returned strings.
If <B></B><FONT SIZE="-1"><B>NEWCODE</B></FONT><B></B> is given, calls <TT>&quot;bind_textdomain_codeset&quot;</TT> to set the
character encoding in which messages for the domain
represented by <TT>$d</TT> are returned. Returns the (possibly changed)
current encoding name.
</DL>
<P>
<B>gettext()</B>, <B>dgettext()</B>, and <B>dcgettext()</B> attempt to retrieve a string
matching their <TT>&quot;msgid&quot;</TT> parameter within the context of the current
locale. <B>dcgettext()</B> takes the message's category and the text domain
as parameters while <B>dgettext()</B> defaults to the <FONT SIZE="-1">LC_MESSAGES</FONT> category
and <B>gettext()</B> defaults to <FONT SIZE="-1">LC_MESSAGES</FONT> and uses the current text domain.
If the string is not found in the database, then <TT>&quot;msgid&quot;</TT> is returned.
<P>
<B>ngettext()</B>, <B>dngettext()</B>, and <B>dcngettext()</B> function similarily but
implement differentiation of messages between singular and plural.
See the documentation for the corresponding C functions for details.
<P>
<B>textdomain()</B> sets the current text domain and returns the previously
active domain.
<P>
<I>bindtextdomain(domain, dirname)</I> instructs the retrieval functions to look
for the databases belonging to domain <TT>&quot;domain&quot;</TT> in the directory
<TT>&quot;dirname&quot;</TT>
<P>
<I>bind_textdomain_codeset(domain, codeset)</I> instructs the retrieval
functions to translate the returned messages to the character encoding
given by <B>codeset</B> if the encoding of the message catalog is known.
<A NAME="lbAE">&nbsp;</A>
<H2>NOTES</H2>
Not all platforms provide all of the functions. Functions that are
not available in the underlying C library will not be available in
Perl either.
<P>
Perl programs should use the object interface. In addition to being
able to return native Perl wide character strings,
<TT>&quot;bind_textdomain_codeset&quot;</TT> will be emulated if the C library does
not provide it.
<A NAME="lbAF">&nbsp;</A>
<H2>VERSION</H2>
1.07.
<A NAME="lbAG">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3i+gettext">gettext</A></B>(3i), <B><A HREF="/cgi-bin/man/man2html?1+gettext">gettext</A></B>(1), <B><A HREF="/cgi-bin/man/man2html?1+msgfmt">msgfmt</A></B>(1)
<A NAME="lbAH">&nbsp;</A>
<H2>AUTHOR</H2>
Kim Vandry &lt;<A HREF="mailto:vandry@TZoNE.ORG">vandry@TZoNE.ORG</A>&gt;
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="9"><A HREF="#lbAB">NAME</A><DD>
<DT id="10"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="11"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="12"><A HREF="#lbAE">NOTES</A><DD>
<DT id="13"><A HREF="#lbAF">VERSION</A><DD>
<DT id="14"><A HREF="#lbAG">SEE ALSO</A><DD>
<DT id="15"><A HREF="#lbAH">AUTHOR</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:47 GMT, March 31, 2021
</BODY>
</HTML>