Is it possible to use something like gettext to translate an R script. If so, how? If not, what other options I have?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use base::gettext/ngettext, base::bindtextdomain and tools::xgettext2pot functions.
For example:
Then, supposing this function is inside a file whose path is “/my/dir/R/myfile.R” use:
tools::xgettext2pot("/my/dir", "/my/translation/dir/pot/R-myProgram.pot")then use msginit, msgfmt, etc. to create a .mo file/my/translation/dir/fr/LC_MESSAGES/R-myProgram.mo. myFunction() should now print “Bonjour” instead of “Hello” if your locale is French.A couple of other points :
domainargument seems to be by default the namespace of the function calling gettext()