What I want to do is make my GUI startable in different languages. I would input a parameter when starting the gui (e.g. perl gui.pl english) and when initialising the widgets it would get the text from a xml file that looks like this:

<?xml version="1.0"?> <language> <english> <widget ID="1">input</widget> <widget ID="2">output</widget> </english> <deutsch> <widget ID="1">eingabe</widget> <widget ID="2">ausgabe</widget> </deutsch> </language>

in the text setting of widgets i call a function with the widget id as a parameter.

sub change_lang { my $id= shift; my $file='lang.xml'; my $result; my $parser = XML::LibXML->new(); my $tree = $parser->parse_file($file); $result=$tree->findnodes("/language/$language/widget[@ID="$id"]"); return $result; }

but that doesnt work ("global symbol @ID requires explicit package name"). I don't know how to get to the content of the xml with scalars in the findnodes path. how would i do this? If anyone has better ideas for implementing language change, I'd be open for it, too. I'm too much of a perl scrub.


In reply to language selection via libxml by banzai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.