NAME
Log::Report::Translator - base implementation for translating messages
INHERITANCE
Log::Report::Translator is extended by
Log::Report::Translator::Gettext
Log::Report::Translator::POT
SYNOPSIS
# internal infrastructure
my $msg = Log::Report::Message->new(_msgid => "Hello World\n");
print Log::Report::Translator->new(...)->translate($msg);
# normal use
textdomain 'my-domain'
, translator => Log::Report::Translator->new; # default
print __"Hello World\n";
DESCRIPTION
A module (or distribution) has a certain way of translating messages, usually gettext
. The translator is based on some textdomain
for the message, which can be specified as option per text element, but usually is package scoped.
This base class does not translate at all: it will use the MSGID (and MSGID_PLURAL if available). It's a nice fallback if the language packs are not installed.
METHODS
Constructors
- Log::Report::Translator->new(%options)
-
-Option --Default charset <from locale> lexicons <see text>
- charset => STRING
-
When the locale contains a codeset in its name, then that will be used. Otherwise, the default is
utf-8
. - lexicons => DIRECTORY|ARRAY-of-DIRECTORYs
-
The DIRECTORY where the translations can be found. See Log::Report::Lexicon::Index for the expected structure of such DIRECTORY.
The default is based on the location of the module which instantiates this translator. The filename of the module is stripped from its
.pm
extension, and used as directory name. Within that directory, there must be a directory namedmessages
, which will be the root directory of a Log::Report::Lexicon::Index.
example: default lexicon directory
# file xxx/perl5.8.8/My/Module.pm use Log::Report 'my-domain' , translator => Log::Report::Translator::POT->new; # lexicon now in xxx/perl5.8.8/My/Module/messages/
Accessors
- $obj->charset()
-
Returns the default charset, which can be overrule by the locale.
- $obj->lexicons()
-
Returns a list of Log::Report::Lexicon::Index objects, where the translation files may be located.
Translating
- $obj->load($domain, $locale)
-
Load the translation information in the text $domain for the indicated $locale. Multiple calls to load() should not cost significant performance: the data must be cached.
- $obj->translate( $message, [$language, $ctxt] )
-
Returns the translation of the $message, a
Log::Report::Message
object, based on the current locale.Translators are permitted to peek into the internal HASH of the message object, for performance reasons.
SEE ALSO
This module is part of Log-Report distribution version 1.05, built on June 24, 2014. Website: http://perl.overmeer.net/log-report/
LICENSE
Copyrights 2007-2014 by [Mark Overmeer]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html