EVOLUTION-MANAGER
Edit File: gettext.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Translate Text Messages</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for gettext {base}"><tr><td>gettext {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Translate Text Messages</h2> <h3>Description</h3> <p>If Native Language Support was enabled in this build of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>, attempt to translate character vectors or set where the translations are to be found. </p> <h3>Usage</h3> <pre> gettext(..., domain = NULL) ngettext(n, msg1, msg2, domain = NULL) bindtextdomain(domain, dirname = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>One or more character vectors.</p> </td></tr> <tr valign="top"><td><code>domain</code></td> <td> <p>The ‘domain’ for the translation.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>a non-negative integer.</p> </td></tr> <tr valign="top"><td><code>msg1</code></td> <td> <p>the message to be used in English for <code>n = 1</code>.</p> </td></tr> <tr valign="top"><td><code>msg2</code></td> <td> <p>the message to be used in English for <code>n = 0, 2, 3, ...</code>.</p> </td></tr> <tr valign="top"><td><code>dirname</code></td> <td> <p>The directory in which to find translated message catalogs for the domain.</p> </td></tr> </table> <h3>Details</h3> <p>If <code>domain</code> is <code>NULL</code> or <code>""</code>, and <code>gettext</code> or <code>ngettext</code> is called from a function in the namespace of package <span class="pkg">pkg</span> the domain is set to <code>"R-pkg"</code>. Otherwise there is no default domain. </p> <p>If a suitable domain is found, each character string is offered for translation, and replaced by its translation into the current language if one is found. The value (logical) <code>NA</code> suppresses any translation. </p> <p>Conventionally the domain for <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> warning/error messages in package <span class="pkg">pkg</span> is <code>"R-pkg"</code>, and that for C-level messages is <code>"pkg"</code>. </p> <p>For <code>gettext</code>, leading and trailing whitespace is ignored when looking for the translation. </p> <p><code>ngettext</code> is used where the message needs to vary by a single integer. Translating such messages is subject to very specific rules for different languages: see the GNU Gettext Manual. The string will often contain a single instance of <code>%d</code> to be used in <code><a href="sprintf.html">sprintf</a></code>. If English is used, <code>msg1</code> is returned if <code>n == 1</code> and <code>msg2</code> in all other cases. </p> <p><code>bindtextdomain</code> is a wrapper for the C function of the same name: your system may have a <code>man</code> page for it. With a non-<code>NULL</code> <code>dirname</code> it specifies where to look for message catalogues: with <code>domain = NULL</code> it returns the current location. </p> <h3>Value</h3> <p>For <code>gettext</code>, a character vector, one element per string in <code>...</code>. If translation is not enabled or no domain is found or no translation is found in that domain, the original strings are returned. </p> <p>For <code>ngettext</code>, a character string. </p> <p>For <code>bindtextdomain</code>, a character string giving the current base directory, or <code>NULL</code> if setting it failed. </p> <h3>See Also</h3> <p><code><a href="stop.html">stop</a></code> and <code><a href="warning.html">warning</a></code> make use of <code>gettext</code> to translate messages. </p> <p><code><a href="../../tools/html/xgettext.html">xgettext</a></code> for extracting translatable strings from <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> source files. </p> <h3>Examples</h3> <pre> bindtextdomain("R") # non-null if and only if NLS is enabled for(n in 0:3) print(sprintf(ngettext(n, "%d variable has missing values", "%d variables have missing values"), n)) ## Not run: ## for translation, those strings should appear in R-pkg.pot as msgid "%d variable has missing values" msgid_plural "%d variables have missing values" msgstr[0] "" msgstr[1] "" ## End(Not run) miss <- c("one", "or", "another") cat(ngettext(length(miss), "variable", "variables"), paste(sQuote(miss), collapse = ", "), ngettext(length(miss), "contains", "contain"), "missing values\n") ## better for translators would be to use cat(sprintf(ngettext(length(miss), "variable %s contains missing values\n", "variables %s contain missing values\n"), paste(sQuote(miss), collapse = ", "))) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>