Locale-Maketext-Gettext
view release on metacpan or search on metacpan
lib/Locale/Maketext/Gettext/Functions.pm view on Meta::CPAN
bindtextdomain textdomain get_handle maketext __ N_
dmaketext pmaketext dpmaketext
reload_text read_mo encoding key_encoding encode_failure
die_for_lookup_failures);
@EXPORT_OK = @EXPORT;
# Prototype declaration
sub bindtextdomain($;$);
sub textdomain(;$);
sub get_handle(@);
sub maketext(@);
sub __(@);
sub N_(@);
sub dmaketext($$@);
sub pmaketext($$@);
sub dpmaketext($$$@);
sub reload_text();
sub encoding(;$);
sub key_encoding(;$);
sub encode_failure(;$);
sub die_for_lookup_failures(;$);
sub _declare_class($);
sub _cat_class(@);
sub _init_textdomain($);
sub _get_langs($$);
sub _get_handle();
sub _get_empty_handle();
sub _reset();
sub _new_rid();
sub _k($);
sub _lang($);
use Encode qw(encode decode from_to FB_DEFAULT);
use File::Spec::Functions qw(catdir catfile);
use Locale::Maketext::Gettext qw(read_mo);
our (%LOCALEDIRS, %RIDS, %CLASSES, %LANGS);
our (%LHS, $_EMPTY, $LH, $DOMAIN, $CATEGORY, $BASE_CLASS, @LANGS, %PARAMS);
our (@SYSTEM_LOCALEDIRS);
%LHS = qw();
# The category is always LC_MESSAGES
lib/Locale/Maketext/Gettext/Functions.pm view on Meta::CPAN
}
# Maketext, in its long name
# Use @ instead of $@ in prototype, so that we can pass @_ to it.
sub maketext(@) {
return __($_[0], @_[1..$#_]);
}
# Maketext, in its shortcut name
# Use @ instead of $@ in prototype, so that we can pass @_ to it.
sub __(@) {
local ($_, %_);
my ($key, @param, $keyd);
($key, @param) = @_;
# Reset the current language handle if it is not set yet
_get_handle() if !defined $LH;
# Decode the source text
$keyd = $key;
$keyd = decode($PARAMS{"KEY_ENCODING"}, $keyd, $PARAMS{"ENCODE_FAILURE"})
if exists $PARAMS{"KEY_ENCODING"} && !Encode::is_utf8($key);
lib/Locale/Maketext/Gettext/Functions.pm view on Meta::CPAN
&& !Encode::is_utf8($key)) {
$_ = encode($PARAMS{"KEY_ENCODING"}, $_, $PARAMS{"ENCODE_FAILURE"});
}
return $_;
}
# Return the original text untouched, so that it can be cached
# with xgettext
# Use @ instead of $@ in prototype, so that we can pass @_ to it.
sub N_(@) {
# Watch out for this Perl magic! :p
return $_[0] unless wantarray;
return @_;
}
# Maketext in another text domain temporarily,
# an equivalent to dgettext().
sub dmaketext($$@) {
local ($_, %_);
my ($domain, $key, @param, $lh0, $domain0, $text);
lib/Locale/Maketext/Gettext/Functions.pm view on Meta::CPAN
for ($id = "", $_ = 0; $_ < $RID_LEN; $_++) {
$id .= $RID_CHARS[int rand scalar @RID_CHARS];
}
} while exists $RIDS{$id};
$RIDS{$id} = 1;
return $id;
}
# Build the key for the domain registry
sub _k($) {
return join "\n", $LOCALEDIRS{$_[0]}, $CATEGORY, $_[0];
}
# The language from a language handle. language_tag is not quite sane.
sub _lang($) {
local ($_, %_);
$_ = $_[0];
$_ = ref($_);
s/^.+:://;
s/_/-/g;
( run in 2.400 seconds using v1.01-cache-2.11-cpan-524268b4103 )