/
msg.coretag
56 lines (49 loc) · 1.4 KB
/
msg.coretag
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
44
45
46
47
48
49
50
51
52
53
54
55
56
UserTag msg Order key
UserTag msg addAttr
UserTag msg attrAlias lc inline
UserTag msg hasEndTag
UserTag msg Interpolate
UserTag msg PosNumber 1
UserTag msg Routine <<EOR
sub {
my ($key, $opt, $body) = @_;
my (@args, $message, $out, $startlocale);
unless ($opt->{raw}) {
if (ref $opt->{arg} eq 'ARRAY') {
@args = @{ $opt->{arg} };
} elsif (ref $opt->{arg} eq 'HASH') {
@args = map { $opt->{arg}->{$_} } sort keys %{ $opt->{arg} };
} elsif (! ref $opt->{arg}) {
@args = $opt->{arg};
}
}
if ($opt->{locale}) {
# we only mess with scratch mv_locale because
# Vend::Util::find_locale_bit uses it to determine current locale
$startlocale = $::Scratch->{mv_locale};
Vend::Util::setlocale($opt->{locale}, undef, { persist => 1 });
}
if ($opt->{inline}) {
$message = Vend::Util::find_locale_bit($body);
} else {
$message = $body;
}
if ($key) {
if ($Vend::Cfg->{Locale} and defined $Vend::Cfg->{Locale}{$key}) {
$message = $Vend::Cfg->{Locale}{$key};
} elsif ($Global::Locale and defined $Global::Locale->{$key}) {
$message = $Global::Locale->{$key};
}
}
if ($opt->{raw}) {
$out = $message;
} else {
$out = errmsg($message, @args);
}
if ($opt->{locale}) {
$::Scratch->{mv_locale} = $startlocale;
Vend::Util::setlocale();
}
return $out;
}
EOR