4 use vars qw( @ISA @EXPORT_OK $conf $locale $debug );
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';
16 $debug = $conf->exists('show-msgcat-codes')
21 FS::msgcat - Object methods for message catalog entries
25 use FS::msgcat qw(gettext);
27 #simple interface for retreiving messages...
28 $message = gettext('msgcode');
29 #or errors (includes the error code)
30 $message = geterror('msgcode');
33 $record = new FS::msgcat \%hash;
34 $record = new FS::msgcat { 'column' => 'value' };
36 $error = $record->insert;
38 $error = $new_record->replace($old_record);
40 $error = $record->delete;
42 $error = $record->check;
46 An FS::msgcat object represents an message catalog entry. FS::msgcat inherits
47 from FS::Record. The following fields are currently supported:
51 =item msgnum - primary key
53 =item msgcode - Error code
67 Creates a new example. To add the example to the database, see L<"insert">.
69 Note that this stores the hash reference, not a distinct copy of the hash it
70 points to. You can ask the object for a copy with the I<hash> method.
74 # the new method can be inherited from FS::Record, if a table method is defined
76 sub table { 'msgcat'; }
80 Adds this record to the database. If there is an error, returns the error,
81 otherwise returns false.
85 # the insert method can be inherited from FS::Record
89 Delete this record from the database.
93 # the delete method can be inherited from FS::Record
95 =item replace OLD_RECORD
97 Replaces the OLD_RECORD with this one in the database. If there is an error,
98 returns the error, otherwise returns false.
102 # the replace method can be inherited from FS::Record
106 Checks all fields to make sure this is a valid example. If there is
107 an error, returns the error, otherwise returns false. Called by the insert
112 # the check method should currently be supplied - FS::Record contains some
113 # data checking routines
119 $self->ut_numbern('msgnum')
120 || $self->ut_text('msgcode')
121 || $self->ut_text('msg')
123 return $error if $error;
125 $self->locale =~ /^([\w\@]+)$/ or return "illegal locale: ". $self->locale;
137 =item gettext MSGCODE
139 Returns the full message for the supplied message code.
144 $debug ? geterror(@_) : _gettext(@_);
149 my $msgcat = qsearchs('msgcat', {
150 'msgcode' => $msgcode,
156 warn "WARNING: message for msgcode $msgcode in locale $locale not found";
162 =item geterror MSGCODE
164 Returns the full message for the supplied message code, including the message
171 my $msg = _gettext($msgcode);
172 if ( $msg eq $msgcode ) {
173 "Error code $msgcode (message for locale $locale not found)";
175 "$msg (error code $msgcode)";
187 L<FS::Record>, schema.html from the base documentation.