NAME

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

SYNOPSIS

use CGI::Application::Plugin::I18N;

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    => 'locale',
);

$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!' );

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'.

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.