Skip to content

Instantly share code, notes, and snippets.

@shoorick shoorick/2_td.pl
Created Dec 13, 2010

Embed
What would you like to do?
Mojolicious::Lite with Mojolicious::Plugin::Textdomain example
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
$self->render(
'template' => 'index',
'count' => int rand 33,
);
};
plugin 'charset' => { 'charset' => 'utf8' };
plugin 'textdomain' => {
'domain' => 'example',
'search_dirs' => [ 'locale' ],
};
app->start;
__DATA__
@@ index.html.ep
% layout 'page';
in template:
%= __ 'It works?';
<p>Plural via <code>__nx</code>:
<%= __nx '{count} apple was found', '{count} apples were found', $count, 'count' => $count %>
</p>
<p>Plural via <code>__n</code>:
<%= sprintf __n ( '%d apple was found', '%d apples were found', $count), $count %>
</p>
@@ layouts/page.html.ep
<!doctype html><html>
<head><title>i18n <%= __ 'Example' %></title></head>
<body>
<h1>in layout: <%= __ 'It works?' %></h1>
<%== content %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.