4 use vars qw( @ISA @EXPORT_OK $conf $def_locale $debug @translate_auto_insert );
7 #use FS::Record qw( qsearchs ); # wtf? won't import...
9 #use FS::Conf; #wtf? causes dependency loops too.
13 @EXPORT_OK = qw( gettext geterror );
15 FS::UID->install_callback( sub {
19 $def_locale = $conf->config('locale') || 'en_US';
20 $debug = $conf->exists('show-msgcat-codes');
21 @translate_auto_insert = $conf->config('translate-auto-insert');
26 FS::Msgcat - Message catalog functions
30 use FS::Msgcat qw(gettext geterror);
32 #simple interface for retreiving messages...
33 $message = gettext('msgcode');
34 #or errors (includes the error code)
35 $message = geterror('msgcode');
39 FS::Msgcat provides functions to use the message catalog. If you want to
40 maintain the message catalog database, see L<FS::msgcat> instead.
48 Returns the full message for the supplied message code.
53 $debug ? geterror(@_) : _gettext(@_);
56 #though i guess we don't really have to cache here since we do it in
62 return '' unless defined($msgcode) && length($msgcode) > 0;
64 my $locale = (@_ && shift)
65 || $FS::CurrentUser::CurrentUser->locale
68 return $cache{$locale}->{$msgcode} if exists $cache{$locale}->{$msgcode};
70 my $msgcat = FS::Record::qsearchs('msgcat', {
71 'msgcode' => $msgcode,
75 $cache{$locale}->{$msgcode} = $msgcat->msg;
77 warn "WARNING: message for msgcode $msgcode in locale $locale not found"
78 unless $locale eq 'en_US';
79 $cache{$locale}->{$msgcode} = $msgcode;
81 if ( $locale ne 'en_US' && grep { $_ eq $locale } @translate_auto_insert ) {
84 my $newmsgcat = new FS::Record('msgcat', { locale => $locale,
88 warn "WARNING: auto-inserting message for msgcode $msgcode in locale $locale";
96 =item geterror MSGCODE
98 Returns the full message for the supplied message code, including the message
105 my $msg = _gettext($msgcode);
106 if ( $msg eq $msgcode ) {
107 my $locale = $FS::CurrentUser::CurrentUser->option('locale') || $def_locale;
108 "Error code $msgcode (message for locale $locale not found)";
110 "$msg (error code $msgcode)";
122 L<FS::Locales>, L<FS::msgcat>