Returns a new object which copies info from original, and updates it with the specified %options and $variables. The advantage is that the cached translations are shared between the objects.
my $s = __x "found {nr} files", nr => 5; my $t = $s->clone(nr => 3); my $t = $s->(nr => 3); # equivalent print $s; # found 5 files print $t; # found 3 files
See Log::Report::Extract::Template on the details how to integrate Log::Report translations with Template::Toolkit (version 1 and 2)
End-users: do not use this method directly, but use Log::Report::__()
and friends. The %options is a mixed list of object initiation parameters
(all with a leading underscore) and variables to be filled in into the
translated _msgid
string.
Option | Default |
---|---|
_append |
|
_category |
|
_class | [] |
_classes | [] |
_context |
|
_count |
|
_domain | <from "use Log::Report"> |
_expand |
|
_join |
|
_lang | <from locale> |
_msgid |
|
_plural |
|
_prepend |
|
_to | <undef> |
Returns the string or Log::Report::Message object which is appended
after this one. Usually undef
.
Returns the LIST of classes which are defined for this message; message group indicators, as often found in exception-based programming.
Returns an HASH if there is a context defined for this message.
Returns the count, which is used to select the translation alternatives.
Returns the domain of the first translatable string in the structure.
Returns the msgid which will later be translated.
Returns the string which is prepended to this one. Usually undef
.
Returns the $name of a dispatcher if explicitly specified with the '_to' key. Can also be used to set it. Usually, this will return undef, because usually all dispatchers get all messages.
Lookup the named $parameter for the message. All pre-defined names have their own method which should be used with preference.
When the message was produced with
my @files = qw/one two three/; my $msg = __xn "found one file: {file}" , "found {nrfiles} files: {files}" , scalar @files , file => $files[0] , files => \@files , nrfiles => @files+0 , _class => 'IO, files' , _join => ', ';
then the values can be takes from the produced message as
my $files = $msg->valueOf('files'); # returns ARRAY reference print @$files; # 3 my $count = $msg->count; # 3 my @class = $msg->classes; # 'IO', 'files' if($msg->inClass('files')) # true
Simplified, the above example can also be written as:
local $" = ', '; my $msg = __xn "found one file: {files}" , "found {_count} files: {files}" , @files # has scalar context , files => \@files , _class => 'IO, files';
This method implements the overloading of concatenation, which is needed
to delay translations even longer. When $prepend is true, the STRING
or $object (other Log::Report::Message
) needs to prepended, otherwise
it is appended.
print __"Hello" . ' ' . __"World!"; print __("Hello")->concat(' ')->concat(__"World!")->concat("\n");
Returns true if the message is in the specified $class (string) or matches the Regexp. The trueth value is the (first matching) class.
Translate a message. If not specified, the default locale is used.
Return the concatenation of the prepend, msgid, and append strings. Variable expansions within the msgid is not performed.