/usr/share/perl5/Locale/gettext_dumb.pm is in libintl-perl 1.23-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | #! /bin/false
# vim: set autoindent shiftwidth=4 tabstop=4:
# Pure Perl implementation of Uniforum message translation.
# Copyright (C) 2002-2013 Guido Flohr <guido@imperia.net>,
# all rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
package Locale::gettext_dumb;
use Locale::gettext_pp;
use vars qw (%EXPORT_TAGS @EXPORT_OK @ISA $VERSION);
%EXPORT_TAGS = (locale_h => [ qw (gettext
dgettext
dcgettext
ngettext
dngettext
dcngettext
pgettext
dpgettext
dcpgettext
npgettext
dnpgettext
dcnpgettext
textdomain
bindtextdomain
bind_textdomain_codeset
)],
libintl_h => [ qw (LC_CTYPE
LC_NUMERIC
LC_TIME
LC_COLLATE
LC_MONETARY
LC_MESSAGES
LC_ALL)],
);
@EXPORT_OK = qw (gettext
dgettext
dcgettext
ngettext
dngettext
dcngettext
pgettext
dpgettext
dcpgettext
npgettext
dnpgettext
dcnpgettext
textdomain
bindtextdomain
bind_textdomain_codeset
nl_putenv
LC_CTYPE
LC_NUMERIC
LC_TIME
LC_COLLATE
LC_MONETARY
LC_MESSAGES
LC_ALL);
@ISA = qw (Exporter);
*Locale::gettext_dumb::textdomain = \&Locale::gettext_pp::textdomain;
*Locale::gettext_dumb::bindtextdomain = \&Locale::gettext_pp::bindtextdomain;
*Locale::gettext_dumb::bind_textdomain_codeset =
\&Locale::gettext_pp::bind_textdomain_codeset;
*Locale::gettext_dumb::nl_putenv = \&Locale::gettext_pp::nl_putenv;
*Locale::gettext_dumb::LC_CTYPE = \&Locale::gettext_pp::LC_CTYPE;
*Locale::gettext_dumb::LC_NUMERIC = \&Locale::gettext_pp::LC_NUMERIC;
*Locale::gettext_dumb::LC_TIME= \&Locale::gettext_pp::LC_TIME;
*Locale::gettext_dumb::LC_COLLATE = \&Locale::gettext_pp::LC_COLLATE;
*Locale::gettext_dumb::LC_MONETARY = \&Locale::gettext_pp::LC_MONETARY;
*Locale::gettext_dumb::LC_MESSAGES = \&Locale::gettext_pp::LC_MESSAGES;
*Locale::gettext_dumb::LC_ALL = \&Locale::gettext_pp::LC_ALL;
sub gettext ($) {
my ($msgid) = @_;
return dcnpgettext ('', undef, $msgid, undef, undef, undef);
}
sub dgettext ($$) {
my ($domainname, $msgid) = @_;
return dcnpgettext ($domainname, undef, $msgid, undef, undef, undef);
}
sub dcgettext ($$$) {
my ($domainname, $msgid, $category) = @_;
return dcnpgettext ($domainname, undef, $msgid, undef, undef, undef);
}
sub ngettext ($$$) {
my ($msgid, $msgid_plural, $n) = @_;
return dcnpgettext ('', undef, $msgid, $msgid_plural, $n, undef);
}
sub dngettext ($$$$) {
my ($domainname, $msgid, $msgid_plural, $n) = @_;
return dcnpgettext ($domainname, undef, $msgid, $msgid_plural, $n, undef);
}
sub dcngettext ($$$$$) {
my ($domainname, $msgid, $msgid_plural, $n, $category) = @_;
return dcnpgettext ($domainname, undef, $msgid, $msgid_plural, $n, ,
$category);
}
sub pgettext ($$) {
my ($msgctxt, $msgid) = @_;
return dcnpgettext ('', $msgctxt, $msgid, undef, undef, undef);
}
sub dpgettext ($$$) {
my ($domainname, $msgctxt, $msgid) = @_;
return dcnpgettext ($domainname, $msgctxt, $msgid, undef, undef, undef);
}
sub dcpgettext($$$$) {
my ($domainname, $msgctxt, $msgid, $category) = @_;
return dcnpgettext ($domainname, $msgctxt, $msgid, undef, undef, undef);
}
sub npgettext ($$$$) {
my ($msgctxt, $msgid, $msgid_plural, $n) = @_;
return dcnpgettext ('', $msgctxt, $msgid, $msgid_plural, $n, undef);
}
sub dnpgettext ($$$$$) {
my ($domainname, $msgctxt, $msgid, $msgid_plural, $n) = @_;
return dcnpgettext ($domainname, $msgctxt, $msgid, $msgid_plural, $n, undef);
}
sub dcnpgettext ($$$$$$) {
my ($domainname, $msgctxt, $msgid, $msgid_plural, $n, $category) = @_;
my $locale;
if (exists $ENV{LANGUAGE} && length $ENV{LANGUAGE}) {
$locale = $ENV{LANGUAGE};
$locale =~ s/:.*//s;
} elsif (exists $ENV{LC_ALL} && length $ENV{LC_ALL}) {
$locale = $ENV{LC_ALL};
} elsif (exists $ENV{LANG} && length $ENV{LANG}) {
$locale = $ENV{LANG};
} elsif (exists $ENV{LC_MESSAGES} && length $ENV{LC_MESSAGES}) {
$locale = $ENV{LC_MESSAGES};
} else {
$locale = 'C';
}
return Locale::gettext_pp::_dcnpgettext_impl ($domainname, $msgctxt,
$msgid, $msgid_plural, $n,
$category, $locale);
}
1;
__END__
=head1 NAME
Locale::gettext_dumb - Locale unaware Implementation of Uniforum Message Translation
=head1 SYNOPSIS
use Locale::gettext_dumb (:locale_h :libintl_h);
# Normally, you will not want to include this module directly but this way:
use Locale::Messages;
my $selected = Locale::Messages->select_package ('gettext_dumb');
gettext $msgid;
dgettext $domainname, $msgid;
dcgettext $domainname, $msgid, LC_MESSAGES;
ngettext $msgid, $msgid_plural, $count;
dngettext $domainname, $msgid, $msgid_plural, $count;
dcngettext $domainname, $msgid, $msgid_plural, $count, LC_MESSAGES;
pgettext $msgctxt, $msgid;
dpgettext $domainname, $msgctxt, $msgid;
dcpgettext $domainname, $msgctxt, $msgid, LC_MESSAGES;
npgettext $msgctxt, $msgid, $msgid_plural, $count;
dnpgettext $domainname, $msgctxt, $msgid, $msgid_plural, $count;
dcnpgettext $domainname, $msgctxt, $msgid, $msgid_plural, $count, LC_MESSAGES;
textdomain $domainname;
bindtextdomain $domainname, $directory;
bind_textdomain_codeset $domainname, $encoding;
my $category = LC_CTYPE;
my $category = LC_NUMERIC;
my $category = LC_TIME;
my $category = LC_COLLATE;
my $category = LC_MONETARY;
my $category = LC_MESSAGES;
my $category = LC_ALL;
=head1 DESCRIPTION
B<IMPORTANT!> This module is experimental. It may not work as described!
The module B<Locale::gettext_dumb> does exactly the same as
Locale::gettext_xs(3pm) or Locale::gettext_pp(3pm).
While both other modules use POSIX::setlocale() to determine the currently
selected locale, this backend only checks the environment variables
LANGUAGE, LANG, LC_ALL, LC_MESSAGES (in that order), when it tries to locate
a message catalog (a .mo file).
This class was introduced in libintl-perl 1.22.
=head1 USAGE
This module should not be used for desktop software or scripts run locally.
Why? If you use a message catalog for example in Danish in UTF-8 (da_DA.UTF8)
but the system locale is set to Russian with KOI8-R (ru_RU.KOI8-R) you
may produce invalid output, either invalid multi-byte sequences or invalid
text, depending on how you look at it.
That will happen, when you mix output from B<Locale::gettext_pp> with
locale-dependent output from the operating system like the contents of
the variable "$!", date and time formatting functions (localtime(),
gmtime(), POSIX::strftime() etc.), number formatting with printf() and
friends, and so on.
A typical usage scenario looks like this:
You have a server application (for example a web application) that is supposed
to display a fixed set of messages in many languages. If you want to do this
with Locale::gettext_xs(3pm) or Locale::gettext_pp(3pm), you have to install
the locale data for all of those languages. Otherwise, translating the
messages will not work.
With Locale::gettext_dumb(3pm) you can relax these requirements, and display
messages for all languages that you have mo files for.
On the other hand, you will soon reach limits with this approach. Almost
any application requires more than bare translation of messages for
localisation. You want to formatted dates and times, you want to display
numbers in the correct formatting for the selected languages, and you may
want to display system error messages ("$!").
In practice, Locale::gettext_dumb(3pm) is still useful in these scenarios.
Your users will have to live with the fact that the presented output is
in different languages resp. for different locales, when "their" locale
is not installed on your system.
More dangerous is mixing output in different character sets but that can
be easily avoided. Simply make sure that B<Locale::gettext_dump> uses
UTF-8 (for example by setting the environment variable OUTPUT_CHARSET or
by calling bind_textdomain_codeset()) and make sure that the system locale
also uses UTF-8, for example "en_US.UTF8". If that fails, switch to a
locale that uses a subset of UTF-8. In practice that will be US-ASCII, the
character set used by the default locale "C" resp. "POSIX".
Your application will then to a certain extent mix output for different
localisations resp. languages. But this is completely under your control.
=head1 EXAMPLE
See above! Normally you should not use this module! However, let us assume
you have read the warnings. In a web application you would do something
like this:
use Locale::TextDomain qw (com.example.yourapp);
use Locale::Messages qw (nl_putenv LC_ALL bindtextdomain
bind_textdomain_codeset);
use Locale::Util qw (web_set_locale);
use POSIX qw (setlocale);
# First try to switch to the locale requested by the user. If you
# know it you can try to pass it to setlocale like this:
#
# my $hardcoded_locale = 'fr_FR.UTF-8';
# my $success = POSIX::setlocale (LC_ALL, $hardcoded_locale);
#
# However, we try to let libintl-perl do a better job for us:
my $success = web_set_locale $ENV{HTTP_ACCEPT_LANGUAGE},
$ENV{HTTP_ACCEPT_CHARSET};
# Note: If your application forces the use of UTF-8 for its output
# you should pass 'UTF-8' as the second argument to web_set_locale
# instead of $ENV{HTTP_ACCEPT_CHARSET}.
if (!$success) {
# Did not work. Switch to the dumb interface of
# Locale::Messages.
Locale::Messages->select_package ('gettext_dumb');
# And try to switch to a default locale:
if (!setlocale (LC_ALL, 'en_US.UTF-8')) {
# Still no luck. Enforce at least US-ASCII:
setlocale (LC_ALL, 'C');
}
bind_textdomain_codeset 'com.example.yourapp', 'utf-8';
}
If your application forces the usage of UTF-8 you should ignore the environment
variable
=head1 AUTHOR
Copyright (C) 2002-2013, Guido Flohr E<lt>guido@imperia.netE<gt>, all
rights reserved. See the source code for details.
This software is contributed to the Perl community by Imperia
(L<http://www.imperia.net/>).
=head1 SEE ALSO
Locale::TextDomain(3pm), Locale::Messages(3pm), Encode(3pm),
perllocale(3pm), POSIX(3pm), perl(1), gettext(1), gettext(3)
=cut
Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0
perl-label-offset: -4
tab-width: 4
End:
|