msgtools implements a number of utilities for developing and maintaining error, warning, and other messages in R packages, including checking for consistency across messages, spell-checking messages, and building message translations into various languages for purposes of localization. The package is designed to enhance devtools.
Building and updating message translation files
msgtools provides a simplified workflow for creating, maintaining, and updating translations of messages in both R and C code that improve upon those available in the tools package. For some context on message localization in R, see “R Administration” and “Translating R Messages, R >=3.0.0”). A list of “translation teams” is available from https://developer.r-project.org/TranslationTeams.html.
R has reasonably sophisticated built-in internationalization (i18n) features. All calls to message(), warning(), stop(), gettext(), ngettext(), and gettextf() are passed through a C-level functionality that translates the contained messages into the user’s local language (if the translations are available).
To begin localization (l10n) of messages, a package developer simply needs to (1) write translations for these messages using a standardized file format and (2) install the translations into their package. Localization traditionally requires the manual creation of a .pot (“portable object template”) file using the xgettext command line utility and the generation of language-specific .po (“portable object”) translation files that specify the translation of each message string into the target language.
The .pot/.po file format is fairly straightforward, simply containing a series of messages and their translations, plus some metadata:
#: lib/error.c:116
msgid "Unknown system error"
msgstr "Error desconegut del sistema"
(The R source contains a number of examples of translations, for example in the base package.)
msgtools negates the need to directly call the command-line utilities or interact with .pot/.po files by relying on R representations of templates and translations (provided by poio). This makes it possible to programmatically create, modify, and install translations, thus eliminating the need to manually open each translation file in a text editor.
A basic msgtools workflow is as follows:
library("msgtools")
# setup package for localization
use_localization()
# create Spanish translation
es <- make_translation("es", translator = "Some Translator
评论