added utility methods to wobject and oo interface to international

This commit is contained in:
JT Smith 2004-06-18 15:50:09 +00:00
parent 20482def49
commit b2728e2781
3 changed files with 107 additions and 16 deletions

View file

@ -19,6 +19,10 @@
performance at a cost of either memory or disk space or both. The gains
here are primarily enjoyed by large heavy traffic sites that use lots of
templates.
- Added convenience methods to Wobject superclass for internationalization,
wobject ID, and namespace.
- Added an object-oriented interface to the internationalization system. The
old procedural interface still works as well.
6.0.3

View file

@ -35,9 +35,15 @@ This package provides an interface to the internationalization system.
$string = WebGUI::International::get($internationalId,$namespace);
%languages = WebGUI::International::getLanguages();
This package can also be used in object-oriented (OO) style.
use WebGUI::International;
my $i = WebGUI::International->new($namespace);
$i->get($internationalId);
=head1 METHODS
These functions are available from this package:
These functions/methods are available from this package:
=cut
@ -67,36 +73,34 @@ An integer that specifies the language that the user should see. Defaults to th
=cut
sub get {
my ($output, $language, $namespace, $cache);
if ($_[2] ne "") {
$language = $_[2];
} elsif ($session{user}{language} ne "") {
$language = $session{user}{language};
my ($id, $language, $namespace);
if (ref($_[0]) eq "WebGUI::International") {
$id = $_[1] || 0;
$namespace = $_[2] || $_[0]->{_namespace} || "WebGUI";
$language = $_[3] || $_[0]->{_language} || $session{user}{language} || 1;
} else {
$language = 1;
}
if ($_[1] ne "") {
$namespace = $_[1];
} else {
$namespace = "WebGUI";
$id = $_[0] || 0;
$namespace = $_[1] || "WebGUI";
$language = $_[2] || $session{user}{language} || 1;
}
my $cachetag = $session{config}{configFile}."-International";
if ($session{config}{useSharedInternationalCache}) {
$cachetag = "International";
}
$cache = WebGUI::Cache->new($language."_".$namespace."_".$_[0],$cachetag);
$output = $cache->get;
my $cache = WebGUI::Cache->new($language."_".$namespace."_".$id,$cachetag);
my $output = $cache->get;
if (not defined $output) {
($output) = WebGUI::SQL->quickArray("select message from international
where internationalId=$_[0] and namespace='$namespace' and languageId='$language'");
where internationalId=$id and namespace='$namespace' and languageId='$language'");
if ($output eq "" && $language ne 1) {
$output = get($_[0],$namespace,1);
$output = get($id,$namespace,1);
}
$cache->set($output, 3600);
}
return $output;
}
#-------------------------------------------------------------------
=head2 getLanguages ( )
@ -111,5 +115,34 @@ sub getLanguages {
return $hashRef;
}
#-------------------------------------------------------------------
=head2 new ( [ namespace, languageId ] )
The constructor for the International function if using it in OO mode.
=over
=item namespace
Specify a default namespace. Defaults to "WebGUI".
=item languageId
Specify a default language. Defaults to user preference.
=back
=cut
sub new {
my $class = shift;
my $namespace = shift;
my $language = shift;
bless({_namespace=>$namespace,_language=>$language},$class);
}
1;

View file

@ -420,6 +420,33 @@ sub getValue {
#-------------------------------------------------------------------
=head2 i18n ( id [, namespace ]) {
Returns an internationalized message.
=over
=item id
The identifier for the internationalized message.
=item namespace
The namespace for the internationalized message. Defaults to the namespace of the wobject.
=back
=cut
sub i18n {
my $self = shift;
my $id = shift;
my $namespace = shift || $self->get("namespace");
return WebGUI::International::get($id,$namespace);
}
#-------------------------------------------------------------------
=head2 inDateRange ( )
@ -567,6 +594,20 @@ sub name {
}
#-------------------------------------------------------------------
=head2 namespace ( )
Returns the namespace of this wobject. This is a shortcut for $self->get("namespace");
=cut
sub namespace {
my $self = shift;
return $self->get("namespace");
}
#-------------------------------------------------------------------
=head2 new ( -properties, -extendedProperties [, -useDiscussion ] )
@ -1056,6 +1097,19 @@ sub uiLevel {
#-------------------------------------------------------------------
=head2 wid ( )
Returns the wobject id of this wobject. This is a shortcut for $self->get("wobjectId");
=cut
sub wid {
my $self = shift;
return $self->get("wobjectId");
}
#-------------------------------------------------------------------
=head2 www_copy ( )
Copies this instance to the clipboard.