webgui/lib/WebGUI/International.pm
2002-12-17 04:12:34 +00:00

124 lines
3.4 KiB
Perl

package WebGUI::International;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2002 Plain Black LLC.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
#Test to see if IPC::Shareable will load.
my $hasIPC=1;
eval " use IPC::Shareable; "; $hasIPC=0 if $@;
use strict;
use WebGUI::Session;
use WebGUI::SQL;
=head1 NAME
Package WebGUI::International
=head1 DESCRIPTION
This package provides an interface to the internationalization system.
=head1 SYNOPSIS
use WebGUI::International;
$string = WebGUI::International::get($internationalId,$namespace);
%languages = WebGUI::International::getLanguages();
=head1 METHODS
These functions are available from this package:
=cut
#-------------------------------------------------------------------
=head2 get ( internationalId [ , namespace, languageId ] )
Returns the internationalized message string for the user's language. If there is no internationalized message, this method will return the English string.
=over
=item internationalId
An integer that relates to a message in the international table in the WebGUI database.
=item namespace
A string that relates to the namespace field in the international table in the WebGUI database. Defaults to 'WebGUI'.
=item languageId
An integer that specifies the language that the user should see. Defaults to the user's defined language. If the user hasn't specified a default language it defaults to '1' (English).
=back
=cut
sub get {
my ($output, $language, $namespace, %international);
my $useCache = ($session{env}{MOD_PERL} && $hasIPC && $session{config}{cacheInternational});
if ($useCache) {
my $glue = 'intl';
my %options = (
create => 0,
exclusive => 0,
mode => 0666,
destroy => 0,
);
tie %international, 'IPC::Shareable', $glue, { %options } or WebGUI::ErrorHandler::warn("Couldn't cache international message.");
}
if ($_[2] ne "") {
$language = $_[2];
} elsif ($session{user}{language} ne "") {
$language = $session{user}{language};
} else {
$language = 1;
}
if ($_[1] ne "") {
$namespace = $_[1];
} else {
$namespace = "WebGUI";
}
if ($useCache && $international{$language}{$namespace}{$_[0]}) {
$output = $international{$language}{$namespace}{$_[0]};
} else {
($output) = WebGUI::SQL->quickArray("select message from international
where internationalId=$_[0] and namespace='$namespace' and languageId='$language'");
if ($output eq "" && $language ne 1) {
$output = get($_[0],$namespace,1);
}
$international{$language}{$namespace}{$_[0]} = $output if ($useCache);
}
return $output;
}
#-------------------------------------------------------------------
=head2 getLanguages ( )
Returns a hash reference to the languages (languageId/lanugage) installed on this WebGUI system.
=cut
sub getLanguages {
my ($hashRef);
$hashRef = WebGUI::SQL->buildHashRef("select languageId,language from language");
return $hashRef;
}
1;