NAME
Locale::Maketext::TieHash::quant - Tying method quant to a hash
SYNOPSIS
if you don't use Locale::Maketext::TieHash::L10N
use strict;
use Locale::Maketext::TieHash::quant;
tie my %quant, 'Locale::Maketext::TieHash::quant';
{ use MyProgram::L10N;
my $lh = MyProgram::L10N->get_handle() || die "What language?";
# store language handle
$quant{L10N} = $lh;
}
# store option numf_comma
$quant{numf_comma} = 1;
...
# if you use HTML
# store "nbsp_flag", "auto_nbsp_flag1" and "auto_nbsp_flag2"
@quant{qw/nbsp_flag auto_nbsp_flag1 auto_nbsp_flag2/} = qw(~ 1 1);
...
my $part = 5000.5;
print qq~$mt{Example}:\n$quant{$part.' '.$lh->maketext('part,parts,no part')}\n~;
if you use Locale::Maketext::TieHash::L10N
use strict;
use Locale::Maketext::TieHash::L10N;
tie my %mt, 'Locale::Maketext::TieHash::L10N';
use Locale::Maketext::TieHash::quant;
tie my %quant, 'Locale::Maketext::TieHash::quant';
{ 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;
# only if you use HTML: store option nbsp_flag
$mt{nbsp_flag} = '~';
# copy settings
@quant{tied(%mt)->Keys} = tied(%mt)->Values;
...
# if you use HTML
# store option auto_nbsp_flag1 and auto_nbsp_flag2
@quant{qw/auto_nbsp_flag1 auto_nbsp_flag2/} = (1, 1);
...
my $part = 5000.5;
print qq~$mt{Example}:\n$quant{"$part $mt{'part,parts,no part'}"}\n~;
get the language handle "
L10N"
, "
nbsp"
, "
nbsp_flag"
, "
auto_nbsp_flag1"
and/or "
auto_nbsp_flag2"
back
# You can get the language handle "L10N", "nbsp", "nbsp_flag", "auto_nbsp_flag1" and/or "auto_nbsp_flag2" back on this way.
my ($lh, $nbsp, $nbsp_flag, $auto_nbsp_flag1, $auto_nbsp_flag2) = tied(%quant)->Get(qw/L10N nbsp nbsp_flag auto_nbsp_flag1 auto_nbsp_flag2/);
DESCRIPTION
Object methods like quant don't have interpreted into strings. The module ties the method quant to a hash. The object method quant is executed at fetch hash. At long last this is the same, only the notation is shorter.
You can use the module also without Locale::Maketext::TieHash::L10N. Whether this is better for you, have decide you.
METHODS
TIEHASH
use Locale::Maketext::TieHash::quant;
tie my %quant, 'Locale::Maketext::TieHash::quant';
"
TIEHASH"
ties your hash and set options defaults.
STORE
"
STORE"
stores the language handle or options.
# store the language handle
$quant{L10N} = $lh;
# store option of language handle
$quant{numf_comma} = 1;
# the same is:
$lh->{numf_comma} = 1;
# only for debugging your HTML response
$quant{nbsp} = 'see_position_of_nbsp_in_HTML_response'; # default is ' '
# Set a flag to say:
# Substitute the whitespace before this flag and this flag to ' ' or your debugging string.
# The "nbsp_flag" is a string (1 or more characters).
$quant{nbsp_flag} = '~';
# You get the string "singular,plural,negative" from any data base.
$quant{auto_nbsp_flag1} = 1; # As if the "nbsp_flag" in front of "singular" would stand.
$quant{auto_nbsp_flag2} = 1; # As if the "nbsp_flag" in front of "plural" would stand.
The method calls croak, if the key of your hash is undef or your key isn't correct and if the value, you set to option "
nbsp"
, is undef.
FETCH
"
FETCH"
quantifying the given key of your hash and give back the translated string as value.
# quantifying
print $quant{"$number singular,plural,negative"};
# the same is:
print $lh->quant($number, 'singular', 'plural', 'negative');
...
# Use "nbsp" and "nbsp_flag", "auto_nbsp_flag1" and "auto_nbsp_flag2" are true.
print $quant{"$number singular,plural,negative"};
# the same is:
my $result = $lh->quant($number, '~'.'singular', '~'.'plural', 'negative');
$result =~ s/ ~/ /g; # But not a global debugging function is available.
The method calls croak, if the method "
quant"
of your stored language handle dies.
Get
Submit 1 key or more. The method "
Get"
give you the values back.
The method calls croak if a key is undef or unknown.
SEE ALSO
Tie::Hash
Locale::Maketext
Locale::Maketext::TieHash::L10N
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.