trans {translated} | R Documentation |
Translate strings
Description
This function finds a translation for given keys in translation
JSON files. If none found, a bare key is returned and a warning raised.
Translation language is controlled by trans_locale()
function.
Translation strings may contain {var}
chunks. These are replaced in the
final string by respective strings passed to ...
.
If a translation depends on a count, a .n
parameter allows the user to
select an appropriate translation form. Count interpretation is defined
within translation JSONs for each language separately under $.config.plural
path. Integer returned by this interpretation function is used as index for
extracting the correct translation from an array.
Thanks to the implementation strategy, it is possible to create recursive translations (i.e. translations whose smaller chunks are translations themselves). This makes it possible to translate statements like "Found n file(s) in m directory/ies" by translating "files" and "directories" chunks first. In this case an appropriate translation entry would look like: "Found trans("file", .n = n_files) in trans("directory", .n = n_dirs)". Braces evaluate the content inside as R code.
Usage
trans(.key, ..., .n = NULL)
Arguments
.key |
|
... |
|
.n |
|
Value
A string vector of the same length as .key
, each element being a
translated string.
Examples
trans_path(system.file("examples", package = "translated"))
trans("title")
trans("btn_insert", number = "five")
# Non-character values are coerced to strings
trans("btn_insert", number = 5)
# Missing entries raise a warning and return the key
trans("missing_entry")