package Template::Flute::I18N; use strict; use warnings; =head1 NAME Template::Flute::I18N - Localization class for Template::Flute =head1 CONSTRUCTOR =head2 new [CODEREF] Create a new Template::Flute::I18N object. CODEREF is used by localize method for the text translation. =cut sub new { my ($proto, @args) = @_; my ($class, $self); $class = ref($proto) || $proto; $self = {}; if (ref($args[0]) eq 'CODE') { # use first parameter as localization function $self->{func} = shift(@args); } else { # noop translation $self->{func} = sub {return;} } bless ($self, $class); } =head1 METHODS =head2 localize STRING Calls localize function with provided STRING. The result is returned if it contains non blank characters. Otherwise the original STRING is returned. =cut sub localize { my ($self, $text) = @_; my ($trans); $trans = $self->{func}->($text); if (defined $trans && $trans =~ /\S/) { return $trans; } return $text; } =head1 AUTHOR Stefan Hornburg (Racke), =head1 LICENSE AND COPYRIGHT Copyright 2010-2011 Stefan Hornburg (Racke) . This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 1;