Learn R Programming

msgtools (version 0.2.4)

msgtools: Tools for developing diagnostic messages

Description

This package implements a number utilities for developing and maintaining error, warning, and other diagnostic messages in R packages, including checking for consistency across messages, spell-checking messages, and managing internationalization and location of messages (i.e., translations into various languages).

Usage

use_localization(charset = "UTF-8", pkg = ".", domain = "R", verbose = getOption("verbose"))

Arguments

charset
A character string specifying the character set of the translation template file.
pkg
The directory of an R package to extract diagnostic messages from. Path is passed to as.package.
domain
A character string specifying the “domain” of the messages. Either “R” (the default) or “C”. This is case insensitive.
verbose
A logical. Should the function be chatty?

Details

use_localization (alias: use_l10n) is the high-level, devtools-style function to create a /po directory and initialize a translation template (.pot) file.

make_template provides a lower-level interface for this internationalization step and make_translation handles localization. install_translations installs the translations for use.

get_messages returns a tibble (data frame) of messages and their file locations. spell_check_msgs returns a subset of messages with possible misspelled words and suggested replacements.

References

GNU gettext Manual

See Also

make_template, make_translation

Examples

Run this code
  # create example package
  pkg <- dummy_pkg()
  
  # get messages in memory
  get_messages(pkg = pkg)
  # spell check messages
  spell_check_msgs(pkg = pkg)

  # setup pkg for localization
  use_localization(pkg = pkg)
  
  # make a translation
  tran <- make_translation("es", translator = "Some Person <example@examle.com>", pkg = pkg)
  write_translation(tran, pkg = pkg)

  # install translation(s)
  check_translations(pkg = pkg) # check for errors before install
  install_translations(pkg = pkg)

Run the code above in your browser using DataLab