From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4239B3858D35; Sun, 12 Nov 2023 13:30:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4239B3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1699795809; bh=ln949Se1SA0MjOqx+TFd861BlZXnOTJYpOyj1oFz4GE=; h=From:To:Subject:Date:From; b=kMC9SprhwnecNV7k4zXBCYeqDzowwnUMLBdzZ31a6L/B2Hcat661X+DllIyW7GFfC +5ekd/3Z14uPSLL8XJ4TISCiqOajtfr7ZXFzADoFUVIhzFQLUrNxzUTJZPyEBhFZAp K8CEpYP8jYEq3Mb3ZGMesuVHcdgaRYifTcPH7MCc= From: "sebaaa1754 at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug manual/31057] New: 'How to use "gettext" in GUI programs' could mention pgettext() Date: Sun, 12 Nov 2023 13:30:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: manual X-Bugzilla-Version: 2.38 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sebaaa1754 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31057 Bug ID: 31057 Summary: 'How to use "gettext" in GUI programs' could mention pgettext() Product: glibc Version: 2.38 Status: UNCONFIRMED Severity: normal Priority: P2 Component: manual Assignee: unassigned at sourceware dot org Reporter: sebaaa1754 at gmail dot com CC: mtk.manpages at gmail dot com Target Milestone: --- The node 'How to use "gettext" in GUI programs' details at length how to so= lve the problem of translating repeated short strings in GUI application. The solution provided is a custom function called `sgettext`. However, gettext includes a function that is virtually identical: pgettext.= As can be seen in https://www.gnu.org/software/gettext/manual/html_node/Contexts.html. I think it would be nice to replace this section with pgettext in mind, or = at least mentions pgettext, which is not mentioned anywhere in the glibc manual currently. Here I quote the relevant section of the node from manual/locale.texi: > One solution to this problem is to artificially extend the strings > to make them unambiguous. But what would the program do if no > translation is available? The extended string is not what should be > printed. So we should use a slightly modified version of the functions. >=20 > To extend the strings a uniform method should be used. E.g., in the > example above, the strings could be chosen as >=20 > @smallexample > Menu|File > Menu|Printer > Menu|File|Open > Menu|File|New > Menu|Printer|Select > Menu|Printer|Open > Menu|Printer|Connect > @end smallexample >=20 > Now all the strings are different and if now instead of @code{gettext} > the following little wrapper function is used, everything works just > fine: >=20 > @cindex sgettext > @smallexample > char * > sgettext (const char *msgid) > @{ > char *msgval =3D gettext (msgid); > if (msgval =3D=3D msgid) > msgval =3D strrchr (msgid, '|') + 1; > return msgval; > @} > @end smallexample >=20 > What this little function does is to recognize the case when no > translation is available. This can be done very efficiently by a > pointer comparison since the return value is the input value. If there > is no translation we know that the input string is in the format we used > for the Menu entries and therefore contains a @code{|} character. We > simply search for the last occurrence of this character and return a > pointer to the character following it. That's it! >=20 > If one now consistently uses the extended string form and replaces > the @code{gettext} calls with calls to @code{sgettext} (this is normally > limited to very few places in the GUI implementation) then it is > possible to produce a program which can be internationalized. >=20 > With advanced compilers (such as GNU C) one can write the > @code{sgettext} functions as an inline function or as a macro like this: >=20 > @cindex sgettext > @smallexample > #define sgettext(msgid) \ > (@{ const char *__msgid =3D (msgid); \ > char *__msgstr =3D gettext (__msgid); \ > if (__msgval =3D=3D __msgid) \ > __msgval =3D strrchr (__msgid, '|') + 1; \ > __msgval; @}) > @end smallexample >=20 > The other @code{gettext} functions (@code{dgettext}, @code{dcgettext} > and the @code{ngettext} equivalents) can and should have corresponding > functions as well which look almost identical, except for the parameters > and the call to the underlying function. >=20 > Now there is of course the question why such functions do not exist in > @theglibc{}? There are two parts of the answer to this question. >=20 > @itemize @bullet > @item > They are easy to write and therefore can be provided by the project they > are used in. This is not an answer by itself and must be seen together > with the second part which is: >=20 > @item > There is no way the C library can contain a version which can work > everywhere. The problem is the selection of the character to separate > the prefix from the actual string in the extended string. The > examples above used @code{|} which is a quite good choice because it > resembles a notation frequently used in this context and it also is a > character not often used in message strings. --=20 You are receiving this mail because: You are on the CC list for the bug.=