Skip to content

Instantly share code, notes, and snippets.

@shoorick
Created December 13, 2010 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoorick/738816 to your computer and use it in GitHub Desktop.
Save shoorick/738816 to your computer and use it in GitHub Desktop.
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