File: i18n.pl

package info (click to toggle)
libtext-xslate-perl 3.5.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,108 kB
  • sloc: perl: 19,756; ansic: 214; pascal: 182; makefile: 9; cs: 8
file content (45 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (5)
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
#!perl
use strict;
use warnings;
use utf8;

use Text::Xslate;
use Text::Xslate::Util qw(html_escape html_builder);
use Encode ();

{
    package MyApp::I18N;
    use FindBin qw($Bin);
    use parent 'Locale::Maketext';
    use Locale::Maketext::Lexicon {
        '*'     => [Gettext => "$Bin/locale/*.po"],
        _auto   => 1,
        _decode => 1,
        _style  => 'gettext',
    };
}

my $i18n = MyApp::I18N->get_handle('ja');

my $xslate = Text::Xslate->new(
    syntax   => 'TTerse',
    function => {
        l => sub {
            return $i18n->maketext(@_);
        },
        l_raw => html_builder {
            my $format = shift;
            my @args = map { html_escape($_) } @_;
            return $i18n->maketext($format, @args);
        },
    },
);

my %param = (location => '<Tokyo>'); # user inputs
my $body = $xslate->render_string(<<'TEMPLATE', \%param);
[% l_raw('Hello!<br />') %]
[% l_raw('I am in %1<br />', $location) %]
TEMPLATE

print Encode::encode_utf8($body);