Title: | Simple and Robust Translation System |
---|---|
Description: | Allows translating with formatted string literals, grouped entries, and configurable system of plurals. Have a separate file for each locale and use inheritance to handle dialect differences. |
Authors: | Laura Bakala [cre, aut] , Edward Gillian [ctb] , Transition Technologies Science [cph, fnd] |
Maintainer: | Laura Bakala <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.1 |
Built: | 2024-11-12 05:41:20 UTC |
Source: | https://github.com/ttscience/translated |
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.
trans(.key, ..., .n = NULL)
trans(.key, ..., .n = NULL)
.key |
|
... |
|
.n |
|
A string vector of the same length as .key
, each element being a
translated string.
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")
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")
This function displays available locales
trans_available()
trans_available()
Returns available locales in df
path <- system.file("examples", package = "translated") trans_path(path) # Display available locales trans_available()
path <- system.file("examples", package = "translated") trans_path(path) # Display available locales trans_available()
This function allows setting translation locale and accessing the currently set one.
trans_locale(locale)
trans_locale(locale)
locale |
|
If locale
was not passed, currently set locale, else nothing.
trans_path(system.file("examples", package = "translated")) # Check your default locale trans_locale() # Switch the translation to Polish language trans_locale("pl_PL") trans("title")
trans_path(system.file("examples", package = "translated")) # Check your default locale trans_locale() # Switch the translation to Polish language trans_locale("pl_PL") trans("title")
This function allows setting translation path and accessing the currently set one.
trans_path(path)
trans_path(path)
path |
|
If path
was not passed, currently set path, else nothing.
# Set path to example translations shipped with this package trans_path(system.file("examples", package = "translated")) # Check the current path trans_path()
# Set path to example translations shipped with this package trans_path(system.file("examples", package = "translated")) # Check the current path trans_path()
This function forces the translations to be loaded from JSON files again.
trans_reload()
trans_reload()
No return value, called for its side effect.
trans_path(system.file("examples", package = "translated")) trans_reload()
trans_path(system.file("examples", package = "translated")) trans_reload()