If make a simple example to translate the hompage with a template.
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 |
#!/usr/bin/perl use strict; #example html my $html = q( <H1>(@T1@)</H1> <p>(@T2@)</p> ); #translate german my %GER = ( T1 => 'Uberschrift', T2 => 'Inhalt', ); #translate english my %ENG = ( T1 => 'Title', T2 => 'Content', ); #tests print interpolate($html,%GER).$/; print interpolate($html,%ENG).$/; #interpolate sub interpolate { my ($var,$hash) = @_; foreach my $search (sort {length($hash->{$a}) <= length($hash->{$b})} keys $hash) { $var =~ s!(@$search@)!$hash->{$search}!g; } $var =~ s!(@.{1,}@)!?!go; return($var); } |
The HTML code result looks like this:
1 2 3 4 5 6 |
<H1>Uberschrift</H1> <p>Inhalt</p> <H1>Title</H1> <p>Content</p> |
in the Browser it looks like this:
Uberschrift
Inhalt
Title
Content
My brother suggested I may like this website. He
View Commentwas once totally right. This put up truly made my day.
You can not imagine just how so much time I had spent for this info!
Thank you!