summaryrefslogtreecommitdiff
path: root/FS/FS/Maketext.pm
blob: ccfc1204b112fc62222f8656c7e8700f7605f460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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 emt js_mt );

our $lh;

sub mt {
  $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')
             || 'en_US';
  $locale =~ s/_/-/g;
  FS::L10N->get_handle($locale) || die "Unknown locale $locale";
}

# XXX pod me

1;