Class::Usul::L10N - Localise text strings
use Class::Usul::L10N; my $l10n = Class::Usul::L10N->new( { localedir => 'path_to_message_catalogs', log => Log::Handler->new, } ); $local_text = $l10n->localize( 'message_to_localize', { domains => [ 'message_file', 'another_message_file' ], locale => 'de_DE', params => { name => 'value', }, } );
Localise text strings by looking them up in a GNU Gettext PO message catalogue
A POSIX locale id has the form
<language>_<country>.<charset>@<key>=<value>;...
If the use_country attribute is set to true in the constructor call then the language and country are used from locale. By default use_country is false and only the language from the locale attribute is used
use_country
locale
Defines the following attributes;
l10n_attributes
Hash ref passed to the File::Gettext constructor
_domains
Names of the mo/po files to search for
_source_name
Either po for Portable Object (the default) or mo for the Machine Object
po
mo
_use_country
See above
localedir
Base directory to search for mo/po files
log
Optional logging object
tempdir
Directory to use for temporary files
Monkey with the constructors signature
Finish initialising the object
$po_header_hash_ref = $l10n->get_po_header( { locale => 'de' } );
Returns a hash ref containing the keys and values of the PO header record
$l10n->invalidate_cache;
Causes a reload of the domain files the next time a message is localised
$local_text = $l10n->loc( $key, @args );
Calls "localizer" supplying "locale" as the first argument
$local_text = $l10n->localize( $key, $args );
Localises the message indexed by $key. The message catalogue is loaded from a GNU Gettext portable object file. Returns the $key if the message is not in the catalogue (and $args->{no_default} is not true). Language is selected by the $args->{locale} attribute. Expands positional parameters of the form [_<n>] if $args->{params} is an array reference of values to substitute. Otherwise expands named attributes of the form {attr_name} using the $args hash for substitution values. If $args->{quote_bind_values} is true the placeholder values are displayed wrapped in quotes. The attribute $args->{count} is passed to the portable object files plural function which is used to select either the singular or plural form of the translation. If $args->{context} is supplied it is prepended to the $key before the lookup in the catalogue takes place
$key
$args->{no_default}
$args->{locale}
[_<n>]
$args->{params}
{attr_name}
$args
$args->{quote_bind_values}
$args->{count}
$args->{context}
$local_text = $l10n->localizer( $locale, $key, @args );
Curries the call to localize. It constructs the $args parameter in the call to localize from the @args parameter, defaulting the locale attribute to $locale. The @args parameter can be a hash reference, an array reference or a list of values
@args
$locale
Asserts that the locale attribute is set
There are no known incompatibilities in this module
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <pjfl@cpan.org>
<pjfl@cpan.org>
Larry Wall - For the Perl programming language
Copyright (c) 2018 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
To install Class::Usul, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Usul
CPAN shell
perl -MCPAN -e shell install Class::Usul
For more information on module installation, please visit the detailed CPAN module installation guide.