write_po_file {potools} | R Documentation |
Write a .po or .pot file corresponding to a message database
Description
Serialize a message database in the ‘.po’ and ‘.pot’ formats recognized by the gettext ecosystem.
Usage
write_po_file(
message_data,
po_file,
metadata,
width = 79L,
wrap_at_newline = TRUE,
use_base_rules = metadata$package %chin% .potools$base_package_names
)
po_metadata(
package = "",
version = "",
language = "",
author = "",
email = "",
bugs = "",
copyright = NULL,
...
)
## S3 method for class 'po_metadata'
format(x, template = FALSE, use_plurals = FALSE, ...)
## S3 method for class 'po_metadata'
print(x, ...)
Arguments
message_data |
|
po_file |
Character vector giving a destination path. Paths ending in
‘.pot’ will be written with template files (e.g., |
metadata |
A |
width |
Numeric governing the wrapping width of the output file.
Default is |
wrap_at_newline |
Logical, default |
use_base_rules |
Logical; Should internal behavior match base behavior
as strictly as possible? |
package |
Character; the name of the package being translated. |
version |
Character; the version of the package being translated. |
language |
Character; the language of the |
author |
Character; an author (combined with |
email |
Character; an e-mail address associated with |
bugs |
Character; a URL where issues with the translations can be reported. |
copyright |
An object used to construct the initial Copyright reference
in the output. If
If a |
... |
Additional (named) components to add to the metadata. For
|
x |
A |
template |
Logical; format the metadata as in a ‘.pot’ template? |
use_plurals |
Logical; should the |
Details
Three components are set automatically if not provided:
-
pot_timestamp
- APOSIXct
used to write thePOT-Creation-Date
entry. Defaults to theSys.time()
at run time. -
po_timestamp
- APOSIXct
used to write thePO-Revision-Date
entry. Defaults to be the same aspot_timestamp
. -
language_team
- A string used to write theLanguage-Team
entry. Defaults to be the same aslanguage
; if provided manually, the formatLANGUAGE <LL@li.org>
is recommended.
The charset
for output is always set to "UTF-8"
; this is
intentional to make it more cumbersome to create non-UTF-8 files.
Value
For po_metadata
, an object of class po_metadata
that
has a format
method used to serialize the metadata.
Author(s)
Michael Chirico
References
https://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html
See Also
translate_package()
, get_message_data()
,
tools::xgettext2pot()
, tools::update_pkg_po()
Examples
message_data <- get_message_data(system.file('pkg', package='potools'))
desc_data <- read.dcf(system.file('pkg', 'DESCRIPTION', package='potools'), c('Package', 'Version'))
metadata <- po_metadata(
package = desc_data[, "Package"], version = desc_data[, "Version"],
language = 'ar_SY', author = 'R User', email = 'ruser@gmail.com',
bugs = 'https://github.com/ruser/potoolsExample/issues'
)
# add fake translations
message_data[type == "singular", msgstr := "<arabic translation>"]
# Arabic has 6 plural forms
message_data[type == "plural", msgstr_plural := .(as.list(sprintf("<%d translation>", 0:5)))]
# Preview metadata
print(metadata)
# write .po file
write_po_file(
message_data[message_source == "R"],
tmp_po <- tempfile(fileext = '.po'),
metadata
)
writeLines(readLines(tmp_po))
# write .pot template
write_po_file(
message_data[message_source == "R"],
tmp_pot <- tempfile(fileext = '.pot'),
metadata
)
writeLines(readLines(tmp_pot))
# cleanup
file.remove(tmp_po, tmp_pot)
rm(message_data, desc_data, metadata, tmp_po, tmp_pot)