CGI-Application-Plugin-I18N
view release on metacpan or search on metacpan
lib/CGI/Application/Plugin/I18N.pm view on Meta::CPAN
import within your calling objects namespace (Your CGI::App class)
=head2 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
C<I18N::LangTags> for more details.
If LIST is ommited then the method will attempt to figure out the users locale
using C<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;
=head2 localtext_lang
This method returns the currently selected language. This is the tag that was
lib/CGI/Application/Plugin/I18N.pm view on Meta::CPAN
min => [ qw(i18n_config localtext) ],
);
$VERSION = '0.03';
%DEFAULT_OPTIONS = (
Path => "$RealBin/I18N",
Style => 'gettext',
Export => '_maketext',
Decode => 1,
Encoding => '', # When set to locale, .po and .mo files that include a Content-Type cause the software to die?
);
sub i18n_config {
my $self = shift;
my $class = ref $self || $self;
local %DEFAULT_OPTIONS = %DEFAULT_OPTIONS;
if ( @_ ) {
lib/CGI/Application/Plugin/I18N/Guide.pod view on Meta::CPAN
=head2 Testing your demo .po file
Ok, now we are ready to test out your .po file and see it in action. Use your
browser to open the script potest.cgi.
I'm testing locally on my Vista IIS7. So /tmp/potest for me is actually
c:\inetpub\wwwroot\cgi-bin\potest, I'll be opening
http://localhost/cgi-bin/potest/potest.cgi in my browser.
You'll get a very basic HTML form asking for a locale, and showing small bits
of localized text (I do plan on an advanced version at some point). Enter in
I<en-us> and hit submit. You'll see all that has changed is I<Colour: Colour>.
Finally I wont have Americans moaning about how they can't spell colour or
cheque properly :P
If you enter in de then you'll get a german example that I've created as an
example of a more complete language pack (although my German is minimal, I used
babelfish to translate parts so it probably isn't structured correctly).
sample/potest/I18N/de.po view on Meta::CPAN
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-KeywordsList: localtext\n"
"X-Poedit-SearchPath-0: c:\\temp\\potest\n"
#: c:\temp\potest/potest.pm:43
msgid "PO file test"
msgstr "PO-Aktentest"
#: c:\temp\potest/potest.pm:44
msgid "Input locale"
msgstr "Eingangsschauplatz"
#: c:\temp\potest/potest.pm:45
msgid "Hello"
msgstr "Hallo"
#: c:\temp\potest/potest.pm:46
msgid "Colour"
msgstr "Farbe"
sample/potest/potest.pm view on Meta::CPAN
$self->i18n_config();
}#sub
sub test {
my $self = shift;
# Get CGI query object
my $q = $self->query();
$self->localtext_langs( $q->param( 'locale' ) );
my $template = $self->load_tmpl( 'test.html', die_on_bad_params => 0 );
$template->param(
{ scriptname => $RealScript,
title => $self->localtext( 'PO file test' ),
message => $self->localtext( 'Input locale' ),
hello => $self->localtext( 'Hello' ),
colour => $self->localtext( 'Colour' ),
locale => $q->param( 'locale' ),
}
);
return $template->output();
}#sub
sub teardown {
my $self = shift;
sample/potest/test.html view on Meta::CPAN
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><tmpl_var name=title></title>
</head>
<body>
<form action="<tmpl_var name=scriptname>" method=post>
<tmpl_var name=message>
<input type=text name=locale value="<tmpl_var name=locale>" />
<input type=hidden name=rm value=test />
<input type=submit />
</form>
Hello: <b><tmpl_var name=hello></b><br />
Colour: <b><tmpl_var name=colour></b>
</body>
</html>
( run in 1.166 second using v1.01-cache-2.11-cpan-ceb78f64989 )