bugGNU gettext - Bugs: bug #64481, Gtk.builder.new_from_string...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #64481: Gtk.builder.new_from_string strings not extracted

Submitter:  Anders Jonsson <haaninjo>
Submitted:  Thu 27 Jul 2023 09:27:05 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Confirmed
Privacy:  Public Assigned to:  None
Open/Closed:  Open

Tue 07 Nov 2023 01:17:08 AM UTC, comment #2: 


> xgettext can't possibly know, when parsing C sources, that the text inside the Gtk.builder.new_from_string() argument should instead be parsed as Glade XML


Sure it can. The function name 'gtk_builder_new_from_string' (that's the actual function name in the C code) provides the necessary information.

> should instead be parsed as Glade XML (for which it has a completely different parsing mode).


It is doable.

Bruno Haible <haible>
Group administrator
Mon 06 Nov 2023 10:45:24 PM UTC, comment #1: 

It seems to me this is what gettext_noop() (see 'info "(gettext)Special cases"' is intended for.

xgettext can't possibly know, when parsing C sources, that the text inside the Gtk.builder.new_from_string() argument should instead be parsed as Glade XML (for which it has a completely different parsing mode).

But you can add "--keyword=gettext_noop" to your xgettext arguments, and use it to export the translatable strings to your .pot file by adding these lines to the code:

gettext_noop("_Edit");
gettext_noop("_Copy");
gettext_noop("_Paste");


xgettext will capture the strings, and they'll be replaced in the UI thanks to Gtk.Builder's gettext integration.

Frank Dana <ferdnyc>
Thu 27 Jul 2023 09:27:05 AM UTC, original submission:  

In GIMP there are some strings in a gtk.Builder ui xml embedded as a string in a C file. That is used with Gtk.builder.new_from_string to make a menu. ( https://gitlab.gnome.org/GNOME/gimp/-/blob/master/plug-ins/imagemap/imap_main.c )

The contents of this string do not get extracted by my usual xgettext flags [1], and if I instead use -a to extract all it returns that whole xml as a single string, not only parts marked "translatable".

Same thing can be seen with this example code from gtk: https://developer-old.gnome.org/gtk4/stable/GtkApplicationWindow.html

Attached file is that example with a string added outside the xml to demonstrate that only the string outside the xml is extracted.

Is there some way to extract only the labels marked translatable out of the xml rather than the whole xml? Or is that unimplemented? Moving that xml to another file makes extraction work as expected, so the problem is probably that all the xml is in a single string.




[1] xgettext gettext_extract_example.c --from-code utf-8 --add-comments --output gimp.pot --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 --keyword=g_dcgettext:2 --keyword=g_dngettext:2,3 --keyword=g_dpgettext2:2c,3 --flag=N_:1:pass-c-format --flag=C_:2:pass-c-format --flag=NC_:2:pass-c-format --flag=g_dngettext:2:pass-c-format --flag=g_strdup_printf:1:c-format --flag=g_string_printf:2:c-format --flag=g_string_append_printf:2:c-format --flag=g_error_new:3:c-format --flag=g_set_error:4:c-format --msgid-bugs-address https://gitlab.gnome.org/GNOME/gimp/issues

Anders Jonsson <haaninjo>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by haible (Posted a comment)
  • -email is unavailable- added by ferdnyc (Posted a comment)
  • -email is unavailable- added by haaninjo (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-11-07 haible StatusNone Confirmed
    2023-07-27 haaninjo Attached File- Added gettext_extract_example.c, #54976

    Back to the top

    Powered by Savane 3.13-c54d.
    Corresponding source code