X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FMaketext.pm;h=b4a9b81c7a235d5ab90c2d88dc5e9c9e5962a8ac;hp=319fb1d37edf2303a81782162d70fe3a45e385ce;hb=389b6f1116c3309c2ee57a6c295ed1a793503095;hpb=be40a9fa3750374b32f2aa31e8807433c05d7817 diff --git a/FS/FS/Maketext.pm b/FS/FS/Maketext.pm index 319fb1d37..b4a9b81c7 100644 --- a/FS/FS/Maketext.pm +++ b/FS/FS/Maketext.pm @@ -1,22 +1,46 @@ package FS::Maketext; - use base qw( Exporter ); + use FS::CurrentUser; use FS::Conf; use FS::L10N; +use HTML::Entities qw( encode_entities ); -our @EXPORT_OK = qw( mt ); +our @EXPORT_OK = qw( mt emt js_mt ); our $lh; +our $locale; +#ask FS::UID to run this stuff for us later +FS::UID->install_callback( sub { + my $conf = new FS::Conf; + $locale = $conf->config('locale'); +}); + sub mt { + return '' if $_[0] eq ''; $lh ||= lh(); $lh->maketext(@_); } +# HTML-escaped version of mt() +sub emt { + encode_entities(mt(@_)); +} + +# Javascript-escaped version of mt() +sub js_mt { + my $s = mt(@_); + #false laziness w/Mason.pm + $s =~ s/(['\\])/\\$1/g; + $s =~ s/\r/\\r/g; + $s =~ s/\n/\\n/g; + $s = "'$s'"; +} + sub lh { - my $locale = $FS::CurrentUser::CurrentUser->option('locale') - || FS::Conf->new->config('locale') + my $locale = $FS::CurrentUser::CurrentUser->locale + || $locale || 'en_US'; $locale =~ s/_/-/g; FS::L10N->get_handle($locale) || die "Unknown locale $locale";