ropensci / unconf16

rOpenSci's San Francisco hackathon/unconf 2016
http://unconf16.ropensci.org
23 stars 7 forks source link

Message translation package #36

Open seankross opened 8 years ago

seankross commented 8 years ago

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 takes L() 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:

message(L()%:%"Hello world!")

Volunteers have been writing translations inside of .yaml files. The syntax for yaml is pretty intuitive:

"This is a sentence in English":
 "Esta es una frase en Español"

Each yaml file is read in as a list() and each list is stored in R/sysdata.rda. The L() function references these lists for translations.

This is just one idea and I'd love to discuss any other approaches.

leeper commented 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.

seankross commented 8 years ago

@leeper awesome! I'll take a look.