4 use vars qw( @ISA @EXPORT_OK $conf $locale );
7 use FS::Record qw( qsearchs );
10 @ISA = qw(FS::Record);
11 @EXPORT_OK = qw( gettext geterror );
13 $FS::UID::callback{'msgcat'} = sub {
15 $locale = $conf->config('locale') || 'en_US';
20 FS::msgcat - Object methods for message catalog entries
24 use FS::msgcat qw(gettext);
26 #simple interface for retreiving messages...
27 $message = gettext('msgcode');
28 #or errors (includes the error code)
29 $message = geterror('msgcode');
32 $record = new FS::msgcat \%hash;
33 $record = new FS::msgcat { 'column' => 'value' };
35 $error = $record->insert;
37 $error = $new_record->replace($old_record);
39 $error = $record->delete;
41 $error = $record->check;
45 An FS::msgcat object represents an message catalog entry. FS::msgcat inherits
46 from FS::Record. The following fields are currently supported:
50 =item msgnum - primary key
52 =item msgcode - Error code
66 Creates a new example. To add the example to the database, see L<"insert">.
68 Note that this stores the hash reference, not a distinct copy of the hash it
69 points to. You can ask the object for a copy with the I<hash> method.
73 # the new method can be inherited from FS::Record, if a table method is defined
75 sub table { 'msgcat'; }
79 Adds this record to the database. If there is an error, returns the error,
80 otherwise returns false.
84 # the insert method can be inherited from FS::Record
88 Delete this record from the database.
92 # the delete method can be inherited from FS::Record
94 =item replace OLD_RECORD
96 Replaces the OLD_RECORD with this one in the database. If there is an error,
97 returns the error, otherwise returns false.
101 # the replace method can be inherited from FS::Record
105 Checks all fields to make sure this is a valid example. If there is
106 an error, returns the error, otherwise returns false. Called by the insert
111 # the check method should currently be supplied - FS::Record contains some
112 # data checking routines
118 $self->ut_numbern('msgnum')
119 || $self->ut_text('msgcode')
120 || $self->ut_text('msg')
122 return $error if $error;
124 $self->locale =~ /^([\w\@]+)$/ or return "illegal locale: ". $self->locale;
136 =item gettext MSGCODE
138 Returns the full message for the supplied message code.
144 my $msgcat = qsearchs('msgcat', {
145 'msgcode' => $msgcode,
151 warn "WARNING: message for msgcode $msgcode in locale $locale not found";
157 =item geterror MSGCODE
159 Returns the full message for the supplied message code, including the message
166 my $msg = gettext($msgcode);
167 if ( $msg eq $msgcode ) {
168 "Error code $msgcode (message for locale $locale not found)";
170 "$msg (error code $msgcode)";
182 L<FS::Record>, schema.html from the base documentation.