Description Usage Arguments Details Value See Also Examples
If Native Language Support was enabled in this build of R, attempt to translate character vectors or set where the translations are to be found.
1 2 3 4 5 |
... |
One or more character vectors. |
domain |
The ‘domain’ for the translation. |
n |
a non-negative integer. |
msg1 |
the message to be used in English for |
msg2 |
the message to be used in English for |
dirname |
The directory in which to find translated message catalogs for the domain. |
If domain
is NULL
or ""
, and gettext
is
called from a function in the namespace of package pkg the
domain is set to "R-pkg"
. Otherwise there is no default
domain.
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) NA
suppresses any
translation.
Conventionally the domain for R warning/error messages in package
pkg is "R-pkg"
, and that for C-level messages is "pkg"
.
For gettext
, leading and trailing whitespace is ignored when
looking for the translation.
ngettext
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 %d
to be used in
sprintf
. If English is used, msg1
is returned if
n == 1
and msg2
in all other cases.
bindtextdomain
is a wrapper for the C function of the same
name: your system may have a man
page for it. With a
non-NULL
dirname
it specifies where to look for message
catalogues: with domain = NULL
it returns the current location.
For gettext
, a character vector, one element per string in
...
. If translation is not enabled or no domain is found or
no translation is found in that domain, the original strings are
returned.
For ngettext
, a character string.
For bindtextdomain
, a character string giving the current base
directory, or NULL
if setting it failed.
stop
and warning
make use of gettext
to
translate messages.
xgettext
for extracting translatable strings from R
source files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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 = ", ")))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.