[Rd] translation domain is not inferred correctly from a package's print methods -- intended behavior?

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Fri Oct 1 12:48:28 CEST 2021


>>>>> Michael Chirico 
>>>>>     on Mon, 12 Jul 2021 14:21:14 -0700 writes:

    > Here is a reprex:


    > # initialize reprex package
    > cd /tmp
    > mkdir myPkg && cd myPkg
    > echo "Package: myPkg" > DESCRIPTION
    > echo "Version: 0.0.1" >> DESCRIPTION
    > mkdir R
    > echo "print.my_class = function(x, ...) { cat(gettext(\"'%s' is
    > deprecated.\"), '\n', gettext(\"'%s' is deprecated.\",
    > domain='R-myPkg'), '\n') }" > R/foo.R
    > echo "S3method(print, my_class)" > NAMESPACE
    > # extract string for translation
    > Rscript -e "tools::update_pkg_po('.')"
    > # add dummy translation
    > msginit -i po/R-myPkg.pot -o po/R-ja.po -l ja --no-translator
    > head -n -1 po/R-ja.po > tmp && mv tmp po/R-ja.po
    > echo 'msgstr "%s successfully translated"' >> po/R-ja.po
    > # install .mo translations
    > Rscript -e "tools::update_pkg_po('.')"
    > # install package & test
    > R CMD INSTALL .
    > LANGUAGE=ja Rscript -e "library(myPkg); print(structure(1, class = 'my_class'))"
    > #  '%s' は廃止予定です
    > #  %s successfully translated

Trying to see if the current "R-devel trunk" would still suffer
from this, and prompted by Suharto Anggono's suggestion on R's
bugzilla,   https://bugs.r-project.org/show_bug.cgi?id=17998#c24


I've finally started looking at this ..
(Not having a Japanese locale installed though).

    > Note that the first gettext() call, which doesn't supply domain=,
    > returns the corresponding translation from base R (i.e., the output is
    > the same as gettext("'%s' is deprecated.", domain="R-base")).

I don't see this (not having a Japanase locale?  should I try
with a locale I have installed?)

    > The second gettext() call, where domain= is supplied, returns our
    > dummy translation, which is what I would have expected from the first
    > execution.

I can get the following which seems to say that everything is
fine and fixed now, right?

MM using lynne:myPkg$ LANGUAGE=ja R-devel -s --vanilla -e 'library(myPkg,lib.loc="~/R/library/64-linux-MM-only");structure(1,class="my_class");R.version.string'
%s successfully translated 
 %s successfully translated 
[1] "R Under development (unstable) (2021-09-30 r80997)"


MM using lynne:myPkg$ LANGUAGE=ja `R-devel RHOME`/bin/Rscript --vanilla -e 'library(myPkg,lib.loc="~/R/library/64-linux-MM-only");structure(1,class="my_class");R.version.string'
%s successfully translated 
 %s successfully translated 
[1] "R Under development (unstable) (2021-09-30 r80997)"


Note: During my experiments, I also do observe things confusing to me, when
using Rscript and R from the command line... in some cases
getting errors (in Japanese) ... but that may be just in those
cases I have left any space in the string
((in the case of 'R' which in my case suffers from quoting hell
  because I use wrapper  sh-scripts to call my versions of R ... ))


    > Here is what's in ?gettext:

    >> If domain is NULL or "", and gettext or ngettext is called from a function in the namespace of package pkg the domain is set to "R-pkg". Otherwise there is no default domain.


    > Does that mean the S3 print method is not "in the namespace of myPkg"?

no.

    > Or is there a bug here?

Yes, rather;  or there *was* one.

Thanks a lot, Michael!

Best,
Martin



More information about the R-devel mailing list