NAME
Locale::Utils::PlaceholderMaketext - Utils to expand maketext palaceholders
$Id: PlaceholderMaketext.pm 665 2017-07-16 10:12:00Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/Locale-Utils-PlaceholderMaketext/trunk/lib/Locale/Utils/PlaceholderMaketext.pm $
VERSION
1.005
SYNOPSIS
my
$obj
= Locale::Utils::PlaceholderMaketext->new(
# optional is_strict switch
is_strict
=> 1,
# optional escape of % to %%
is_escape_percent_sign
=> 1,
# optional fromatter code
formatter_code
=>
sub
{ ... },
# space between number and singular/plural at function quant
space
=>
"\N{NO-BREAK SPACE}"
,
);
$expanded
=
$obj
->expand_maketext(
$text
,
@args
);
$expanded
=
$obj
->expand_maketext(
$text
, \
@args
);
DESCRIPTION
Utils to transform text from maketext to gettext style and reverse. Utils to expand placeholders in maketext or gettext style.
Locale::Maketext encapsulates the expander. To use the expander in other modules it is not possible. Use this module instead. Use method formatter_code and feel free how to format numerics. Use method sapce to prevent the linebreak bitween number and singular/plural.
SUBROUTINES/METHODS
method new
see SYNOPSIS
method maketext_to_gettext
Maps maketext strings with
%
[_1]
[quant,_2,singular]
[quant,_3,singular,plural]
[quant,_4,singular,plural,zero]
[*,_5,singular]
[*,_6,singular,plural]
[*,_7,singular,plural,zero]
inside to
%%
%1
%quant
(%2,singluar)
%quant
(%3,singluar,plural)
%quant
(%4,singluar,plural,zero)
%*(%5,singluar)
%*(%6,singluar,plural)
%*(%7,singluar,plural,zero)
inside. % to %% depends on is_escape_percent_sign
$gettext_string
=
$obj
->maketext_to_gettext(
$maketext_string
);
This method can called as class method too.
$gettext_string
= Locale::Utils::PlaceholderMaketext->maketext_to_gettext(
$maketext_string
);
method gettext_to_maketext
It is the same like method maktetext_to_gettext only the other direction.
$maketext_string
=
$obj
->gettext_to_maketext(
$gettext_string
);
This method can called as class method too.
$maketext_string
= Locale::Utils::PlaceholderMaketext->gettext_to_maketext(
$gettext_string
);
method space, reset_space
Set the space bitween number and singular/plural. Prevent the linebreak after the number using no-break space. The default of space is q{ }
.
$obj
->space(
"\N{NO-BREAK SPACE}"
);
# unicode example
$obj
->reset_space;
# to reset to the default q{ }
method is_strict
If is_strict is true: For normal replacement undef will be converted to q{}. For quant undef will be converted to 0.
$obj
->is_strict(1);
# boolean true or false;
method is_escape_percent_sign
If is_ecscpe_percent_sign is true: A single % willbe escaped to %%.
$obj
->is_escape_percent_sign(1);
# boolean true or false;
method formatter_code, clear_formatter_code
If it is needed to localize e.g. the numerics than describe this in a code reference.
my
$code_ref
=
sub
{
my
(
$value
,
$type
,
$function_name
) =
@_
;
# $value is never undefined
# $type is 'numeric' or 'string'
# $function_name is 'quant' or undef
...
return
$value
;
};
$obj
->formatter_code(
$code_ref
);
Than method expand_maketext and expand_gettext will run this code before the substitution of placeholders.
To switch off this code - clear them.
$obj
->clear_formatter_code;
method expand_maketext
Expands strings containing maketext placeholders.
maketext style:
[_1]
[quant,_1,singular]
[quant,_1,singular,plural]
[quant,_1,singular,plural,zero]
[*,_1,singular]
[*,_1,singular,plural]
[*,_1,singular,plural,zero]
$expanded
=
$obj
->expand_maketext(
$maketext_text
,
@args
);
or
$expanded
=
$obj
->expand_maketext(
$maketext_text
, \
@args
);
method expand_gettext
Expands strings containing gettext placeholders.
gettext style:
%1
%quant
(%1,singular)
%quant
(%1,singular,plural)
%quant
(%1,singular,plural,zero)
%*(%1,singular)
%*(%1,singular,plural)
%*(%1,singular,plural,zero)
$expanded
=
$obj
->expand_maketext(
$gettext_text
,
@args
);
or
$expanded
=
$obj
->expand_maketext(
$gettext_text
, \
@args
);
EXAMPLE
Inside of this distribution is a directory named example. Run the *.pl files.
DIAGNOSTICS
none
CONFIGURATION AND ENVIRONMENT
none
DEPENDENCIES
INCOMPATIBILITIES
not known
BUGS AND LIMITATIONS
not known
SEE ALSO
http://en.wikipedia.org/wiki/Gettext
AUTHOR
Steffen Winkler
LICENSE AND COPYRIGHT
Copyright (c) 2011 - 2017, Steffen Winkler <steffenw at cpan.org>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.