Open seankross opened 8 years ago
This infrastructure already exists in R in the form of gettext()
and ngettext()
, though the documentation is pretty sparse. Richie Cotton and I just got funding from the RConsortium to expand this considerably. See here for a draft of our package aimed at making it easier to manage translations in packages. I'd be happy to collaborate, hear ideas, get input, and start coding on this more, if there's interest.
@leeper awesome! I'll take a look.
Many folks on the Internet asked me if they could translate swirl's menus, which are just calls to
message()
. I was wondering what this community thinks about a package, a potential devtools feature, or a document with general guidance for managing message/string translations in a package. These are the concerns I had when implementing translations in swirl:The approach I took in order to address these issues in swirl was to create a function
L()
that produces a potential translation from a string, and then to create a binary operator%:%
that takesL()
on the left hand side, and a string to be translated on the right hand side. The%:%
operator returns either the translation or the string from the right hand side verbatim if no translation exists. When it's all put together the code looks like this:Volunteers have been writing translations inside of
.yaml
files. The syntax for yaml is pretty intuitive:Each yaml file is read in as a
list()
and each list is stored inR/sysdata.rda
. TheL()
function references these lists for translations.This is just one idea and I'd love to discuss any other approaches.