Learn R Programming

msgtools (version 0.2.4)

read_translation: Handle message translations (.po files)

Description

Read, write, and generate translations of diagnostic messages

Usage

read_translation(language, pkg = ".", domain = "R")
write_translation(translation, pkg = ".", verbose = getOption("verbose"))
make_translation(language, translator, team = " ", pkg = ".", domain = "R", verbose = getOption("verbose"))
sync_translations(pkg = ".", verbose = getOption("verbose"))

Arguments

language
A character string specifying a language, as either: (1) “ll”, an ISO 639 two-letter language code (lowercase), or (2) “ll_CC”, an ISO 639 two-letter language code (lowercase) and ‘CC’ is an ISO 3166 two-letter country code (uppercase).
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.
translation
An object of class "po" containing a message translation.
verbose
A logical. Should the function be chatty?
translator
A character string the name and email of a translation of the form First Last .
team
Optionally, a character string specifying contact information for a “translation team”.

Value

make_translation and read_translation reutrn an object of class “po”. write_translation returns the path to the file, invisibly.

Details

read_translation and write_translation provide basic input and output functionality for translation (.po) files. If called from with an R package directory, the locations of these fies are identified automatically. read_po provides a lower-level interface for reading a specific file.

The behavior of make_translation depends on context. If the requested translation already exists, it is updated against the template (.pot) file and loaded into memory. If the translation does not already exist, the function creates a "po" translation object from the message template (.pot) file (if one does not exist, it is created). The language and translator arguments are mandatory in the latter case and only used to update values in an existing file if they differ from the existing values. language must be an allowed language code (see language_codes); the “Plural-Forms” metadata field is generated automatically from the language value (see plural_forms).

sync_translations() updates the template file (via sync_template and then updates existing translation files against it.

edit_translation is a very simple interactive interface for editing a translation object in memory.

See Also

make_template, use_localization, edit_translation

Examples

Run this code
## Not run: 
#   # create example package
#   pkg <- dummy_pkg()
#   
#   # setup pkg for localization
#   use_localization(pkg)
#   
#   # generate Portugal Portugese translation in memory
#   make_translation("pt_PT", translator = "Some Person <example@example.com>")
#   # generate Spanish translation in memory
#   (tran <- make_translation("es", translator = "Some Person <example@example.com>"))
#   # write to disk
#   write_translation(tran)
# ## End(Not run)

Run the code above in your browser using DataLab