webgui/lib/WebGUI/International.pm
2003-01-05 18:32:19 +00:00

116 lines
3.1 KiB
Perl

package WebGUI::International;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2003 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 Cache::FileCache will load.
my $hasCache=1;
eval " use Cache::FileCache; "; $hasCache=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, $cache);
my $useCache = ($hasCache && $session{config}{cacheInternational});
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) {
$cache = new Cache::FileCache({'namespace'=>'International'});
$output = $cache->get($language."_".$namespace."_".$_[0]);
}
if (not defined $output) {
($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);
}
$cache->set($language."_".$namespace."_".$_[0], $output, $session{config}{cacheInternational}) 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;