1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
use strict; use warnings; use Tk; my $lang = 0; my $mw = Tk::MainWindow->new(-title=>"language support"); $mw->geometry("100x100"); my @menulanguages =("sprache","language"); #menubar my $menubar = $mw->Menu(-relief => 'flat'); $mw->configure(-menu => $menubar); my $menu_lang = $menubar->cascade(-label => "$menulanguages[$lang]"); my $german_radio_menu = $menu_lang->radiobutton(-label=>"deutsch", -variable=>\$lang, -value=>0, -command=>\&update_mw); my $english_radio_menu = $menu_lang->radiobutton(-label=>"english", -variable=>\$lang, -value=>1, -command=>\&update_mw); #button my @buttonlanguages =("Klick mich","Click me"); my $mybutton = $mw->Button(-text=>"$buttonlanguages[$lang]")->pack(); Tk::MainLoop(); sub update_mw { $mw->update(); # $menu_lang->configure(-label=>"$menulanguages[$lang]"); # $mybutton->configure(-text=>"$buttonlanguages[$lang]"); }
$mw->update()
2012-06-27T11:13:09 DrMaexVielen Dank, dann werde ich wohl in den sauren Apfel beissen müssen und den weg über "configure" gehen.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!perl
use strict;
use warnings;
use utf8;
use Tk;
my $map = {
'de' => {
btn_click_me => 'Klick mich',
},
'en' => {
btn_click_me => 'Cleck me',
}
};
my $lang = 'de';
my $mw = Tk::MainWindow->new(-title=>"language support");
$mw->geometry("100x100");
my @menulanguages =("de","en");
my $menubar = $mw->Menu(-relief => 'flat');
$mw->configure(-menu => $menubar);
my $menu_lang = $menubar->cascade(-label => $lang);
$menu_lang->radiobutton(-label=> $_, -variable => \$lang, -value => $_, -command => \&update_window) for @menulanguages;
my $mybutton = $mw->Button(
-textvariable => \$map->{$lang}->{btn_click_me},
)->pack();
$mw->MainLoop();
sub update_window {
$mw->update();
} # /update_window
1 2 3 4 5 6 7 8 9 10 11 12
........ my $lang = 'de'; # default-Sprache my $btntext; update_window(); # Texte in default-Sprache ........ my $mybutton = $mw->Button( -textvariable => \$btntext, )->pack(); ........ sub update_window { # Texte in gewählter Sprache $btntext = $map->{$lang}->{btn_click_me}; } # /update_window
2012-06-28T21:54:59 pktmAh ok. Aber dann braucht man eine lexikalische Variable pro lokalisiertem Text. Ein Hash wäre mir natürlich lieber
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
........ my $lang = 'de'; # default-Sprache my %widgetinfo; my @allwidgets; ........ my $mybutton; my $btntxt = $map->{$lang}->{btn_click_me}; $mybutton = $mw->Button( -textvariable => \$btntxt, )->pack(); $widgetinfo{$mybutton} = [\$btntxt, 'btn_click_me']; push @allwidgets, $mybutton; ........ sub update_window { foreach my $mybutton (@allwidgets) { my ($txtvar_ref, $txtname) = @{$widgetinfo{$mybutton}}; $$txtvar_ref = $map->{$lang}->{$txtname}; } } # /update_window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use strict; use warnings; use Tk; my $lang = 0; my $mw = Tk::MainWindow->new(-title=>"language support"); $mw->geometry("100x100"); #menubar my $menubar = $mw->Menu(-relief => 'flat'); $mw->configure(-menu => $menubar); my @menulanguages =("sprache","language"); my $menu_lang = $menubar->cascade(-label => "$menulanguages[$lang]"); my $german_radio_menu = $menu_lang->radiobutton(-label=>"deutsch", -variable=>\$lang, -value=>0, -command=>\&update_mw); my $english_radio_menu = $menu_lang->radiobutton(-label=>"english", -variable=>\$lang, -value=>1, -command=>\&update_mw); #button my @buttonlanguages =("Klick mich","Click me"); my $buttonlabel = $buttonlanguages[$lang]; my $mybutton = $mw->Button(-textvariable=>\$buttonlabel)->pack(); Tk::MainLoop(); sub update_mw { $menu_lang->configure(-label => "$menulanguages[$lang]"); $buttonlabel = $buttonlanguages[$lang]; }