An alternative to gettext()
and xgettext()
that enables support of many
languages in any R application. Find, and extract source text that requires
translation. Store, structure, and manipulate source texts and translations
via R6
classes exposing a user-friendly API. Easily export and import to/
from a plain text format that fosters collaboration with other non-technical
and external collaborators.
There is no way GNU gettext
can
be replaced. This is well-designed software that exposes an extensive set
of functionalities. It is ubiquitous, and has withstood the test of time. Its
relevance within the R programming language is unquestionable, and it is not
the objective of transltr
to replace it. Instead, it aims to provide a
much-lighter alternative for simpler use cases. But why?
❌ Trying to extend gettext()
to functions other than stop()
,
warning()
, and message()
usually leads to fragile and incomplete
ad-hoc implementations.
❌ R's Native Language Support (NLS) functionalities are not always
intuitive, and their documentation is scattered across many manual pages
of package base
and tools
.
❌ There is no easy way to inspect, and manipulate information found in
Portable Object (.po
) files (without writing a lot of code).
❌ Portable Objects are not intuitive for non-technical collaborators.
❌ Changing an R session's locale is not always a good idea when the intent is to merely display source text in another language. Doing so may lead to undefined behavior.
❌ R offers no way to decouple languages used for backend and frontend purposes. For example, the user interface of a Shiny application could be displayed in a language that differs from the server's internal locale.
✅ transltr::translate()
works everywhere. It can always be located,
and extracted automatically with transltr::find_source()
.
✅ transltr
features are centralized, and thoroughly documented, even
internal ones.
✅ transltr
stores, and structures source text and translations as
regular R objects. They can easily be inspected, modified, imported, and
exported.
✅ transltr
uses an intuitive plain text format that is (more) easily
sharable, maintainable, and modifiable, even by non-technical collaborators.
✅ transltr
leaves the underlying locale unchanged.
✅ transltr
may be used in conjunction with R's NLS features, keeping
front-end translations separate from back-end messages, logs, etc.
✅ transltr
only uses three carefully chosen dependencies: digest
,
R6
, and yaml
.
The plan is to submit transltr
to CRAN for the first time in late November
2024. Until further notice, please do not attempt to use it. It should be
considered as being in a pre-beta stage until further notice.
Write your programs as you normally would. Whenever you require a piece
of text to be translated at runtime, wrap it with transltr::translate()
.
This section will be completed later.
The following diagram gives an overview of how the package works.
Submit them here. Thank you for your collaboration.