From tom@@@k@||ber@ @end|ng |rom gm@||@com  Fri Nov  5 16:15:19 2021
From: tom@@@k@||ber@ @end|ng |rom gm@||@com (Tomas Kalibera)
Date: Fri, 5 Nov 2021 16:15:19 +0100
Subject: [Rd] gettext(msgid, domain="R") doesn't work for some 'msgid':s
In-Reply-To: <000f4e2a-684d-e26b-2b1c-fabc28880d55@gmail.com>
References: <CAFDcVCT0zPRGEG5ugr+yEbgKH57bo1MMwXRgh=q5y7OwAU1F0A@mail.gmail.com>
 <000f4e2a-684d-e26b-2b1c-fabc28880d55@gmail.com>
Message-ID: <23255480-95fb-f5b0-4828-56aaace9b575@gmail.com>


On 11/5/21 4:12 PM, Duncan Murdoch wrote:
> On 05/11/2021 10:51 a.m., Henrik Bengtsson wrote:
>> I'm trying to reuse some of the translations available in base R by 
>> using:
>>
>> ?? gettext(msgid, domain="R")
>>
>> This works great for most 'msgid's, e.g.
>>
>> $ LANGUAGE=de Rscript -e 'gettext("cannot get working directory", 
>> domain="R")'
>> [1] "kann das Arbeitsverzeichnis nicht ermitteln"
>>
>> However, it does not work for all.? For instance,
>>
>> $ LANGUAGE=de Rscript -e 'gettext("Execution halted\n", domain="R")'
>> [1] "Execution halted\n"
>>
>> This despite that 'msgid' existing in:
>>
>> $ grep -C 2 -F 'Execution halted\n' src/library/base/po/de.po
>>
>> #: src/main/main.c:342
>> msgid "Execution halted\n"
>> msgstr "Ausf?hrung angehalten\n"
>>
>> It could be that the trailing newline causes problems, because the
>> same happens also for:
>>
>> $ LANGUAGE=de Rscript --vanilla -e 'gettext("error during cleanup\n",
>> domain="R")'
>> [1] "error during cleanup\n"
>>
>> Is this meant to work, and if so, how do I get it to work, or is it a 
>> bug?
>
> I don't know the solution, but I think the cause is different than you 
> think, because I also have the problem with other strings not 
> including "\n":
>
> $ LANGUAGE=de Rscript -e 'gettext("malformed version string", 
> domain="R")'
> [1] "malformed version string"

I can reproduce Henrik's report and the problem there is that the 
trailing \n is stripped by R before doing the lookup, in do_gettext


 ??????????? /* strip leading and trailing white spaces and
 ?????????????? add back after translation */
 ??????????? for(p = tmp;
 ??????????????? *p && (*p == ' ' || *p == '\t' || *p == '\n');
 ??????????????? p++, ihead++) ;

But, calling dgettext with the trailing \n does translate correctly for me.

I'd leave to translation experts how this should work (e.g. whether the 
.po files should have trailing newlines).

Tomas

>
> Duncan Murdoch
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] gettext(msgid, domain="R") doesn't work for some 'msgid':s
Tomas Kalibera