I22r::Translate::Filter - Role for translation filters.
To use a Filter on all translations
I22r::Translate->config( filter => [ filter1, filter2, ... ], ... other config ... )
To use a Filter with a specific backend
I22r::Translate->config( 'My::Backend' => { filter => [ filter3, ... ], ... other backend config ... } ... other global config ... }
To use a Filter on a specific translation request
I22r::Translate->translate_string( src => ..., dest => ..., text => ..., filter => [ filter4, ... ] );
(the filter option is also recognized with the I22r::Translate->translate_list or I22r::Translate->translate_hash methods.
filter
I22r::Translate->translate_list
I22r::Translate->translate_hash
Sometimes you do not want to pass a piece of text directly to a translation engine. The text might contain HTML tags or other markup. It might contain proper nouns or other words that you don't intend to translate. Classes that implement the I22r::Translate::Filter role can be used to adjust the text before it is passed to a translation engine, and to unadjust the translator's output.
I22r::Translate::Filter
Accepts a I22r::Translate::Request object and a key from the input. Sanitizes $req->text->{$key} for use in a translation backend and keeps a record of what modifications were made, so they can be unmade in the "unapply" method on the translator output.
$req->text->{$key}
Modifies backend output in $req->results->{$key}->text to restore whatever changes were made to the backend input in the "apply" method.
$req->results->{$key}->text
A new filter must implement the apply and unapply methods. The filter must track the modifications made to input in the apply method, including the correct order of modifications, so that those modifications may be undone in the correct order in the unapply method.
apply
unapply
The source code for the I22r::Translate::Filter::Literal and I22r::Translate::Filter::HTML filters are currently the best places to look for examples of how this can be done.
I22r::Translate, I22r::Translate::Filter::Literal, I22r::Translate::Filter::HTML
To install I22r::Translate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm I22r::Translate
CPAN shell
perl -MCPAN -e shell install I22r::Translate
For more information on module installation, please visit the detailed CPAN module installation guide.