Hi all.
There is a string in the quick settings menu, “Power Mode”, that appears twice (here, for example), and I would like to translate it in different ways depending on its position.
I know that this means adding a “context” to the translatable string in the source code so that gettext can differentiate the two instances. Now, I neved coded in JavaScript—so all this is probably due to my ignorance—but I figured it was an easy enough change, so I cloned the GNOME Shell repo and tried to do it on my machine (hoping to post a merge request later).
I’m using the toolbox workflow outlined here on the GitLab repo to build and run the modified version of the shell locally, on Fedora 42 (with the latest updates).
The string appears as _('Power Mode’), and I tried two different things to change it.
- If I understood the syntax right (see e.g. this line), I should modify it to
C_('context1', 'Power Mode’)andC_('context2', 'Power Mode’)in the two different cases (with more meaningful context indicators, of course). When I callxgettext -f po/POTFILES.into generate the PO template, however, the “Power mode” string disappears from the translatable ones, and ends up in the “#~strings” at the end of the PO file. To be fair, every other string marked for translation with theC_(#1, #2)function for adding context has the same fate. - From the
gettextmanual, I read that thepgettextfunction can be used to add a context to a translatable string. If I use this instead ofC_, then the “Power Mode” string correctly appears, with two different contexts, in the PO file. However, the shell doesn’t run correctly anymore because it does not recognize thepgettextfunction:
GNOME Shell-CRITICAL **: 11:34:36.074: Failed to setup quick settings: ReferenceError: pgettext is not defined
What am I missing here to make it work?