loading...

Translate a message given a set of known messages and regex patterns

translate(
  msg,
  dictionary,
  domain = "R-svAssert",
  trim = TRUE,
  format = TRUE,
  ...
)

format_inline_(
  ...,
  .envir = parent.frame(),
  collapse = TRUE,
  keep_whitespace = TRUE,
  post_translate = TRUE
)

create_messages_script(
  dictionary,
  topic,
  pkg_dir = ".",
  export = TRUE,
  source = NULL,
  release = NULL
)

Arguments

msg

The message to be translated

dictionary

A character vector with messages to translate and regular expressions to find the corresponding error strings as names.

domain

The domain where to look for messages (see gettext()). The default looks in "R-svAssert", and it should be changed for translations that are available in another package.

trim

Logical, indicating whether leading and trailing whitespace before looking for message translation. TRUE by default.

format

Logical, indicating whether to format the translated message with format_inline_(). Default is TRUE.

...

Messages passed to format_inline().

.envir

The environment in which to evaluate expressions in ....

collapse

Logical, indicating whether to collapse multiple lines into a single string with newlines.

keep_whitespace

Logical, indicating whether to keep whitespace in the formatted message.

post_translate

Logical, indicating whether to translate ", and " and ", or " in the final message.

topic

The identifier for a dictionary. Usually, it should be the name of the package that generates the messages, but it is not mandatory. Use "general" for a set with no particular topic.

pkg_dir

The root directory of the sources of an R package. The produced messages-topic.R script file is created in the R/ subdirectory.

export

Logical, indicating whether the created object should be exported. Default is TRUE.

source

An optional URL indicating where the messages come from, e.g., a GitHub repository.

release

An optional string indicating the release version of the source where the messages were extracted from.

Value

For translate() the translated message if a correspondence is found in the dictionary and a translation is known, or the original message otherwise.

For format_inline_() a formatted message as a string. If an error occurs during formatting, a warning is issued and a simple concatenation of the arguments is returned instead.

For create_messages_script() the name of the script file that is created is returned invisibly. The function is used for its side effect of creating the adequate script file.

Examples

checkmate_msgs[1:3] # First 3 {checkmate} messages
#>                                                                                        ^Variable '([^']*)': (.+)$ 
#>                                                                                         "Variable {.var %s}: %s." 
#> ^Unknown type '([^']*)' to specify check for names\\. Supported are 'unnamed', 'named', 'unique' and 'strict'\\.$ 
#>        "Unknown option '%s' to specify check for names. Supported are 'unnamed', 'named', 'unique' and 'strict'." 
#>                                                                              ^Unknown class identifier '([^']*)'$ 
#>                                                                             "Unknown class identifier {.cls %s}." 
msg <- "Unknown class identifier 'my_class'"
translate(msg, checkmate_msgs, domain = "R-svAssert")
#> [1] "Unknown class identifier 'my_class'"