Catalyst-Plugin-I18N

 view release on metacpan or  search on metacpan

lib/Catalyst/Plugin/I18N/Manual.pod  view on Meta::CPAN

=encoding UTF-8

=head1 NAME

Catalyst::Plugin::I18N::Manual - (Draft) I18N and L10N with Catalyst and Template Toolkit.

=head1 OUTLINE

    Prerequisites:
     - perl >= 5.8.0
     - Catalyst >= 5.33
     - Catalyst::Plugin::I18N >= 0.04
     - Catalyst::Plugin::Unicode >= 0.2
     - Catlayst::View::TT && Template-Toolkit >= 2.14
     - GNU gettext utilities
     - An editor that understands UTF-8 and Byte Order Mark (BOM)

    $ catalyst.pl MyApp
    created "MyApp"
    created "MyApp/script"
    created "MyApp/lib"
    created "MyApp/root"
    created "MyApp/root/static"
    created "MyApp/root/static/images"
    created "MyApp/t"
    created "MyApp/lib/MyApp"
    created "MyApp/lib/MyApp/Model"
    created "MyApp/lib/MyApp/View"
    created "MyApp/lib/MyApp/Controller"
    created "MyApp/lib/MyApp.pm"
    created "MyApp/Makefile.PL"
    created "MyApp/README"
    created "MyApp/Changes"
    created "MyApp/t/01app.t"
    created "MyApp/t/02pod.t"
    created "MyApp/t/03podcoverage.t"
    created "MyApp/root/static/images/catalyst_logo.png"
    created "MyApp/root/static/images/btn_120x50_built.png"
    created "MyApp/root/static/images/btn_120x50_built_shadow.png"
    created "MyApp/root/static/images/btn_120x50_powered.png"
    created "MyApp/root/static/images/btn_120x50_powered_shadow.png"
    created "MyApp/root/static/images/btn_88x31_built.png"
    created "MyApp/root/static/images/btn_88x31_built_shadow.png"
    created "MyApp/root/static/images/btn_88x31_powered.png"
    created "MyApp/root/static/images/btn_88x31_powered_shadow.png"
    created "MyApp/root/favicon.ico"
    created "MyApp/script/myapp_cgi.pl"
    created "MyApp/script/myapp_fastcgi.pl"
    created "MyApp/script/myapp_server.pl"
    created "MyApp/script/myapp_test.pl"
    created "MyApp/script/myapp_create.pl"

    $ cd MyApp
    $ vim lib/MyApp.pm

    use Catalyst qw/-Debug I18N Unicode/;
    
    sub begin : Private {
        my ( $self, $c ) = @_;
        
        my $locale = $c->request->param('locale');
        
        $c->response->headers->push_header( 'Vary' => 'Accept-Language' );  # hmm vary and param?
        $c->languages( $locale ? [ $locale ] : undef );
    }

    sub default : Private {
        my ( $self, $c ) = @_;

        my $name = $c->request->param('name') || $c->loc('Guest');

        $c->response->content_type('text/plain; charset=utf-8');
        $c->response->body( $c->loc( 'Welcome [_1]!', $name ) );
    }

    $ mkdir lib/MyApp/I18N

