pazt has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks

I'm trying "inflate" languages parts from my App.pl script but i'm not getting works

This is my working App.pl

#!/usr/bin/perl # Brazilian portuguese package App::I18N::pt_br; use Mojo::Base 'Locale::Maketext'; use utf8; our %Lexicon = ('hello world'=> 'Olá Mundo'); # French package App::I18N::fr; use Mojo::Base 'Locale::Maketext'; use utf8; our %Lexicon = ('hello world'=> 'salut monde'); package main; use Mojolicious::Lite; plugin I18N => { namespace => 'App::I18N', support_url_langs => [qw(en fr pt_br)] }; get '/' => 'index'; app->start; __DATA__ @@ index.html.ep %= l 'hello world'

Using that script above everything works. But when i try to separate the language parts, the script not fail, but not translate the 'hello world' word.

I tried split the script like this:

App |+- App.pl |- I18N | |- fr.pm | +- pt_br.pm

App.pl becames:

use Mojolicious::Lite; plugin I18N => { namespace => 'App::I18N', support_url_langs => [qw(en fr pt_br)] }; get '/' => 'index'; app->start; __DATA__ @@ index.html.ep %= l 'hello world'

and package App::I18N::pt_br becames pt_br.pm:

package App::I18N::pt_br; use Mojo::Base 'Locale::Maketext'; use utf8; our %Lexicon = ('hello world'=> 'Olá Mundo');

So.... Am I doing something wrong? How can I split my language parts from my script and keep it working?

Thank you very much

Replies are listed 'Best First'.
Re: Mojolicious i18n "inflate"
by beech (Parson) on Oct 09, 2016 at 02:59 UTC

    Using that script above everything works. But when i try to separate the language parts, the script not fail, but not translate the 'hello world' word.

    Hi,

    What happens if you add

    # debug mode on BEGIN { $ENV{MOJO_I18N_DEBUG} = 1 };

      Hi beech,

      I don't know if i'd insert the "BEGIN { $ENV{MOJO_I18N_DEBUG} = 1 };" on right file/line. Sorry, i'm just mojolicious rookie yet.

      Anyway, my App.pl becomes:

      #!/usr/bin/perl use Mojolicious::Lite; BEGIN { $ENV{MOJO_I18N_DEBUG} = 1 }; plugin I18N => { namespace => 'App::I18N', support_url_langs => [qw(en fr pt_br)] }; get '/' => 'index'; app->start; __DATA__ @@ index.html.ep %= l 'hello world'

      And the response was:

      Server available at http://127.0.0.1:3000
      Load default namespace App::I18N::pt_br at /usr/local/share/perl/5.18.2/Mojolicious/Plugin/I18N.pm line 200.
      Create default namespace App::I18N::pt_br at /usr/local/share/perl/5.18.2/Mojolicious/Plugin/I18N.pm line 206.
      Load the I18N class App::I18N::pt_br::en at /usr/local/share/perl/5.18.2/Mojolicious/Plugin/I18N.pm line 216.
      Create the I18N class App::I18N::pt_br::en at /usr/local/share/perl/5.18.2/Mojolicious/Plugin/I18N.pm line 224.
      Load the I18N class App::I18N::pt_br::pt_br at /usr/local/share/perl/5.18.2/Mojolicious/Plugin/I18N.pm line 216.
      Load the I18N class App::I18N::pt_br::pt at /usr/local/share/perl/5.18.2/Mojolicious/Plugin/I18N.pm line 216.
      Load the I18N class App::I18N::pt_br::en_us at /usr/local/share/perl/5.18.2/Mojolicious/Plugin/I18N.pm line 216.
      Sat Oct 8 06:55:57 2016 debug GET "/"
      Sat Oct 8 06:55:57 2016 debug Rendering template "index.html.ep" from DATA section
      Sat Oct 8 06:55:57 2016 debug 200 OK (0.003052s, 327.654/s)

      The selected language on my browser is "pt_BR".
      And "MOJO_I18N_DEBUG" showed that "App.pl" isn't calling my pt_br.pm on I18N folder

      What's the next step?

      Thanks for your help

        Hi,

        It appears you need a dash  perl app.pl get / -H "Accept-Language: pt-br"

        Maybe the DEBUG option should have logged that pt_br is not recognized ... might be worth a bug report to the author

        FYI, FWIW, App::I18N exists :)

        Also, debug/log info is data, so Put <code> </code> tags around it