Mojolicious::Plugin::I18NUtils - provide some helper functions for I18N
version 0.20
In your startup:
startup
sub startup { my $self = shift; # do some Mojolicious stuff $self->plugin( 'I18NUtils' ); # more Mojolicious stuff }
In your template:
<%= datetime_loc('2014-12-10', 'de') %>
If you use a default format other than %Y-%m-%d %H:%M:%S for dates in your application, you can set a format for the parser. E.g. if your dates look like
10.12.2014 12:34:56
You can add the plugin this way
$self->plugin( I18NUtils => { format => '%d.%m.%Y %H:%M:%S' } );
This plugin adds those helper methods to your web application:
Return a list of languages defined in the Accept-Language header.
my @languages = $c->browser_languages;
or
your browser accepts those languages: <%= join ', ', browser_languages() %>
Samples:
Accept-Language: en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2
returns
your browser accepts those languages: en-ca, en, en-us, de-de, de
This helper returns the givent date and time in the localized format.
<%= datetime_loc('2014-12-10 11:12:13', 'de') %>
will return
10.12.2014 11:12:13
If you omit the language it will be retrieved from Accept-Language header
<%= datetime_loc('2014-12-10 11:12:13') %> # Accept-Language: de, en;q=0.8
Same as datetime_loc, but omits the time
datetime_loc
<%= date_loc('2014-12-10 11:12:13', 'de') %>
10.12.2014
<%= date_loc('2014-12-10 11:12:13') %> # Accept-Language: de, en;q=0.8
If you need to handle prices, the helper currency might help you
currency
<%= currency(1111.99, 'ar', 'EUR') %> <%= currency(1111.99, 'de', 'EUR') %> <%= currency(1111.99, 'en', 'EUR') %>
€ ١٬١١١٫٩٩ 1.111,99 € €1,111.99
<%= currency(1111.99, 'EUR') %> # Accept-Language: de, en;q=0.8
1.111,99 €
<%= decimal( 2000, 'ar' ) %> <%= decimal( 2000, 'de' ) %> <%= decimal( 2000, 'en' ) %>
٢٬٠٠٠ 2.000 2,000
<%= decimal( 2000 ) %> # Accept-Language: de, en;q=0.8
2.000
<%= range(1, 2000, 'ar' ) %> <%= range(1, 2000, 'de' ) %> <%= range(1, 2000, 'en' ) %>
١–٢٬٠٠٠ 1–2.000 1–2,000
<%= range( 1, 2000 ) %> # Accept-Language: de, en;q=0.8
1–2.000
<%= at_least( 2000, 'ar' ) %> <%= at_least( 2000, 'de' ) %> <%= at_least( 2000, 'en' ) %>
+٢٬٠٠٠ 2.000+ 2,000+
<%= at_least( 2000 ) %> # Accept-Language: de, en;q=0.8
2.000+
Called when registering the plugin.
# load plugin, alerts are dismissable by default $self->plugin( 'I18NUtils' );
Renee Baecker <reneeb@cpan.org>
This software is Copyright (c) 2017 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Mojolicious::Plugin::I18NUtils, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::I18NUtils
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::I18NUtils
For more information on module installation, please visit the detailed CPAN module installation guide.