Mojolicious-Plugin-I18N-1.6000755000765000024 012562324546 16226 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/Build.PL000444000765000024 153612562324546 17664 0ustar00sharifulinstaff000000000000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Mojolicious::Plugin::I18N', license => 'perl', dist_author => 'Anatoly Sharifulin ', dist_version_from => 'lib/Mojolicious/Plugin/I18N.pm', dist_abstract => 'Internationalization Plugin for Mojolicious', configure_requires => { 'Module::Build' => 0.42 }, build_requires => { 'Test::More' => 0, }, requires => { 'perl' => 5.010001, 'I18N::LangTags' => 0.35, 'Mojolicious' => 5.0, }, add_to_cleanup => [], meta_merge => { resources => { repository => 'http://github.com/sharifulin/Mojolicious-Plugin-I18N', }, keywords => ['mojo', 'mojolicious', 'plugin', 'i18n', 'internationalization'], }, create_makefile_pl => 'traditional', ); $builder->create_build_script; Mojolicious-Plugin-I18N-1.6/Changes000444000765000024 170512562324546 17661 0ustar00sharifulinstaff000000000000Revision history for Mojolicious-Plugin-I18N 1.5 2015-03-17/11:32 * Mojolicious 6 ready 1.4 2014-12-28/21:04 * Fixed [rt.cpan.org #101168] Fails with Mojolicious 5.69 and 5.70 * Merry X-Mas! 1.3 2014-06-22/0:10 * Mojolicious 5.0 ready, thanks @kostya-ten 1.21 2014-01-04/13:27 * fixed url_for api compatibility issues (@alexeiras) 1.2 2014-01-02/07:35 * Cleanup, bugfixes for CPAN Testers * Happy New Year! :-) 1.1 2013-12-25/13:20 * Some bugfixes, thanks github.com and @temoon 1.0 2013-06-01/17:05 * Stable version of i18n plugin, it works with Mojolicious 4.0+ 0.9 2013-01-03/01:02 * fixed default langauage and url_for, thnx github.com 0.82 2012-12-09/19:09 * pull reqs on github.com, thanks everyone 0.81 2012-07-23/16:32 * fixed test suite 0.8 2012-07-04/18:48 * rename namespace 0.2 2012-06-16/13:37 * fixed url_for 0.1 2012-02-29/15:40 * first release for public * improve url_for helper * add script app_i18n2_mail.pl Mojolicious-Plugin-I18N-1.6/Makefile.PL000444000765000024 72212562324546 20316 0ustar00sharifulinstaff000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.4210 require 5.010001; use ExtUtils::MakeMaker; WriteMakefile ( 'VERSION_FROM' => 'lib/Mojolicious/Plugin/I18N.pm', 'EXE_FILES' => [], 'PREREQ_PM' => { 'Test::More' => 0, 'Mojolicious' => '5', 'I18N::LangTags' => '0.35' }, 'NAME' => 'Mojolicious::Plugin::I18N', 'PL_FILES' => {}, 'INSTALLDIRS' => 'site' ) ; Mojolicious-Plugin-I18N-1.6/MANIFEST000444000765000024 42312562324546 17473 0ustar00sharifulinstaff000000000000Build.PL Changes lib/Mojolicious/Plugin/I18N.pm Makefile.PL MANIFEST META.yml README.pod script/App.pm script/app_i18n_mail.pl script/test.mail.ep t/App/I18N.pm t/App/I18N/en_us.pm t/i18n.t t/i18n_app.t t/i18n_lite_app.t t/i18n_shortcut_lite_app.t t/i18n_url_for.t META.json Mojolicious-Plugin-I18N-1.6/META.json000444000765000024 243412562324546 20007 0ustar00sharifulinstaff000000000000{ "abstract" : "Internationalization Plugin for Mojolicious", "author" : [ "Anatoly Sharifulin " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.421", "keywords" : [ "mojo", "mojolicious", "plugin", "i18n", "internationalization" ], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Mojolicious-Plugin-I18N", "prereqs" : { "build" : { "requires" : { "Test::More" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0.42" } }, "runtime" : { "requires" : { "I18N::LangTags" : "0.35", "Mojolicious" : "5", "perl" : "5.010001" } } }, "provides" : { "Mojolicious::Plugin::I18N" : { "file" : "lib/Mojolicious/Plugin/I18N.pm", "version" : "1.6" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "http://github.com/sharifulin/Mojolicious-Plugin-I18N" } }, "version" : "1.6" } Mojolicious-Plugin-I18N-1.6/META.yml000444000765000024 146112562324546 17636 0ustar00sharifulinstaff000000000000--- abstract: 'Internationalization Plugin for Mojolicious' author: - 'Anatoly Sharifulin ' build_requires: Test::More: '0' configure_requires: Module::Build: '0.42' dynamic_config: 1 generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.143240' keywords: - mojo - mojolicious - plugin - i18n - internationalization license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Mojolicious-Plugin-I18N provides: Mojolicious::Plugin::I18N: file: lib/Mojolicious/Plugin/I18N.pm version: '1.6' requires: I18N::LangTags: '0.35' Mojolicious: '5' perl: '5.010001' resources: license: http://dev.perl.org/licenses/ repository: http://github.com/sharifulin/Mojolicious-Plugin-I18N version: '1.6' Mojolicious-Plugin-I18N-1.6/README.pod000444000765000024 646112562324546 20033 0ustar00sharifulinstaff000000000000=encoding UTF-8 =head1 NAME Mojolicious::Plugin::I18N - Internationalization Plugin for Mojolicious =head1 SYNOPSIS # Mojolicious $self->plugin('I18N'); % languages 'de'; %=l 'hello' # Mojolicious::Lite (detect language from URL, i.e. /en/ or /de/) plugin I18N => {namespace => 'MyApp::I18N', support_url_langs => [qw(en de)]}; %=l 'hello' # Lexicon package MyApp::I18N::de; use Mojo::Base 'MyApp::I18N'; our %Lexicon = (hello => 'hallo'); 1; =head1 DESCRIPTION L is internationalization plugin for Mojolicious It works with Mojolicious 4.0+. Old namespace is L. =head1 OPTIONS L supports the following options. =head2 C plugin I18N => {support_url_langs => [qw(en de)]}; Detect language from URL. =head2 C plugin I18N => {support_hosts => { 'mojolicious.ru' => 'ru', 'mojolicio.us' => 'en' }}; Detect Host header and use language for that host. =head2 C plugin I18N => {no_header_detect => 1}; Off header detect. =head2 C plugin I18N => {default => 'en'}; Default language for i18n, defaults to C. =head2 C plugin I18N => {namespace => 'MyApp::I18N'}; Lexicon namespace, defaults to the application class followed by C<::I18N>. =head1 HELPERS L implements helpers same as L. =head2 C %=l 'hello' $self->l('hello'); Translate sentence. =head2 C % languages 'de'; $self->languages('de'); Change languages. =head1 METHODS L inherits all methods from L and reimplements the following new ones. =head2 C $plugin->register; Register plugin hooks and helpers in L application. =head1 DEBUG MODE L has debug mode. # debug mode on BEGIN { $ENV{MOJO_I18N_DEBUG} = 1 }; # or MOJO_I18N_DEBUG=1 perl script.pl =head1 SEE ALSO L, L, L. =head1 AUTHORS 2011-2014 Anatoly Sharifulin 2010-2012 Sebastian Riedel =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes. =over 5 =item * Github L =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPANTS: CPAN Testing Service L =item * CPAN Ratings L =item * Search CPAN L =back =head1 COPYRIGHT & LICENSE Copyright (C) 2011-2014 by Anatoly Sharifulin. Copyright (C) 2008-2012, Sebastian Riedel. This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. =cut Mojolicious-Plugin-I18N-1.6/lib000755000765000024 012562324546 16774 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/lib/Mojolicious000755000765000024 012562324546 21270 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/lib/Mojolicious/Plugin000755000765000024 012562324546 22526 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/lib/Mojolicious/Plugin/I18N.pm000444000765000024 2045012562324546 23721 0ustar00sharifulinstaff000000000000package Mojolicious::Plugin::I18N; use Mojo::Base 'Mojolicious::Plugin'; use Mojo::URL; use I18N::LangTags; use I18N::LangTags::Detect; our $VERSION = '1.6'; # "Can we have Bender burgers again? # No, the cat shelter’s onto me." sub register { my ($plugin, $app, $conf) = @_; # Initialize my $namespace = $conf->{namespace} || ( (ref $app) . '::I18N' ); my $default = $conf->{default } || 'en'; $default =~ tr/-A-Z/_a-z/; $default =~ tr/_a-z0-9//cd; my $langs = $conf->{support_url_langs}; my $hosts = $conf->{support_hosts }; # Default Handler my $handler = sub { shift->stash->{i18n} = Mojolicious::Plugin::I18N::_Handler->new(namespace => $namespace, default => $default) ; }; # Add hook $app->hook( before_dispatch => sub { my $self = shift; # Handler $handler->( $self ); # Header detection my @languages = $conf->{no_header_detect} ? () : I18N::LangTags::implicate_supers( I18N::LangTags::Detect->http_accept_langs( $self->req->headers->accept_language ) ) ; # Host detection my $host = $self->req->headers->header('X-Host') || $self->req->headers->host; if ($conf->{support_hosts} && $host) { warn $host; $host =~ s/^www\.//; # hack if (my $lang = $conf->{support_hosts}->{ $host }) { $self->app->log->debug("Found language $lang, Host header is $host"); unshift @languages, $lang; } } # Set default language $self->stash(lang_default => $languages[0]) if $languages[0]; # URL detection if (my $path = $self->req->url->path) { my $part = $path->parts->[0]; if ($part && $langs && grep { $part eq $_ } @$langs) { # Ignore static files return if $self->res->code; $self->app->log->debug("Found language $part in URL $path"); unshift @languages, $part; # Save lang in stash $self->stash(lang => $part); # Clean path shift @{$path->parts}; $path->trailing_slash(0); } } # Languages $self->languages(@languages, $default); } ); # Add "languages" helper $app->helper(languages => sub { my $self = shift; $handler->( $self ) unless $self->stash('i18n'); $self->stash->{i18n}->languages(@_); }); # Add "l" helper $app->helper(l => sub { my $self = shift; $handler->( $self ) unless $self->stash('i18n'); $self->stash->{i18n}->localize(@_); }); # Reimplement "url_for" helper my $mojo_url_for = *Mojolicious::Controller::url_for{CODE}; my $i18n_url_for = sub { my $self = shift; my $url = $self->$mojo_url_for(@_); # Absolute URL return $url if $url->is_abs; # Discard target if present shift if (@_ % 2 && !ref $_[0]) || (@_ > 1 && ref $_[-1]); # Unveil params my %params = @_ == 1 ? %{$_[0]} : @_; # Detect lang if (my $lang = $params{lang} || $self->stash('lang')) { my $path = $url->path || []; # Root if (!$path->[0]) { $path->parts([ $lang ]); } # No language detected elsif ( ref $langs ne 'ARRAY' or not scalar grep { $path->contains("/$_") } @$langs ) { unshift @{ $path->parts }, $lang; } } $url; }; { no strict 'refs'; no warnings 'redefine'; *Mojolicious::Controller::url_for = $i18n_url_for; } } package Mojolicious::Plugin::I18N::_Handler; use Mojo::Base -base; use constant DEBUG => $ENV{MOJO_I18N_DEBUG} || 0; # "Robot 1-X, save my friends! And Zoidberg!" sub languages { my ($self, @languages) = @_; unless (@languages) { my $lang = $self->{language}; # lang such as en-us $lang =~ s/_/-/g; return $lang; } # Handle my $namespace = $self->{namespace}; # Load Lang Module $self->_load_module($namespace => $_) for @languages; if (my $handle = $namespace->get_handle(@languages)) { $handle->fail_with(sub { $_[1] }); $self->{handle} = $handle; $self->{language} = $handle->language_tag; } return $self; } sub localize { my $self = shift; my $key = shift; return $key unless my $handle = $self->{handle}; return $handle->maketext($key, @_); } sub _load_module { my $self = shift; my($namespace, $lang) = @_; return unless $namespace && $lang; # lang such as en-us $lang =~ s/-/_/g; unless ($namespace->can('new')) { DEBUG && warn("Load default namespace $namespace"); (my $file = $namespace) =~ s{::|'}{/}g; eval qq(require "$file.pm"); if ($@) { DEBUG && warn("Create default namespace $namespace"); eval "package $namespace; use base 'Locale::Maketext'; 1;"; die qq/Couldn't initialize I18N default class "$namespace": $@/ if $@; } } for ($self->{default}, $lang) { my $module = "${namespace}::$_"; unless ($module->can('new')) { DEBUG && warn("Load the I18N class $module"); (my $file = $module) =~ s{::|'}{/}g; eval qq(require "$file.pm"); my $default = $self->{default}; if ($@ || not eval "\%${module}::Lexicon") { if ($_ eq $default) { DEBUG && warn("Create the I18N class $module"); eval "package ${module}; use base '$namespace';" . 'our %Lexicon = (_AUTO => 1); 1;'; die qq/Couldn't initialize I18N class "$namespace": $@/ if $@; } } } } } 1; __END__ =head1 NAME Mojolicious::Plugin::I18N - Internationalization Plugin for Mojolicious =head1 SYNOPSIS # Mojolicious $self->plugin('I18N'); % languages 'de'; %=l 'hello' # Mojolicious::Lite (detect language from URL, i.e. /en/ or /de/) plugin I18N => {namespace => 'MyApp::I18N', support_url_langs => [qw(en de)]}; %=l 'hello' # Lexicon package MyApp::I18N::de; use Mojo::Base 'MyApp::I18N'; our %Lexicon = (hello => 'hallo'); 1; =head1 DESCRIPTION L is internationalization plugin for Mojolicious It works with Mojolicious 4.0+. Old namespace is L. =head1 OPTIONS L supports the following options. =head2 C plugin I18N => {support_url_langs => [qw(en de)]}; Detect language from URL. =head2 C plugin I18N => {support_hosts => { 'mojolicious.ru' => 'ru', 'mojolicio.us' => 'en' }}; Detect Host header and use language for that host. =head2 C plugin I18N => {no_header_detect => 1}; Off header detect. =head2 C plugin I18N => {default => 'en'}; Default language for i18n, defaults to C. =head2 C plugin I18N => {namespace => 'MyApp::I18N'}; Lexicon namespace, defaults to the application class followed by C<::I18N>. =head1 HELPERS L implements helpers same as L. =head2 C %=l 'hello' $self->l('hello'); Translate sentence. =head2 C % languages 'de'; $self->languages('de'); Change languages. =head1 METHODS L inherits all methods from L and reimplements the following new ones. =head2 C $plugin->register; Register plugin hooks and helpers in L application. =head1 DEBUG MODE L has debug mode. # debug mode on BEGIN { $ENV{MOJO_I18N_DEBUG} = 1 }; # or MOJO_I18N_DEBUG=1 perl script.pl =head1 SEE ALSO L, L, L. =head1 AUTHORS 2011-2014 Anatoly Sharifulin 2010-2012 Sebastian Riedel =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes. =over 5 =item * Github L =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPANTS: CPAN Testing Service L =item * CPAN Ratings L =item * Search CPAN L =back =head1 COPYRIGHT & LICENSE Copyright (C) 2011-2014 by Anatoly Sharifulin. Copyright (C) 2008-2012, Sebastian Riedel. This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. =cut Mojolicious-Plugin-I18N-1.6/script000755000765000024 012562324546 17532 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/script/App.pm000444000765000024 111212562324546 20740 0ustar00sharifulinstaff000000000000package App; use Mojo::Base 'Mojolicious'; has test => 'Test App'; sub startup { my $self = shift; $self->plugin('mail'); $self->plugin(I18N => {default => 'ru', support_url_langs => [qw(ru en)]}); $self->renderer->paths(['.']); } package App::I18N; use base 'Locale::Maketext'; sub import { warn __PACKAGE__ . ' ' . caller; } package App::I18N::en; use Mojo::Base 'App::I18N'; our %Lexicon = (_AUTO => 1, hello2 => 'Hello two'); package App::I18N::ru; use Mojo::Base 'App::I18N'; use utf8; our %Lexicon = (hello => 'Привет', hello2 => 'Привет два'); 1; Mojolicious-Plugin-I18N-1.6/script/app_i18n_mail.pl000444000765000024 67612562324546 22636 0ustar00sharifulinstaff000000000000#!/usr/bin/env perl use common::sense; use lib qw(../lib ../../mojox-loader/lib ../../mojolicious-plugin-mail/lib ../../mojo/lib); use MojoX::Loader; my $self = MojoX::Loader->load; warn $self->app->test; warn my $mail = $self->render_mail('test', hall => {id => 1, title => 'test'}); $self->mail( to => 'sharifulin@gmail.com', type => 'multipart/mixed', attach => [ { Type => 'text/html', Data => $mail, }, ], ); Mojolicious-Plugin-I18N-1.6/script/test.mail.ep000444000765000024 14212562324546 22072 0ustar00sharifulinstaff000000000000% languages 'ru'; % stash subject => 'Тест!'; Это письмо! %=l 'hello' %=l 'hello2' Mojolicious-Plugin-I18N-1.6/t000755000765000024 012562324546 16471 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/t/i18n.t000555000765000024 232012562324546 17572 0ustar00sharifulinstaff000000000000#!/usr/bin/env perl use lib qw(lib ../lib ../mojo/lib ../../mojo/lib); use utf8; use Mojo::Base -strict; # Disable Bonjour, IPv6 and libev BEGIN { $ENV{MOJO_NO_BONJOUR} = $ENV{MOJO_NO_IPV6} = 1; $ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher'; } use Test::More; package App::I18N; use base 'Locale::Maketext'; package App::I18N::en; use Mojo::Base 'App::I18N'; our %Lexicon = (_AUTO => 1, hello2 => 'Hello two'); package App::I18N::ru; use Mojo::Base 'App::I18N'; our %Lexicon = (hello => 'Привет', hello2 => 'Привет два'); package main; use Mojolicious::Lite; use Test::Mojo; # I18N plugin plugin 'I18N' => { namespace => 'App::I18N', default => 'ru', support_url_langs => [qw(ru en de)] }; get '/' => 'index'; # my $t = Test::Mojo->new; $t->get_ok('/')->status_is(200) ->content_is("ПриветПривет дваru\n"); $t->get_ok('/ru')->status_is(200) ->content_is("ПриветПривет дваru\n"); $t->get_ok('/en')->status_is(200) ->content_is("helloHello twoen\n"); $t->get_ok('/de')->status_is(200) ->content_is("ПриветПривет дваru\n"); $t->get_ok('/es')->status_is(404); done_testing; __DATA__ @@ index.html.ep <%=l 'hello' %><%=l 'hello2' %><%= languages %> Mojolicious-Plugin-I18N-1.6/t/i18n_app.t000555000765000024 200012562324546 20425 0ustar00sharifulinstaff000000000000#!/usr/bin/env perl use lib qw(t lib ../lib ../mojo/lib ../../mojo/lib); use utf8; use Mojo::Base -base; # Disable Bonjour, IPv6 and libev BEGIN { $ENV{MOJO_NO_BONJOUR} = $ENV{MOJO_NO_IPV6} = 1; $ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher'; } use Test::More; use Mojolicious::Lite; use Test::Mojo; # I18N plugin plugin 'I18N' => { namespace => 'App::I18N', default => 'ru', support_url_langs => [qw(ru en de en-us)] }; get '/' => 'index'; # my $t = Test::Mojo->new; $t->get_ok('/')->status_is(200) ->content_is("ПриветПривет дваru\n"); $t->get_ok('/ru')->status_is(200) ->content_is("ПриветПривет дваru\n"); $t->get_ok('/en')->status_is(200) ->content_is("helloHello twoen\n"); $t->get_ok('/de')->status_is(200) ->content_is("ПриветПривет дваru\n"); $t->get_ok('/en-us')->status_is(200) ->content_is("helloHello two USen-us\n"); $t->get_ok('/es')->status_is(404); done_testing; __DATA__ @@ index.html.ep <%=l 'hello' %><%=l 'hello2' %><%= languages %> Mojolicious-Plugin-I18N-1.6/t/i18n_lite_app.t000555000765000024 445412562324546 21461 0ustar00sharifulinstaff000000000000#!/usr/bin/env perl use lib qw(lib ../lib ../mojo/lib ../../mojo/lib); use Mojo::Base -strict; # Disable Bonjour, IPv6 and libev BEGIN { $ENV{MOJO_NO_BONJOUR} = $ENV{MOJO_NO_IPV6} = 1; $ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher'; } use Test::More; package MyTestApp::I18N::de; use Mojo::Base -strict; use base 'MyTestApp::I18N'; our %Lexicon = (hello => 'hallo'); # "Aw, he looks like a little insane drunken angel." package main; use Mojolicious::Lite; use Test::Mojo; # I18N plugin plugin I18N => {namespace => 'MyTestApp::I18N'}; # GET / get '/' => 'index'; # GET /english get '/english' => 'english'; # GET /german get '/german' => 'german'; # GET /mixed get '/mixed' => 'mixed'; # GET /nothing get '/nothing' => 'nothing'; # GET /unknown get '/unknown' => 'unknown'; # Hey, I don’t see you planning for your old age. # I got plans. I’m gonna turn my on/off switch to off. my $t = Test::Mojo->new; # German (detected) $t->get_ok('/' => {'Accept-Language' => 'de, en-US'})->status_is(200) ->content_is("hallode\n"); # English (detected) $t->get_ok('/' => {'Accept-Language' => 'en-US'})->status_is(200) ->content_is("helloen\n"); # English (manual) $t->get_ok('/english' => {'Accept-Language' => 'de'})->status_is(200) ->content_is("helloen\n"); # German (manual) $t->get_ok('/german' => {'Accept-Language' => 'en-US'})->status_is(200) ->content_is("hallode\n"); # Mixed (manual) $t->get_ok('/mixed' => {'Accept-Language' => 'de, en-US'})->status_is(200) ->content_is("hallode\nhelloen\n"); # Nothing $t->get_ok('/nothing')->status_is(200)->content_is("helloen\n"); # Unknown (manual) $t->get_ok('/unknown')->status_is(200)->content_is("unknownde\nunknownen\n"); # Unknwon (manual) $t->get_ok('/unknown' => {'Accept-Language' => 'de, en-US'})->status_is(200) ->content_is("unknownde\nunknownen\n"); done_testing; __DATA__ @@ index.html.ep <%=l 'hello' %><%= languages %> @@ english.html.ep % languages 'en'; <%=l 'hello' %><%= languages %> @@ german.html.ep % languages 'de'; <%=l 'hello' %><%= languages %> @@ mixed.html.ep % languages 'de'; <%=l 'hello' %><%= languages %> % languages 'en'; <%=l 'hello' %><%= languages %> @@ nothing.html.ep <%=l 'hello' %><%= languages %> @@ unknown.html.ep % languages 'de'; <%=l 'unknown' %><%= languages %> % languages 'en'; <%=l 'unknown' %><%= languages %> Mojolicious-Plugin-I18N-1.6/t/i18n_shortcut_lite_app.t000555000765000024 456412562324546 23416 0ustar00sharifulinstaff000000000000#!/usr/bin/env perl use lib qw(lib ../lib ../mojo/lib ../../mojo/lib); use Mojo::Base -strict; # Disable Bonjour, IPv6 and libev BEGIN { $ENV{MOJO_NO_BONJOUR} = $ENV{MOJO_NO_IPV6} = 1; $ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher'; } use Test::More; package MyTestApp::I18N::en; use Mojo::Base -strict; use base 'MyTestApp::I18N'; our %Lexicon = (hello => 'Hello World'); package MyTestApp::I18N::de; use Mojo::Base -strict; use base 'MyTestApp::I18N'; our %Lexicon = (hello => 'Hallo Welt'); # "Planet Express - Our crew is replaceable, your package isn't." package main; use Mojolicious::Lite; use Test::Mojo; # I18N plugin plugin I18N => {namespace => 'MyTestApp::I18N'}; # GET / get '/' => 'index'; # GET /english get '/english' => 'english'; # GET /german get '/german' => 'german'; # GET /mixed get '/mixed' => 'mixed'; # GET /nothing get '/nothing' => 'nothing'; # GET /unknown get '/unknown' => 'unknown'; my $t = Test::Mojo->new; # German (detected) $t->get_ok('/' => {'Accept-Language' => 'de, en-US'})->status_is(200) ->content_is("Hallo Weltde\n"); # English (detected) $t->get_ok('/' => {'Accept-Language' => 'en-US'})->status_is(200) ->content_is("Hello Worlden\n"); # English (manual) $t->get_ok('/english' => {'Accept-Language' => 'de'})->status_is(200) ->content_is("Hello Worlden\n"); # German (manual) $t->get_ok('/german' => {'Accept-Language' => 'en-US'})->status_is(200) ->content_is("Hallo Weltde\n"); # Mixed (manual) $t->get_ok('/mixed' => {'Accept-Language' => 'de, en-US'})->status_is(200) ->content_is("Hallo Weltde\nHello Worlden\n"); # Nothing $t->get_ok('/nothing')->status_is(200)->content_is("Hello Worlden\n"); # Unknown (manual) $t->get_ok('/unknown')->status_is(200)->content_is("unknownde\nunknownen\n"); # Unknwon (manual) $t->get_ok('/unknown' => {'Accept-Language' => 'de, en-US'})->status_is(200) ->content_is("unknownde\nunknownen\n"); done_testing; __DATA__ @@ index.html.ep <%=l 'hello' %><%= languages %> @@ english.html.ep % languages 'en'; <%=l 'hello' %><%= languages %> @@ german.html.ep % languages 'de'; <%=l 'hello' %><%= languages %> @@ mixed.html.ep % languages 'de'; <%=l 'hello' %><%= languages %> % languages 'en'; <%=l 'hello' %><%= languages %> @@ nothing.html.ep <%=l 'hello' %><%= languages %> @@ unknown.html.ep % languages 'de'; <%=l 'unknown' %><%= languages %> % languages 'en'; <%=l 'unknown' %><%= languages %> Mojolicious-Plugin-I18N-1.6/t/i18n_url_for.t000555000765000024 730612562324546 21333 0ustar00sharifulinstaff000000000000#!/usr/bin/env perl use lib qw(lib ../lib ../mojo/lib ../../mojo/lib); use utf8; use Mojo::Base -strict; # Disable Bonjour, IPv6 and libev BEGIN { $ENV{MOJO_NO_BONJOUR} = $ENV{MOJO_NO_IPV6} = 1; $ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher'; } use Test::More; package App::I18N; use base 'Locale::Maketext'; package App::I18N::en; use Mojo::Base 'App::I18N'; our %Lexicon = (_AUTO => 1, hello2 => 'Hello two'); package App::I18N::ru; use Mojo::Base 'App::I18N'; our %Lexicon = (hello => 'Привет', hello2 => 'Привет два'); package main; use Mojolicious::Lite; use Test::Mojo; # I18N plugin plugin 'I18N' => { namespace => 'App::I18N', default => 'ru', support_url_langs => [qw(ru en de)] }; get '/' => 'index'; get '/auth' => 'auth'; get '/test/:slug' => 'compat'; post '/login' => sub { my $self = shift; # Do login things ;) # ... $self->redirect_to($self->param('next') || 'index'); }; # cmp_ok $Mojolicious::VERSION, '>=', 5.0, 'Check Mojolicious >= 5.0'; # my $t = Test::Mojo->new; $t->get_ok('/')->status_is(200) ->content_is("ПриветПривет дваru\n/\n/?test=1\n"); $t->get_ok('/ru')->status_is(200) ->content_is("ПриветПривет дваru\n/ru\n/ru?test=1\n"); $t->get_ok('/en')->status_is(200) ->content_is("helloHello twoen\n/en\n/en?test=1\n"); $t->get_ok('/de')->status_is(200) ->content_is("ПриветПривет дваru\n/de\n/de?test=1\n"); $t->get_ok('/es')->status_is(404); $t->get_ok('/test/hello')->status_is(200) ->content_is( join "\n", qw( /test/hello /en/test/hello /en/test/hello /en/test/hello /en/test/hello /en/perldoc //mojolicio.us/en/perldoc http://mojolicio.us/perldoc ), '' ) ; my $domain = $t->tx->remote_address; my $port = $t->tx->remote_port; my $auth_next = $Mojolicious::VERSION >= 6.09 ? '%2Fauth' : '/auth'; $t->get_ok('/auth')->status_is(200) ->content_is(qq{auth\n}); $t->post_ok('/login?next=/auth')->status_is(302) ->header_is('Location' => "/auth"); my $ru_auth_next = $Mojolicious::VERSION >= 6.09 ? '%2Fru%2Fauth' : '/ru/auth'; $t->get_ok('/ru/auth')->status_is(200) ->content_is(qq{auth\n}); $t->post_ok('/login?next=/ru/auth')->status_is(302) ->header_is('Location' => "/ru/auth"); my $en_auth_next = $Mojolicious::VERSION >= 6.09 ? '%2Fen%2Fauth' : '/en/auth'; $t->get_ok('/en/auth')->status_is(200) ->content_is(qq{auth\n}); $t->post_ok('/login?next=/en/auth')->status_is(302) ->header_is('Location' => "/en/auth"); $t->post_ok('/login?next=/es/auth')->status_is(302) ->header_is('Location' => "/es/auth"); $t->post_ok('/login?next=/ru/en/auth')->status_is(302) ->header_is('Location' => "/ru/en/auth"); $t->post_ok('/login?next=/english/auth')->status_is(302) ->header_is('Location' => "/english/auth"); done_testing; __DATA__ @@ index.html.ep <%=l 'hello' %><%=l 'hello2' %><%= languages %> %= url_for %= url_for->query(test => 1) @@ auth.html.ep auth @@ compat.html.ep %= url_for %= url_for(slug => stash('slug'), lang => 'en') %= url_for({slug => stash('slug'), lang => 'en'}) %= url_for('compat', slug => stash('slug'), lang => 'en') %= url_for('compat', {slug => stash('slug'), lang => 'en'}) %= url_for('/perldoc', lang => 'en') %= url_for('//mojolicio.us/perldoc', lang => 'en') %= url_for('http://mojolicio.us/perldoc', lang => 'en') Mojolicious-Plugin-I18N-1.6/t/App000755000765000024 012562324546 17211 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/t/App/I18N.pm000444000765000024 44712562324546 20350 0ustar00sharifulinstaff000000000000package App::I18N; use base 'Locale::Maketext'; package App::I18N::ru; use Mojo::Base 'App::I18N'; use utf8; our %Lexicon = (hello => 'Привет', hello2 => 'Привет два'); package App::I18N::en; use Mojo::Base 'App::I18N'; our %Lexicon = (_AUTO => 1, hello2 => 'Hello two'); 1; Mojolicious-Plugin-I18N-1.6/t/App/I18N000755000765000024 012562324546 17670 5ustar00sharifulinstaff000000000000Mojolicious-Plugin-I18N-1.6/t/App/I18N/en_us.pm000444000765000024 16212562324546 21453 0ustar00sharifulinstaff000000000000package App::I18N::en_us; use Mojo::Base 'App::I18N'; our %Lexicon = (_AUTO => 1, hello2 => 'Hello two US'); 1;