summaryrefslogtreecommitdiff
path: root/FS/FS/L10N/DBI.pm
blob: dc9231785e0912520fca1e7ac0f2dcbad54b639c (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
package FS::L10N::DBI;
use base qw(FS::L10N);
use strict;
use FS::Msgcat;

sub lexicon {
  my $lh = shift;
  my $class = ref($lh) || $lh;
  no strict 'refs';
  \%{ $class . '::Lexicon' };
}

sub maketext {
  my($lh, $key, @rest) = @_;

  my $lang = $lh->language_tag;
  $lang =~ s/-(\w*)/_\U$1/;

  my $lex = $lh->lexicon;
  unless ( exists $lex->{$key} ) {
    $lex->{$key} = FS::Msgcat::_gettext( $key, $lang );
  }

  my $res = eval { $lh->SUPER::maketext($key, @rest) };
  if ( !$res || $@ ) {
    my $errmsg = "MT error for '$key'";
    warn "$errmsg\n";
    return $errmsg;
  }

  $res;
}

1;