| 1 |
#! /bin/false |
| 2 |
|
| 3 |
# vim: tabstop=4 |
| 4 |
|
| 5 |
# Perl XS implementation of Uniforum message translation. |
| 6 |
# Copyright (C) 2002-2026 Guido Flohr <[email protected]>, |
| 7 |
# all rights reserved. |
| 8 |
|
| 9 |
# This program is free software: you can redistribute it and/or modify |
| 10 |
# it under the terms of the GNU General Public License as published by |
| 11 |
# the Free Software Foundation; either version 3 of the License, or |
| 12 |
# (at your option) any later version. |
| 13 |
|
| 14 |
# This program is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
# GNU General Public License for more details. |
| 18 |
|
| 19 |
# You should have received a copy of the GNU General Public License |
| 20 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
package Locale::gettext_xs; |
| 23 |
|
| 24 |
require DynaLoader; |
| 25 |
require Exporter; |
| 26 |
|
| 27 |
use vars qw (%EXPORT_TAGS @EXPORT_OK @ISA); |
| 28 |
|
| 29 |
%EXPORT_TAGS = (locale_h => [ qw ( |
| 30 |
gettext |
| 31 |
dgettext |
| 32 |
dcgettext |
| 33 |
ngettext |
| 34 |
dngettext |
| 35 |
dcngettext |
| 36 |
pgettext |
| 37 |
dpgettext |
| 38 |
dcpgettext |
| 39 |
npgettext |
| 40 |
dnpgettext |
| 41 |
dcnpgettext |
| 42 |
textdomain |
| 43 |
bindtextdomain |
| 44 |
bind_textdomain_codeset |
| 45 |
) |
| 46 |
], |
| 47 |
libintl_h => [ qw (LC_CTYPE |
| 48 |
LC_NUMERIC |
| 49 |
LC_TIME |
| 50 |
LC_COLLATE |
| 51 |
LC_MONETARY |
| 52 |
LC_MESSAGES |
| 53 |
LC_ALL) |
| 54 |
], |
| 55 |
); |
| 56 |
|
| 57 |
@EXPORT_OK = qw (gettext |
| 58 |
dgettext |
| 59 |
dcgettext |
| 60 |
ngettext |
| 61 |
dngettext |
| 62 |
dcngettext |
| 63 |
pgettext |
| 64 |
dpgettext |
| 65 |
dcpgettext |
| 66 |
npgettext |
| 67 |
dnpgettext |
| 68 |
dcnpgettext |
| 69 |
textdomain |
| 70 |
bindtextdomain |
| 71 |
bind_textdomain_codeset |
| 72 |
nl_putenv |
| 73 |
setlocale |
| 74 |
LC_CTYPE |
| 75 |
LC_NUMERIC |
| 76 |
LC_TIME |
| 77 |
LC_COLLATE |
| 78 |
LC_MONETARY |
| 79 |
LC_MESSAGES |
| 80 |
LC_ALL); |
| 81 |
@ISA = qw (Exporter DynaLoader); |
| 82 |
|
| 83 |
bootstrap Locale::gettext_xs; |
| 84 |
|
| 85 |
require File::Spec; |
| 86 |
|
| 87 |
# Reimplement pgettext functions |
| 88 |
sub pgettext ($$) { |
| 89 |
my ($msgctxt, $msgid) = @_; |
| 90 |
|
| 91 |
my $msg_ctxt_id = join("\004", $msgctxt, $msgid); |
| 92 |
return Locale::gettext_xs::_pgettext_aux |
| 93 |
("", $msg_ctxt_id, $msgid, Locale::gettext_xs::LC_MESSAGES()); |
| 94 |
} |
| 95 |
sub dpgettext ($$$) { |
| 96 |
my ($domain, $msgctxt, $msgid) = @_; |
| 97 |
|
| 98 |
my $msg_ctxt_id = join("\004", $msgctxt, $msgid); |
| 99 |
return Locale::gettext_xs::_pgettext_aux |
| 100 |
($domain, $msg_ctxt_id, $msgid, Locale::gettext_xs::LC_MESSAGES()); |
| 101 |
} |
| 102 |
sub dcpgettext ($$$$) { |
| 103 |
my ($domain, $msgctxt, $msgid, $category) = @_; |
| 104 |
|
| 105 |
my $msg_ctxt_id = join("\004", $msgctxt, $msgid); |
| 106 |
return Locale::gettext_xs::_pgettext_aux |
| 107 |
($domain, $msg_ctxt_id, $msgid, $category); |
| 108 |
} |
| 109 |
|
| 110 |
# Reimplement npgettext functions |
| 111 |
sub npgettext ($$$$) { |
| 112 |
my ($msgctxt, $msgid1, $msgid2, $n) = @_; |
| 113 |
|
| 114 |
my $msg_ctxt_id = join("\004", $msgctxt, $msgid1); |
| 115 |
return Locale::gettext_xs::_npgettext_aux |
| 116 |
("", $msg_ctxt_id, $msgid1, $msgid2, $n, Locale::gettext_xs::LC_MESSAGES()); |
| 117 |
} |
| 118 |
sub dnpgettext ($$$$$) { |
| 119 |
my ($domain, $msgctxt, $msgid1, $msgid2, $n) = @_; |
| 120 |
|
| 121 |
my $msg_ctxt_id = join("\004", $msgctxt, $msgid1); |
| 122 |
return Locale::gettext_xs::_npgettext_aux |
| 123 |
($domain, $msg_ctxt_id, $msgid1, $msgid2, $n, Locale::gettext_xs::LC_MESSAGES()); |
| 124 |
} |
| 125 |
sub dcnpgettext ($$$$$$) { |
| 126 |
my ($domain, $msgctxt, $msgid1, $msgid2, $n, $category) = @_; |
| 127 |
|
| 128 |
my $msg_ctxt_id = join("\004", $msgctxt, $msgid1); |
| 129 |
return Locale::gettext_xs::_npgettext_aux |
| 130 |
($domain, $msg_ctxt_id, $msgid1, $msgid2, $n, $category); |
| 131 |
} |
| 132 |
|
| 133 |
# Wrapper function that converts Perl paths to OS paths. |
| 134 |
sub bindtextdomain ($;$) { |
| 135 |
my ($domain, $directory) = @_; |
| 136 |
|
| 137 |
if (defined $domain && length $domain && |
| 138 |
defined $directory && length $directory) { |
| 139 |
return Locale::gettext_xs::_bindtextdomain |
| 140 |
($domain, File::Spec->catdir ($directory)); |
| 141 |
} else { |
| 142 |
return &Locale::gettext_xs::_bindtextdomain; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
# In the XS version, making the prototype optional, does not work. |
| 147 |
sub textdomain (;$) { |
| 148 |
my $domain = shift; |
| 149 |
|
| 150 |
if (defined $domain) { |
| 151 |
return Locale::gettext_xs::_textdomain ($domain); |
| 152 |
} else { |
| 153 |
return Locale::gettext_xs::_textdomain (""); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
sub nl_putenv ($) { |
| 158 |
my ($envspec) = @_; |
| 159 |
|
| 160 |
return unless defined $envspec; |
| 161 |
return unless length $envspec; |
| 162 |
return if substr ($envspec, 0, 1) eq '='; |
| 163 |
|
| 164 |
my ($var, $value) = split /=/, $envspec, 2; |
| 165 |
|
| 166 |
if ($^O eq 'MSWin32') { |
| 167 |
$value = '' unless defined $value; |
| 168 |
return unless Locale::gettext_xs::_nl_putenv ("$var=$value") == 0; |
| 169 |
if (length $value) { |
| 170 |
$ENV{$var} = $value; |
| 171 |
} else { |
| 172 |
delete $ENV{$var}; |
| 173 |
} |
| 174 |
} else { |
| 175 |
if (defined $value) { |
| 176 |
$ENV{$var} = $value; |
| 177 |
} else { |
| 178 |
delete $ENV{$var}; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
return 1; |
| 183 |
} |
| 184 |
|
| 185 |
1; |
| 186 |
|
| 187 |
__END__ |
| 188 |
|
| 189 |
Local Variables: |
| 190 |
mode: perl |
| 191 |
perl-indent-level: 4 |
| 192 |
perl-continued-statement-offset: 4 |
| 193 |
perl-continued-brace-offset: 0 |
| 194 |
perl-brace-offset: -4 |
| 195 |
perl-brace-imaginary-offset: 0 |
| 196 |
perl-label-offset: -4 |
| 197 |
tab-width: 4 |
| 198 |
End: |
| 199 |
|