[R-pkg-devel] translation .mo files

Fox, John j|ox @end|ng |rom mcm@@ter@c@
Mon Feb 10 16:15:14 CET 2020


Dear Paul,

Here's some information that I prepared for translators of the Rcmdr package, slightly edited to make it more generic. Perhaps you'll find it useful:

R provides a general facility for translating messages from English to other languages using the GNU gettext translation tools <http://www.gnu.org/software/gettext/>. These tools are used both for R itself and for R packages, though most packages are not set up to allow translation.

How translation works in R is described in a 2005 article in R News, available at <https://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf>. There is also some information in the R manuals, at <https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Internationalization>, <https://cran.r-project.org/doc/manuals/R-admin.html#Localization-of-messages>, and at <http://developer.r-project.org/Translations30.html>.

The general procedure for preparing translations is very simple. I'll explain it briefly in case you're unfamiliar with it. The package sources include the plain-text file <package-name>.pot in the package po subdirectory. You would copy this file to R-xx.po (where xx is the usually two-character code for your language -- e.g., fr for French, thus R-fr.po) and then edit that file to provide translations of the Rcmdr messages. (In your case, you could work backwards from the .po file you received to make a .pot file.) 

You would then use the GNU gettext tools (available at <https://www.gnu.org/software/gettext/>) to compile your .po file into a .mo file, conventionally named R-<package-name>.mo. The .mo file would be placed in the package sources at inst/po/xx/LC_MESSAGES/ . You would then test your translation by building and installing the package. 

I hope this helps,
 John

  -----------------------------
  John Fox, Professor Emeritus
  McMaster University
  Hamilton, Ontario, Canada
  Web: http::/socserv.mcmaster.ca/jfox

> On Feb 8, 2020, at 3:14 AM, Paul Gilbert <pgilbert902 using gmail.com> wrote:
> 
> I have been sent .po and .mo files with message translations for one of my packages. The .po file I know goes in the source package po/ directory but I have not had .mo files previously. The translator thinks the .mo file goes in inst/po. The .mo file seems to be generated from the .po file, but I am not sure if that happens in the install of the source package, or in some pre-process. I thought I could determine this by looking at an installed package, but I don't see .po or .mo files in installed packages. So far I have had no luck finding documentation on these details. So I have three questions.
> 
> -Should the .mo file be included in the package, and if so, where?
> 
> -When a package is installed, where does the translation information go in the directory structure of the library?
> 
> -Is this documented somewhere? (Please not a vague reference to 'Writing R Extensions', I've looked there and many other places. I need a section or page reference.)
> 
> Thanks,
> Paul Gilbert
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list