get_message_data {potools} | R Documentation |
Extract user-visible messages from a package
Description
This function looks in the R and src directories of a package for
user-visible messages and compiles them as a
data.table::data.table()
to facilitate
analyzing this corpus as such.
Usage
get_message_data(
dir = ".",
custom_translation_functions = list(R = NULL, src = NULL),
style = NULL,
verbose = !is_testing()
)
Arguments
dir |
Character, default the present directory; a directory in which an R package is stored. |
custom_translation_functions |
A See Details in |
style |
Translation style, either Both styles extract strings explicitly flagged for translation with
|
verbose |
Logical, default |
Value
A data.table
with the following schema:
-
message_source
:character
, either"R"
or"src"
, saying whether the string was found in the R or the src folder of the package -
type
:character
, either"singular"
or"plural"
;"plural"
means the string came fromngettext()
and can be pluralized -
file
:character
, the file where the string was found -
msgid
:character
, the string (character literal orchar
array as found in the source); missing for alltype == "plural"
strings -
msgid_plural
:list(character, character)
, the strings (character literals orchar
arrays as found in the source); the first applies in English forn=1
(seengettext
), while the second applies forn!=1
; missing for alltype == "singular"
strings -
call
:character
, the full call containing the string that was found -
line_number
:integer
, the line infile
where the string was found -
is_repeat
:logical
, whether themsgid
is a duplicate within thismessage_source
-
is_marked_for_translation
:logical
, whether the string is marked for translation (e.g., in R, all character literals supplied to a...
argument instop()
are so marked) -
is_templated
,logical
, whether the string is templatable (e.g., uses%s
or other formatting markers)
Author(s)
Michael Chirico
See Also
translate_package()
,
write_po_file()
Examples
pkg <- system.file('pkg', package = 'potools')
get_message_data(pkg)
# includes strings provided to the custom R wrapper function catf()
get_message_data(pkg, custom_translation_functions = list(R = "catf:fmt|1"))
# includes untranslated strings provided to the custom
# C/C++ wrapper function ReverseTemplateMessage()
get_message_data(
pkg,
custom_translation_functions = list(src = "ReverseTemplateMessage:2")
)
# cleanup
rm(pkg)