.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.37
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Locale::Maketext::Fuzzy 3"
.TH Locale::Maketext::Fuzzy 3 "2007-10-13" "perl v5.8.8" "User Contributed Perl Documentation"
.SH "NAME"
Locale::Maketext::Fuzzy \- Maketext from already interpolated strings
.SH "VERSION"
.IX Header "VERSION"
This document describes version 0.10 of Locale::Maketext::Fuzzy, released
October 14, 2007.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 2
\& package MyApp::L10N;
\& use base 'Locale::Maketext::Fuzzy'; # instead of Locale::Maketext
.Ve
.PP
.Vb 6
\& package MyApp::L10N::de;
\& use base 'MyApp::L10N';
\& our %Lexicon = (
\& # Exact match should always be preferred if possible
\& "0 camels were released."
\& => "Exact match",
.Ve
.PP
.Vb 3
\& # Fuzzy match candidate
\& "[quant,_1,camel was,camels were] released."
\& => "[quant,_1,Kamel wurde,Kamele wurden] freigegeben.",
.Ve
.PP
.Vb 4
\& # This could also match fuzzily, but is less preferred
\& "[_2] released[_1]"
\& => "[_1][_2] ist frei[_1]",
\& );
.Ve
.PP
.Vb 2
\& package main;
\& my $lh = MyApp::L10N->get_handle('de');
.Ve
.PP
.Vb 2
\& # All ->maketext calls below will become ->maketext_fuzzy instead
\& $lh->override_maketext(1);
.Ve
.PP
.Vb 2
\& # This prints "Exact match"
\& print $lh->maketext('0 camels were released.');
.Ve
.PP
.Vb 2
\& # "1 Kamel wurde freigegeben." -- quant() gets 1
\& print $lh->maketext('1 camel was released.');
.Ve
.PP
.Vb 2
\& # "2 Kamele wurden freigegeben." -- quant() gets 2
\& print $lh->maketext('2 camels were released.');
.Ve
.PP
.Vb 2
\& # "3 Kamele wurden freigegeben." -- parameters are ignored
\& print $lh->maketext('3 released.');
.Ve
.PP
.Vb 2
\& # "4 Kamele wurden freigegeben." -- normal usage
\& print $lh->maketext('[*,_1,camel was,camels were] released.', 4);
.Ve
.PP
.Vb 3
\& # "!Perl ist frei!" -- matches the broader one
\& # Note that the sequence ([_2] before [_1]) is preserved
\& print $lh->maketext('Perl released!');
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module is a subclass of \f(CW\*(C`Locale::Maketext\*(C'\fR, with additional
support for localizing messages that already contains interpolated
variables.
.PP
This is most useful when the messages are returned by external sources
\&\*(-- for example, to match \f(CW\*(C`dir: command not found\*(C'\fR against
\&\f(CW\*(C`[_1]: command not found\*(C'\fR.
.PP
Of course, this module is also useful if you're simply too lazy
to use the
.PP
.Vb 1
\& $lh->maketext("[quant,_1,file,files] deleted.", $count);
.Ve
.PP
syntax, but wish to write
.PP
.Vb 1
\& $lh->maketext_fuzzy("$count files deleted");
.Ve
.PP
instead, and have the correct plural form figured out automatically.
.PP
If \f(CW\*(C`maketext_fuzzy\*(C'\fR seems too long to type for you, this module
also provides a \f(CW\*(C`override_maketext\*(C'\fR method to turn \fIall\fR \f(CW\*(C`maketext\*(C'\fR
calls into \f(CW\*(C`maketext_fuzzy\*(C'\fR calls.
.SH "METHODS"
.IX Header "METHODS"
.Sh "$lh\->maketext_fuzzy(\fIkey\fP[, \fIparameters...\fP]);"
.IX Subsection "$lh->maketext_fuzzy(key[, parameters...]);"
That method takes exactly the same arguments as the \f(CW\*(C`maketext\*(C'\fR method
of \f(CW\*(C`Locale::Maketext\*(C'\fR.
.PP
If \fIkey\fR is found in lexicons, it is applied in the same way as
\&\f(CW\*(C`maketext\*(C'\fR. Otherwise, it looks at all lexicon entries that could
possibly yield \fIkey\fR, by turning \f(CW\*(C`[...]\*(C'\fR sequences into \f(CW\*(C`(.*?)\*(C'\fR and
match the resulting regular expression against \fIkey\fR.
.PP
Once it finds all candidate entries, the longest one replaces the
\&\fIkey\fR for the real \f(CW\*(C`maketext\*(C'\fR call. Variables matched by its bracket
sequences (\f(CW$1\fR, \f(CW$2\fR...) are placed before \fIparameters\fR; the order
of variables in the matched entry are correctly preserved.
.PP
For example, if the matched entry in \f(CW%Lexicon\fR is \f(CW\*(C`Test [_1]\*(C'\fR,
this call:
.PP
.Vb 1
\& $fh->maketext_fuzzy("Test string", "param");
.Ve
.PP
is equivalent to this:
.PP
.Vb 1
\& $fh->maketext("Test [_1]", "string", "param");
.Ve
.PP
However, most of the time you won't need to supply \fIparameters\fR to
a \f(CW\*(C`maketext_fuzzy\*(C'\fR call, since all parameters are already interpolated
into the string.
.Sh "$lh\->override_maketext([\fIflag\fP]);"
.IX Subsection "$lh->override_maketext([flag]);"
If \fIflag\fR is true, this accessor method turns \f(CW\*(C`$lh\->maketext\*(C'\fR
into an alias for \f(CW\*(C`$lh\->maketext_fuzzy\*(C'\fR, so all consecutive
\&\f(CW\*(C`maketext\*(C'\fR calls in the \f(CW$lh\fR's packages are automatically fuzzy.
A false \fIflag\fR restores the original behaviour. If the flag is not
specified, returns the current status of override; the default is
0 (no overriding).
.PP
Note that this call only modifies the symbol table of the \fIlanguage
class\fR that \f(CW$lh\fR belongs to, so other languages are not affected.
If you want to override all language handles in a certain application,
try this:
.PP
.Vb 1
\& MyApp::L10N->override_maketext(1);
.Ve
.SH "CAVEATS"
.IX Header "CAVEATS"
.IP "\(bu" 4
The \*(L"longer is better\*(R" heuristic to determine the best match is
reasonably good, but could certainly be improved.
.IP "\(bu" 4
Currently, \f(CW"[quant,_1,file] deleted"\fR won't match \f(CW"3 files deleted"\fR;
you'll have to write \f(CW"[quant,_1,file,files] deleted"\fR instead, or
simply use \f(CW"[_1] file deleted"\fR as the lexicon key and put the correct
plural form handling into the corresponding value.
.IP "\(bu" 4
When used in combination with \f(CW\*(C`Locale::Maketext::Lexicon\*(C'\fR's \f(CW\*(C`Tie\*(C'\fR
backend, all keys would be iterated over each time a fuzzy match is
performed, and may cause serious speed penalty. Patches welcome.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Locale::Maketext, Locale::Maketext::Lexicon
.SH "HISTORY"
.IX Header "HISTORY"
This particular module was written to facilitate an \fIauto-extraction\fR
layer for Slashcode's \fITemplate Toolkit\fR provider, based on
\&\f(CW\*(C`HTML::Parser\*(C'\fR and \f(CW\*(C`Template::Parser\*(C'\fR. It would work like this:
.PP
.Vb 2
\& Input | from the [% story.dept %] dept.
\& Output| [%|loc( story.dept )%]from the [_1] dept.[%END%]
.Ve
.PP
Now, this layer suffers from the same linguistic problems as an
ordinary \f(CW\*(C`Msgcat\*(C'\fR or \f(CW\*(C`Gettext\*(C'\fR framework does \*(-- what if we want
to make ordinates from \f(CW\*(C`[% story.dept %]\*(C'\fR (i.e. \f(CW\*(C`from the 3rd dept.\*(C'\fR),
or expand the \f(CW\*(C`dept.\*(C'\fR to \f(CW\*(C`department\*(C'\fR / \f(CW\*(C`departments\*(C'\fR?
.PP
The same problem occurred in \s-1RT\s0's web interface, where it had to
localize messages returned by external modules, which may already
contain interpolated variables, e.g. \f(CW\*(C`"Successfully deleted 7
ticket(s) in 'c:\etemp'."\*(C'\fR.
.PP
Since I didn't have the time to refactor \f(CW\*(C`DBI\*(C'\fR and \f(CW\*(C`DBI::SearchBuilder\*(C'\fR,
I devised a \f(CW\*(C`loc_match\*(C'\fR method to pre-process their messages into one
of the \fIcandidate strings\fR, then applied the matched string to \f(CW\*(C`maketext\*(C'\fR.
.PP
Afterwards, I realized that instead of preparing a set of candidate
strings, I could actually use the original \fIlexicon file\fR (i.e. \s-1PO\s0 files
via \f(CW\*(C`Locale::Maketext::Lexicon\*(C'\fR) to match against. This is how
\&\f(CW\*(C`Locale::Maketext::Fuzzy\*(C'\fR was born.
.SH "AUTHORS"
.IX Header "AUTHORS"
Audrey Tang
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright 2002, 2007 by Audrey Tang .
.PP
This software is released under the \s-1MIT\s0 license cited below.
.ie n .Sh "The ""\s-1MIT\s0"" License"
.el .Sh "The ``\s-1MIT\s0'' License"
.IX Subsection "The MIT License"
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the \*(L"Software\*(R"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
.PP
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
.PP
\&\s-1THE\s0 \s-1SOFTWARE\s0 \s-1IS\s0 \s-1PROVIDED\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R", \s-1WITHOUT\s0 \s-1WARRANTY\s0 \s-1OF\s0 \s-1ANY\s0 \s-1KIND\s0, \s-1EXPRESS\s0
\&\s-1OR\s0 \s-1IMPLIED\s0, \s-1INCLUDING\s0 \s-1BUT\s0 \s-1NOT\s0 \s-1LIMITED\s0 \s-1TO\s0 \s-1THE\s0 \s-1WARRANTIES\s0 \s-1OF\s0 \s-1MERCHANTABILITY\s0,
\&\s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0 \s-1AND\s0 \s-1NONINFRINGEMENT\s0. \s-1IN\s0 \s-1NO\s0 \s-1EVENT\s0 \s-1SHALL\s0
\&\s-1THE\s0 \s-1AUTHORS\s0 \s-1OR\s0 \s-1COPYRIGHT\s0 \s-1HOLDERS\s0 \s-1BE\s0 \s-1LIABLE\s0 \s-1FOR\s0 \s-1ANY\s0 \s-1CLAIM\s0, \s-1DAMAGES\s0 \s-1OR\s0 \s-1OTHER\s0
\&\s-1LIABILITY\s0, \s-1WHETHER\s0 \s-1IN\s0 \s-1AN\s0 \s-1ACTION\s0 \s-1OF\s0 \s-1CONTRACT\s0, \s-1TORT\s0 \s-1OR\s0 \s-1OTHERWISE\s0, \s-1ARISING\s0
\&\s-1FROM\s0, \s-1OUT\s0 \s-1OF\s0 \s-1OR\s0 \s-1IN\s0 \s-1CONNECTION\s0 \s-1WITH\s0 \s-1THE\s0 \s-1SOFTWARE\s0 \s-1OR\s0 \s-1THE\s0 \s-1USE\s0 \s-1OR\s0 \s-1OTHER\s0
\&\s-1DEALINGS\s0 \s-1IN\s0 \s-1THE\s0 \s-1SOFTWARE\s0.