check_untranslated_cat {potools}R Documentation

Check for untranslated messages emitted by cat

Description

Diagnose the R messages in a package to discover the presence of messages emitted by cat() which haven't been translated (i.e., passed through gettext(), gettextf(), or ngettext()).

Usage

check_untranslated_cat(message_data)

Arguments

message_data

A data.table, or object convertible to one.

Details

The function cat is commonly used to emit messages to users (e.g., for a verbose mode), but it is not equipped for translation. Instead, messages must first be translated and then emitted. Any character literals found in the package's R code used in cat but not translated will be flagged by this function.

For flagged calls, a potential replacement is offered, built using gettext or gettextf (depending on whether one or more ... arguments are supplied to cat). For the gettextf case, the suggested template is always ⁠%s⁠ (string) since this works for all inputs; the author should tighten this to the appropriate sprintf() template marker as appropriate, for example if the author knows the input is an integer, use ⁠%d⁠ or ⁠%i⁠ instead of ⁠%s⁠.

NB: not all cat calls are included – in particular, no cat call specifying a non-default file are flagged, nor are any where the supplied sep is not a character literal (e.g., sep=x instead of sep="")

Value

A data.table with columns call, file, line_number, and replacement summarizing the results.

Author(s)

Michael Chirico

See Also

translate_package(), update_pkg_po()

Examples


pkg <- file.path(system.file(package = 'potools'), 'pkg')
# copy to a temporary location to be able to read/write/update below
tmp_pkg <- file.path(tempdir(), "pkg")
dir.create(tmp_pkg)
file.copy(pkg, dirname(tmp_pkg), recursive = TRUE)

# first, extract message data
message_data = get_message_data(tmp_pkg)

# now, diagnose the messages for any untranslated strings shown through cat()
check_untranslated_cat(message_data)

# cleanup
unlink(tmp_pkg, recursive = TRUE)
rm(pkg, tmp_pkg, message_data)

[Package potools version 0.2.4 Index]