lib/Catalyst/Plugin/I18N/Manual.pod  view on Meta::CPAN

    | /default             | MyApp                                  | default      |
    '----------------------+----------------------------------------+--------------'

    [Fri Dec  2 03:52:48 2005] [catalyst] [info] MyApp powered by Catalyst 5.57
    You can connect to your server at http://localhost:3000

    # point your browser to http://localhost:3000/?name=Joe
    # output should render:

    Välkommen Joe!

    $ vim lib/MyApp.pm

    sub default : Private {

        # ...

        $c->response->body( $c->loc( 'Welcome to my homepage [_1]!', $name ) );
    }
    
    $ xgettext.pl --output=lib/MyApp/I18N/messages.pot --directory=lib/
    $ msgmerge --update lib/MyApp/I18N/sv.po lib/MyApp/I18N/messages.pot
    . done.

    $ vim lib/MyApp/I18N/sv.po

    #. ($name)
    #: lib/MyApp.pm:54
    msgid "Welcome to my homepage %1!"
    msgstr "Välkommen till min hemsida %1!"

    $ perl script/myapp_server.pl

    # point your browser to http://localhost:3000/?name=Joe
    # output should render:

    Välkommen till min hemsida Joe!

    $ perl script/myapp_create.pl view TT TT
     exists "/Users/chansen/MyApp/script/../lib/MyApp/View"
     exists "/Users/chansen/MyApp/script/../t"
    created "/Users/chansen/MyApp/script/../lib/MyApp/View/TT.pm"
    created "/Users/chansen/MyApp/script/../t/view_TT.t"
    
    $ vim lib/MyApp.pm

    sub default : Private {
        my ( $self, $c ) = @_;

        my $name = $c->request->param('name') || $c->loc('Guest');

        $c->response->content_type('text/plain; charset=utf-8');
        $c->stash(
            name     => $name,
            template => 'test.tt' 
        );
        
        $c->forward('MyApp::View::TT');
    }

    $ vim root/test.tt # Save file in UTF-8 with BOM
    
    [% c.loc( 'Welcome to my place [_1]!', c.stash.name ) %]
    
    $ xgettext.pl --output=lib/MyApp/I18N/messages.pot --directory=lib/ --directory=root/
    $ msgmerge --update lib/MyApp/I18N/sv.po lib/MyApp/I18N/messages.pot
    . done.    
    
    $ vim lib/MyApp/I18N/sv.po

    #. (c.stash.name)
    #: root/test.tt:1
    msgid "Welcome to my place %1!"
    msgstr "Välkommen till mitt ställe %1!"
    
    $ perl script/myapp_server.pl 
    [Fri Dec  2 05:12:58 2005] [catalyst] [debug] Debug messages enabled
    [Fri Dec  2 05:12:58 2005] [catalyst] [debug] Loaded plugins:
    .------------------------------------------------------------------------------.
    | Catalyst::Plugin::I18N                                                       |
    | Catalyst::Plugin::Unicode                                                    |
    '------------------------------------------------------------------------------'

    [Fri Dec  2 05:12:58 2005] [catalyst] [debug] Loaded dispatcher "Catalyst::Dispatcher"
    [Fri Dec  2 05:12:58 2005] [catalyst] [debug] Loaded engine "Catalyst::Engine::HTTP"
    [Fri Dec  2 05:12:58 2005] [catalyst] [debug] Found home "/Users/chansen/MyApp"
    [Fri Dec  2 05:12:58 2005] [catalyst] [debug] Initialized i18n "MyApp::I18N"
    [Fri Dec  2 05:12:59 2005] [catalyst] [debug] Loaded components:
    .-------------------------------------------------------------------+----------.
    | Class                                                             | Type     |
    +-------------------------------------------------------------------+----------+
    | MyApp::View::TT                                                   | instance |
    '-------------------------------------------------------------------+----------'

    [Fri Dec  2 05:12:59 2005] [catalyst] [debug] Loaded Private actions:
    .----------------------+----------------------------------------+--------------.
    | Private              | Class                                  | Method       |
    +----------------------+----------------------------------------+--------------+
    | /default             | MyApp                                  | default      |
    '----------------------+----------------------------------------+--------------'

    [Fri Dec  2 05:12:59 2005] [catalyst] [info] MyApp powered by Catalyst 5.57
    You can connect to your server at http://localhost:3000
    
    # point your browser to http://localhost:3000/?name=Joe
    # output should render:

    Välkommen till mitt ställe Joe!   
    

=head1 INTRODUCTION

=head1 INTERNATIONALIZATION

=head1 CONTENT NEGOTIATION

=head2 Server-driven

=head2 Agent-driven

=head1 LOCALIZATION

=head1 STAYING IN SYNC

=head1 TEMPLATE TOOLKIT

=head1 RESOURCES

=head2 Documentation

=head3 Definitions

=over 4

=item Internationalization and localization

L<http://en.wikipedia.org/wiki/Internationalization_and_localization>

=item Locale

L<http://en.wikipedia.org/wiki/Locale>

=item Byte Order Mark (BOM)

L<http://en.wikipedia.org/wiki/Byte_Order_Mark>

=item Character encoding

L<http://en.wikipedia.org/wiki/Character_encoding>

=item Collation

L<http://en.wikipedia.org/wiki/Collation>

=item Content Negotiation

L<http://en.wikipedia.org/wiki/Content_Negotiation>

=item Unicode

L<http://en.wikipedia.org/wiki/Unicode>

=back

=head3 Guides

=over 4

=item Guidelines, Checklists, and Resources

L<http://www.i18nguy.com/guidelines.html>

=item Localisation Guide

L<http://translate.sourceforge.net/wiki/guide/start>

=back

=head3 Perl

=over 4

=item Perl Locale handling

L<http://search.cpan.org/dist/perl/pod/perllocale.pod>

=item Perl Unicode introduction

L<http://search.cpan.org/dist/perl/pod/perluniintro.pod>

=item Perl Unicode support

L<http://search.cpan.org/dist/perl/pod/perlunicode.pod>

=item Unicode-processing issues in Perl and how to cope with it

L<http://www.ahinea.com/en/tech/perl-unicode-struggle.html>

=item Web Localization in Perl

L<http://search.cpan.org/dist/Locale-Maketext-Lexicon/docs/webl10n.html>

=item Localization and Perl: gettext breaks, Maketext fixes



( run in 0.516 second using v1.01-cache-2.11-cpan-98e64b0badf )