On 05/02/13 00:02, Prof Brian Ripley wrote:
> On 04/02/2013 11:14, Florent Angly wrote:
>> Hi Brian,
>>
>> I appreciate your clarifications. I am sending this reply to the
>> R-devel, as per you suggestion.
>>
>> As mentioned in my post, I have no prior experience with this R function
>> and logically, I looked up its help page, which states:
>>> Conventionally the domain for *R* warning/error messages in package
>>> pkg is |"R-pkg"|, and that for C-level messages is |"pkg"|.
>> While it certainly mentions messages in the C-realm, it does not state
>> that they cannot be translated using gettext(). This is less than
>> obvious and could perhaps be explicitly stated.
>
> You are asking us to state what *can not* be done?   It does clearly 
> state the the domain for *R* messages in a package is "R-pkg".   
> Domain "R" is not of that form.

If C-level messages really cannot be read from R code, then yes, it 
makes a lot of sense to write in the documentation of this R function 
that this cannot be done, e.g. the sentence could be rewritten as: 
"Conventionally the domain for *R* messages in package pkg is |"R-pkg"|. 
Note that C-level messages are in domain |"pkg"| but cannot be accessed 
by gettext()."

> It does clearly state the the domain for *R* messages in a package is 
> "R-pkg".   Domain "R" is not of that form.
>> If gettext() cannot be used to get the translation for the "Error in "
>> message in some supported language, then is there an alternative?
>
> You put it in a domain named "R-pkg", prepared using xgetttext().
Thank you. I am sure that this would work but that's not really an 
option seeing as I do not generate any R script files.

In case this is of use to others, I'll add that a solution is to using 
ngettext() instead of gettext() (thanks Brian Cassidy). With ngettext(), 
I am successful in retrieving all desired translations:
> |ngettext( 1, "Error: ", "", domain = "R" )|

Best,
Florent



>
>>
>> Best,
>>
>> Florent
>>
>>
>>
>> On 04/02/13 18:27, Prof Brian Ripley wrote:
>>> The 'wierdness' is that 'R' is a domain of C messages and you are
>>> trying to use it from R.  How messages are massaged before being sent
>>> for translation depends on the language, including how trailing spaces
>>> are handled.   There is no reason to expect domains intended for C
>>> code to work in R-level gettext(), nor in stop() etc.
>>>
>>> This was really an R-devel question: see the posting guide.
>>>
>>> On Mon, 4 Feb 2013, Florent Angly wrote:
>>>
>>>> Hi,
>>>>
>>>> I am trying to use the gettext() function to translate some text. I
>>>> have never used this function before, so, it's entirely possible that
>>>> I am doing something wrong. The issue that I am encountering is that
>>>> gettext() properly translates some text, but not some other.
>>>>
>>>> Natural language was compiled in my R (installed from the Debian
>>>> repositories):
>>>> $ R
>>>> R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
>>>> [...]
>>>>   Natural language support but running in an English locale
>>>> [...]
>>>>> q()
>>>>
>>>> Here is some text that has some translation in the file ./po/fr.po:
>>>>     #: src/main/errors.c:290
>>>>     msgid "invalid option \"warning.expression\""
>>>>     msgstr "option incorrecte \"warning.expression\""
>>>>     [...]
>>>>     #: src/main/errors.c:582
>>>>     msgid "Error in "
>>>>     msgstr "Erreur dans "
>>>>
>>>> Start R in French and see if I can get something translated to French:
>>>> $ LANG=fr_FR.UTF8  R
>>>>> stop('This is an error')
>>>> Erreur : This is an error
>>>>
>>>>> bindtextdomain("R") # does not seem necessary, but just to be safe...
>>>> [1] "/usr/share/R/share/locale"
>>>>
>>>>> gettext("Error in ", domain="R")
>>>> [1] "Error in "
>>>>
>>>>> "invalid option \"warning.expression\"" -> msg; gettext(msg,
>>>>> domain="R")
>>>> [1] "option incorrecte \"warning.expression\""
>>>>
>>>>
>>>> So, the stop() function successfully translates. I can also manually
>>>> translate some entries, but why can does it not work for
>>>> gettext("Error in ", domain="R")?
>>>> Any idea?
>>>> Thanks
>>>>
>>>> Florent
>>>>
>>>> ______________________________________________
>>>> r-h...@r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>
>>
>>     [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>


        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to