++ed by:

1 non-PAUSE user.

Renee Baecker

NAME

Mojolicious::Plugin::I18NUtils - provide some helper functions for I18N

VERSION

version 0.20

SYNOPSIS

In your 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') %>

CONFIGURE

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' } );

HELPERS

This plugin adds those helper methods to your web application:

browser_languages

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

datetime_loc

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

will return

 10.12.2014 11:12:13

date_loc

Same as datetime_loc, but omits the time

 <%= date_loc('2014-12-10 11:12:13', 'de') %>

will return

 10.12.2014

If you omit the language it will be retrieved from Accept-Language header

 <%= date_loc('2014-12-10 11:12:13') %>
 # Accept-Language: de, en;q=0.8

will return

 10.12.2014

currency

If you need to handle prices, the helper currency might help you

  <%= currency(1111.99, 'ar', 'EUR') %>
  <%= currency(1111.99, 'de', 'EUR') %>
  <%= currency(1111.99, 'en', 'EUR') %>

will return

  € ١٬١١١٫٩٩
  1.111,99 €
  €1,111.99 

If you omit the language it will be retrieved from Accept-Language header

 <%= currency(1111.99, 'EUR') %>
 # Accept-Language: de, en;q=0.8

will return

 1.111,99 €

decimal

  <%= decimal( 2000, 'ar' ) %>
  <%= decimal( 2000, 'de' ) %>
  <%= decimal( 2000, 'en' ) %>

will return

  ٢٬٠٠٠
  2.000
  2,000

If you omit the language it will be retrieved from Accept-Language header

 <%= decimal( 2000 ) %>
 # Accept-Language: de, en;q=0.8

will return

 2.000

range

  <%= range(1, 2000, 'ar' ) %>
  <%= range(1, 2000, 'de' ) %>
  <%= range(1, 2000, 'en' ) %>

will return

  ١–٢٬٠٠٠
  1–2.000
  1–2,000

If you omit the language it will be retrieved from Accept-Language header

 <%= range( 1, 2000 ) %>
 # Accept-Language: de, en;q=0.8

will return

  1–2.000

at_least

  <%= at_least( 2000, 'ar' ) %>
  <%= at_least( 2000, 'de' ) %>
  <%= at_least( 2000, 'en' ) %>

will return

  +٢٬٠٠٠
  2.000+
  2,000+

If you omit the language it will be retrieved from Accept-Language header

 <%= at_least( 2000 ) %>
 # Accept-Language: de, en;q=0.8

will return

  2.000+

METHODS

register

Called when registering the plugin.

    # load plugin, alerts are dismissable by default
    $self->plugin( 'I18NUtils' );

AUTHOR

Renee Baecker <reneeb@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by Renee Baecker.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)