Lyle Hopkins > CGI-Application-Plugin-I18N > CGI::Application::Plugin::I18N

Download:
CGI-Application-Plugin-I18N-0.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.03   Source  

NAME ^

CGI::Application::Plugin::I18N - I18N and L10N methods for CGI::App

SYNOPSIS ^

Nothing is exported by default. You can specify a list of individual methods or use one of the groups :std, :max or :min.

    use CGI::Application::Plugin::I18N qw( :std );

Within your setup, cgiapp_init, cgiapp_prerun or specific runmode routine add the line

    $self->i18n_config();

Or

    $self->i18n_config( %options );

%options are the same as for Locale::Maketext::Simple. If none are passed the following default are used:-

    %DEFAULT_OPTIONS = (
        Path        => "$RealBin/I18N",
        Style       => 'gettext',
        Export      => '_maketext',
        Decode      => 1,
        Encoding    => '',
    );

$RealBin being the folder from which the executed cgi script is running. Note that Export must remain as _maketext for this module to function properly!

For instance if you wanted to use maketext style markup in your lexicons you would use the line:-

    $self->i18n_config( Style => 'maketext' );

Then use the localtext method to localize text:-

    print $self->localtext( 'Hello World!' );

DESCRIPTION ^

This module is a wrapper around Locale::Maketext::Simple by Audrey Tang. It extends the CGI::Application object with variour methods to control the localization of text. A "FAQ" is provided with the aim to fill in the gaps.

Methods ^

i18n_config

Runs the initial configuration of Locale::Maketext::Simple and runs it's import within your calling objects namespace (Your CGI::App class)

localtext_langs

Sets the current language for localtext output. Usage:-

    $self->localtext_langs( LIST );

LIST must consist of valid language tags as defined in RFC3066. See I18N::LangTags for more details. If LIST is ommited then the method will attempt to figure out the users locale using I18N::LangTags::Detect.

This method will also return the list of language tags as an array reference.

    my $langtags = $self->localtext_langs( LIST );
    print @$langtags;

localtext_lang

This method returns the currently selected language. This is the tag that was actually available for use, after searching through the localtext_langs list. This is the name of the module used in your MyAPP::I18N::XXX namespace (where XXX is the name of the lexicon used)

    my $lexicon = $self->localtext_lang;

localtext_lang_tag

This method returns the RFC3066 language tag for the currently selected language. This differs from the above method which would most likely return en_us for American English, whereas this method would return en-us.

    my $langtag = $self->localtext_lang_tag;

localtext

This is the method that actually does the work.

    print $self->localtext( 'Hello World!' );

loc

You can choose to import a shorter method called loc that works the same way as localtext. You need to specify this when you use the module:-

    use CGI::Application::Plugin::I18N qw( loc );
    print $self->loc( 'Hello World!' );

Export groups

:max exports:-

    i18n_config localtext_langs localtext_lang localtext_lang_tag localtext loc

:std exports:-

    i18n_config localtext_langs localtext_lang localtext_lang_tag localtext

:min exports:-

    i18n_config localtext

FAQ ^

How does it all work?

I kept a blog on how I put this module together and all the material I looked through in order to understand internationalization. http://perl.bristolbath.org/blog/lyle/2008/12/giving-cgiapplication-internationalization-i18n.html

What is a Lexicon?

Think of it as a kind of hash. Where the text you use (usually english) has a corrosponding value in the local language. So the 'Hello world' under a German lexicon would have the value 'Hallo welt'.

Is there some sort of guide?

Yes I've written one. CGI::Application::Plugin::I18N::Guide See Guide.pod which is part of this distribution. It'll walk you through what you need to know, and how to make your lexicons.

Thanks to:- ^

Catalyst::Plugin::I18N - The module this one was heavily based on

Locale::Maketext::Simple - Making it possible

Locate::Maketext - Doing all the hard work

CGI::Application - Providing the framework

And all others I haven't yet mentioned.

Come join the bestest Perl group in the World! ^

Bristol and Bath Perl moungers is renound for being the friendliest Perl group in the world. You don't have to be from the UK to join, everyone is welcome on the list:- http://perl.bristolbath.org

AUTHOR ^

Lyle Hopkins ;)

syntax highlighting: