NAME

Locale::Maketext::TieHash::L10N - Tying language handle to a hash

SYNOPSIS

use strict;
use Locale::Maketext::TieHash::L10N;
tie my %mt, 'Locale::Maketext::TieHash::L10N';
{ use MyProgram::L10N;
  my $lh = MyProgram::L10N->get_handle() || die "What language?";
  # store language handle
  $mt{L10N} = $lh;
}
# store option numf_comma
$mt{numf_comma} = 1;
...
print qq~$mt{Example}:\n$mt{["Can't open file [_1]: [_2].", $f, $!]}\n~;

The way without this module - You better see the difference.

use strict;
use MyProgram::L10N;
my $lh = MyProgram::L10N->get_handle() || die "What language?";
$lh{numf_comma} = 1;
...
print $lh->maketext('Example') . ":\n" . $lh->maketext("Can't open file [_1]: [_2].", $f, $!) . "\n";
...

Example for writing HTML

use strict;
use Locale::Maketext::TieHash::L10N;
tie my %mt, 'Locale::Maketext::TieHash::L10N';
{ use MyProgram::L10N;
  my $lh = MyProgram::L10N->get_handle() || die "What language?";
  # store language handle
  $mt{L10N} = $lh;
}
# store option numf_comma and set the nbsp_flag to '~';
@mt{qw/numf_comma nbsp_flag/} = qw/1 ~/;
# If you want to test your Script, you set "nbsp" on a string which you see in the Browser.
$mt{nbsp} = '<span style="color:red">§</span>';
...
# The browser shows value and unity always on a line.
print qq#$mt{["Put [*,_1,~component,~components,no component] together, then have [*,_2,~piece,~pieces,no piece] of equipment.", $component, $piece]}\n#;

get the language handle "L10N", "nbsp" and/or "nbsp_flag" back

# You can get the language handle "L10N", "nbsp" and/or "nbsp_flag" back on this way.
my ($lh, $nbsp, $nbsp_flag) = tied(%mt)->Get(qw/L10N nbsp nbsp_flag/);
# You can get the keys "L10N", "nbsp" and "nbsp_flag" back on this way.
my @keys = tied(%mt)->Keys();
# You can get the values of "L10N", "nbsp" and "nbsp_flag" back on this way.
my @values = tied(%mt)->Values();
# This is the way to store values of keys in another tyed hash like %mt.
my %hash;
@hash{tied(%mt)->Keys} = tied(%mt)->Values;

DESCRIPTION

Object methods like "maketext" don't have interpreted into strings. The module ties the language handle to a hash. The object method "maketext" is executed at fetch hash. At long last this is the same, only the notation is shorter.

Sometimes the object method "maketext" expects more than 1 parameter. Then submit a reference on an array as hash key.

If you write HTML text with "Locale::Maketext", it then can happen that value and unity stand on separate lines. The "nbsp_flag" prevents the line break. The "nbsp_flag" per default is undef and this functionality is switched off. Set your choice this value on a character string. For switching the functionality off, set the value to undef or a character string of the length 0. "nbsp" per default is "&nbsp;".

SEE ALSO

Locale::Maketext

AUTHOR

Steffen Winkler, <cpan@steffen-winkler.de>

COPYRIGHT AND LICENSE

Copyright (C) 2004, 2005 by Steffen Winkler

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 122:

Non-ASCII character seen before =encoding in 'style="color:red">§</span>';'. Assuming CP1252