traduire R package provides a wrapper around the
R’s built-in internationalisation is focussed on translating messages, warnings and errors transparently for package authors, within a session that does not change language. The translation is completely transparent, as one writes:
warning("spline: first and last y values differ - using y for both")
(for example, in
stats::spline), and the text used will vary depending on the locale (the environment variable
LC_MESSAGES) to show, in a French locale:
Warning message: In stats::spline(1:10, 1:10, method = "periodic") : spline : la première et la dernière valeurs de y diffèrent - y utilisé pour les deux
It is harder to generate translations in contexts other than messages, warnings and errors - for example the axes of a plot, the output of a knitr document, or the results of a web service. It is also not straightforward to change the language of translation during a session (e.g., to produce knitr output in two different languages, or to respond to a query in a language that changes at the client’s request).
For this, we wanted the ability to internationalise strings on the fly, changing languages within a session, and decoupled from messages. When used within a package, the interface is lightweight.
For an introduction to the package, see the vignette, which shows how to internationalise strings, including strings requiring interpolation (substitution of variables), and for a more complete example that implements an internationalised “hello-world-as-a-service”, showing how to change languages dynamically.
Note that this package is designed only to help with tooling your package or application to allow it to be translated; the translations of content must still be carried out by hand.
Or, install directly from GitHub: