xgettext | R Documentation |
For each file in the ‘R’ directory (including system-specific subdirectories) of a package, extract the unique arguments passed to these “message generating” calls;
xgettext()
:to stop
, warning
, message
,
packageStartupMessage
, gettext
and
gettextf
,
xngettext()
:to ngettext
.
xgettext2pot()
calls both xgettext()
and then xngettext()
.
xgettext(dir, verbose = FALSE, asCall = TRUE) xngettext(dir, verbose = FALSE) xgettext2pot(dir, potFile, name = "R", version, bugs)
dir |
the directory of a source package, i.e., with a ‘./R’ sub directory. |
verbose |
logical: should each file be listed as it is processed? |
asCall |
logical: if |
potFile |
name of |
name, version, bugs |
as recorded in the template file:
|
Leading and trailing white space (space, tab and linefeed
(aka newline, i.e., \n
)) is removed
for all the calls extracted by xgettext()
, see
‘Description’ above,
as it is by the internal code that passes strings for translation.
We look to see if the matched functions were called with
domain = NA
. If so, when asCall
is true, the whole call
is omitted. Note that a call might contain a nested call
to gettext
(or warning
, etc.) whose strings would be visible
if asCall
is false.
xgettext2pot
calls xgettext
and then xngettext
,
and writes a PO template file (to potFile
) for use with the GNU Gettext
tools. This ensures that the strings for simple translation are
unique in the file (as GNU Gettext requires), but does not do so
for ngettext
calls (and the rules are not stated in the Gettext
manual, but msgfmt
complains if there is duplication between
the sets.).
If applied to the base package, this also looks in the ‘.R’ files in ‘R_HOME/share/R’.
For xgettext
, a list of objects of class "xgettext"
(which has a print
method), one per source file that
contains potentially translatable strings.
For xngettext
, a list of objects of class "xngettext"
,
which are themselves lists of length-2 character vectors.
update_pkg_po()
which calls xgettext2pot()
.
## Not run: ## in a source-directory build of R: xgettext(file.path(R.home(), "src", "library", "splines")) ## End(Not run) ## Create source package-like <tmp>/R/foo.R and get text from it: tmpPkg <- tempdir() tmpRDir <- file.path(tmpPkg, "R") dir.create(tmpRDir, showWarnings = FALSE) fnChar <- paste(sep = "\n", "foo <- function(x) {", " if (x < -1) stop('too small')", " # messages unduplicated (not so for ngettext)", " if (x < -.5) stop('too small')", " if (x < 0) {", " warning(", " 'sqrt(x) is', sqrt(as.complex(x)),", " ', which may be too small'", " )", " }", " # calls with domain=NA are skipped", " if (x == 0) cat(gettext('x is 0!\n', domain=NA))", " # gettext strings may be ignored due to 'outer' domain=NA", " if (x > 10) stop('x is ', gettextf('%.2f', x), domain=NA)", " x", "}") writeLines(fnChar, con = file.path(tmpRDir, "foo.R")) ## [[1]] : suppressing (tmpfile) name to make example Rdiff-able xgettext(tmpPkg, asCall=TRUE )[[1]] # default; shows ' sqrt(as.complex(x)) ' xgettext(tmpPkg, asCall=FALSE)[[1]] # doesn't ; but then ' %.2f ' unlink(tmpRDir, recursive=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.