Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Gtk stock button translation

by mtl3 (Novice)
on Mar 07, 2018 at 21:09 UTC ( #1210480=perlquestion: print w/replies, xml ) Need Help??
mtl3 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I use stock buttons to design a perl/Gtk2 GUI. I am looking for a way to put the labels of these buttons in a different language. As far as I could understand from http://gtk2-perl.sourceforge.net/doc/gtk2-perl-study-guide/c1227.html, Gtk2::Stock provides a method that looks to do exactly what I want:

Gtk2::Stock->set_translate_func ($domain, $func, $data=undef)

Unfortunately, the documentation (or I should say the absence of documentation) has left me clueless.

May I request the help of a Monk to provide with a wise example and teaching?

Thanks

Replies are listed 'Best First'.
Re: Gtk stock button translation
by syphilis (Chancellor) on Mar 08, 2018 at 00:38 UTC
    Unfortunately, the documentation (or I should say the absence of documentation) has left me clueless

    Did you grab the demo program from the page you linked to ?

    The relevant part is:
    #create a vbox that will contain all the stock buttons my $vbox_stock = Gtk2::VBox->new(FALSE,5); foreach my $val(sort Gtk2::Stock->list_ids){ my $btn_stock = Gtk2::Button->new_from_stock($val); $vbox_stock->pack_start($btn_stock,FALSE,FALSE,4); }
    I changed that to:
    #create a vbox that will contain all the stock buttons my $vbox_stock = Gtk2::VBox->new(FALSE,5); foreach my $val(sort Gtk2::Stock->list_ids){ print "$val\n"; # List available stock buttons if($val eq 'gtk-add' || $val eq 'gtk-cancel') { my $btn_stock = Gtk2::Button->new_from_stock($val); $vbox_stock->pack_start($btn_stock,FALSE,FALSE,4); } }
    On perl-5.26.0, for me that modification behaves as expected and creates only the "Add" and "Cancel" buttons (with labels).
    My understanding is that those labels will be written in the language that the computer's locale setting specifies.

    Hopefully you can utilise that demo program to help achieve your desired result.
    If not, you could try the gtk-perl mailing list if you can't get good help here.

    For me, on an older version of perl (5.16.0) the same demo (both original and modified) provided the buttons with labels only (no icons).
    Same versions of Gtk and Gtk2 modules. Either a difference in perl itself, or something different in the environments.

    Cheers,
    Rob
      Thank you Rob.

      Yes, the demo "works" on my machine to (also running perl 5.26) in that sense that both icons and labels are displayed. The point of my question was to have the labelled translated (in my case in French). Interestingly, you mention that the translation should happen automatically based on the computer's local settings. If you can confirm that, this would mean that I may need to investigate my gtk install rather than my perl code, which was actually an alternative I had in mind too.

      So could you please confirm that the translation should be triggered automatically via the computer settings (have you observed it)? This would help me moving forward.

      Cheers
        So could you please confirm that the translation should be triggered automatically via the computer settings (have you observed it)?

        I haven't observed it - it's just that, in relation to Gtk2::Stock buttons, the documentation says "the label changes according to your language settings, making internationalization easier".
        However, thinking about that a bit more, it doesn't necessarily mean that changing those labels to French (on your computer) is as easy as changing your computer's language setting to French.
        Having reset your computer's language to French, you might also have to reinstall your gtk libraries and/or rebuild Gtk2. I don't know.

        But I do think the documentation is telling us that, if you run that demo script on a computer whose language setting has always been French, then the labels will be in French.

        More authoritative information can probably be obtained from the gtk-perl mailing list.

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1210480]
Approved by marto
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2018-07-20 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (424 votes). Check out past polls.

    Notices?