perl-unicode

Re: Interesting idea for string resources

2001-09-28 19:36:29
From: "James Briggs" <james(_at_)rf(_dot_)net>
print qL(The weather is $skycover today.);


I guess qL would be the equivalent of

# 1) some sort of lookup that returns the translated string
#     with the $skycover not yet expanded
#    trivial example of a lookup:
$localized = $localization_hash{'The weather is $skycover today.'};
# 2) variable expansion
#     (three cheers for the faq writers!)
$localized =~  s/(\$\w+)/$1/eeg;

I would like an operator for in-place variable expansion! The translation
lookup part is relatively trivial. And there are a zillion ways to do it
already.

Here's a brief example (German from Babelfish!):

#! perl -w

$the_weather = 'The weather is $skycover today.';
$skycover = "sunny";

%localization_hash = ( 'The weather is $skycover today.'
                         => 'Das Wetter ist heute $skycover.',
                       'sunny' => 'sonnig' );

$the_weather = $localization_hash{$the_weather};
$skycover = $localization_hash{$skycover};

$the_weather =~ s/(\$\w+)/$1/eeg;

print "$the_weather\n";

#output: "Das Wetter ist heute sonnig."

The package name could be concatenated with the English string to improve
context:

$the_weather = __PACKAGE__ . 'The weather is $skycover today.';

=Ed


<Prev in Thread] Current Thread [Next in Thread>