Locale::Maketext::TieHash::quant - Tying method quant to a hash |
Locale::Maketext::TieHash::quant - Tying method quant to a hash
0.06
use strict; use warnings;
use Carp qw(croak); use Locale::Maketext::TieHash::quant; use MyProgram::L10N;
my %quant;
my $lh = MyProgram::L10N->get_handle('de_DE') or croak 'What language?';
# tie and configure tie %quant, 'Locale::Maketext::TieHash::quant', ( L10N => $lh, # save language handle numf_comma => 1, # set option numf_comma );
# if you use HTML # configure 'nbsp_flag', 'auto_nbsp_flag1' and 'auto_nbsp_flag2' tied(%quant)->config( nbsp_flag => '~', # set flag to mark whitespaces auto_nbsp_flag1 => 1, # set flag to use 'nbsp_flag' at the singular automatically auto_nbsp_flag2 => 1, # set flag to use 'nbsp_flag' at the plural automatically # If you want to test your Script, # you set 'nbsp' on a string which you see in the Browser. nbsp => '<span style="color:red">*</span>', );
my $part = 5000.5; print <<"EOT"; @{[ $lh->maketext('Example') ]} $quant{ $part . q{ } . $lh->maketext('part,parts,no part') } EOT
use strict; use warnings;
use Carp qw(croak); use Locale::Maketext::TieHash::L10N; use Locale::Maketext::TieHash::quant; use MyProgram::L10N;
my %mt; { my $lh = MyProgram::L10N->get_handle('de_DE') or croak 'What language?'; tie %mt, 'Locale::Maketext::TieHash::L10N', ( L10N => $lh, numf_comma => 1, ); }
tie my %quant, 'Locale::Maketext::TieHash::quant'; tied(%quant)->config( # get back and set language handle and option # only if you use HTML L10N => { tied(%mt)->config() }->{L10N}, nbsp_flag => '~', auto_nbsp_flag1 => 1, auto_nbsp_flag2 => 1, );
my $part = 5000.5; print <<"EOT"; $mt{Example} $quant{"$part $mt{'part,parts,no part'}"} EOT
my %config = tied(%quant)->config();
my %config = tied(%quant)->config( numf_comma => 0, nbsp_flag => q{}, );
Inside of this Distribution is a directory named example. Run this *.pl files.
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.
use Locale::Maketext::TieHash::quant; tie my %quant, 'Locale::Maketext::TieHash::quant', %config;
'TIEHASH' ties your hash and set options defaults.
'config' configures the language handle and/or options.
# configure the language handle tied(%quant)->config(L10N => $lh);
# configure option of language handle tied(%quant)->config(numf_comma => 1); # the same is: $lh->{numf_comma} = 1;
# only for debugging your HTML response tied(%quant)->config( 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). tied(%quant)->config(nbsp_flag => '~');
# You get the string 'singular,plural,zero' from any data base. # - As if the 'nbsp_flag' in front of 'singular' would stand. tied(%quant)->config(auto_nbsp_flag1 => 1); # - As if the 'nbsp_flag' in front of 'plural' would stand. tied(%quant)->config(auto_nbsp_flag2 => 1);
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.
'config' accepts all parameters as Hash and gives a Hash back with all attitudes.
'FETCH' is quantifying the given key of your hash and give back the translated string as value.
# quantifying print $quant{"$number singular,plural,zero"}; # the same is: print $lh->quant($number, 'singular', 'plural', 'zero'); ... # Use 'nbsp' and 'nbsp_flag', 'auto_nbsp_flag1' and 'auto_nbsp_flag2' are true. print $quant{"$number singular,plural,zero"}; # the same is: my $result = $lh->quant($number, '~' . 'singular', '~' . 'plural', 'zero'); $result =~ s{[ ] ~}{ }xmsg; # But not a global debugging function is available.
The method calls croak, if the method 'quant' of your stored language handle dies.
All methods can croak at false parameters.
nothing
Carp
English
not known
not known
Locale::Maketext::TieHash::L10N
Steffen Winkler
Copyright (c) 2004 - 2010,
Steffen Winkler
<steffenw at cpan.org>
.
All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Locale::Maketext::TieHash::quant - Tying method quant to a hash |