NAME

Data::Localize - Alternate Data Localization API

SYNOPSIS

use Data::Localizer;

my $loc = Data::Localizer->new();
$loc->add_localizer(
    class     => "Namespace", # Locale::Maketext-style .pm files
    namespace => "MyApp::I18N"
);

$loc->add_localizer( 
    class => "Gettext",
    path  => "/path/to/localization/data/*.po"
);

$loc->set_languages();
# or explicitly set one
# $loc->set_languages('en', 'ja' );

# looks under $self->languages, and checks if there are any
# localizers that can handle the job
$loc->localize( 'Hellow, [_1]!', 'John Doe' );

# You can enable "auto", which will be your last resort fallback.
# The key you give to the localize method will be used as the lexicon
$self->auto(1);

DESCRIPTION

Data::Localize is an object oriented approach to localization, aimed to be an alternate choice for Locale::Maketext, Locale::Maketext::Lexicon, and Locale::Maketext::Simple.

BASIC WORKING

STRUCTURE

Data::Localize is a wrapper around various Data::Localize::Localizer implementors (localizers). So if you don't specify any localizers, Data::Localize will do... nothing (unless you specify auto).

Localizers are the objects that do the actual localization. Localizers must register themselves to the Data::Localize parent, noting which languages it can handle (which usually is determined by the presence of data files like en.po, ja.po, etc). A special language ID of '*' is used to accept fallback cases. Localizers registered to handle '*' will be tried after all other language possibilities have been exhausted.

If the particular localizer cannot deal with the requested string, then it simply returns nothing.

AUTO-GENERATING LEXICONS

Locale::Maketext allows you to supply an "_AUTO" key in the lexicon hash, which allows you to pass a non-existing key to the localize() method, and use it as the actual lexicon, if no other applicable lexicons exists.

# here, we're deliberately not setting any localizers
my $loc = Data::Localizer->new(auto => 1);

print $loc->localize('Hello, [_1]', 'John Doe'), "\n";

Locale::Maketext attaches this to the lexicon hash itself, but Data::Localizer differs in that it attaches to the Data::Localizer object itself, so you don't have to place _AUTO everwhere.

UTF8

All data is expected to be in decoded utf8. You must "use utf8" for all values passed to Data::Localizer. We won't try to be smart for you. USE UTF8!

DEBUGGING

DEBUG

To enable debug tracing, either set DATA_LOCALIZE_DEBUG environment variable,

DATA_LOCALIZE_DEBUG=1 ./yourscript.pl

or explicitly define a function before loading Data::Localize:

BEGIN {
    *Data::Localize::DEBUG = sub () { 1 };
}
use Data::Localize;

METHODS

add_localizer

Adds a new localizer. You may either pass a localizer object, or arguments to your localizer's constructor:

$loc->add_localizer( YourLocalizer->new );

$loc->add_localizer(
    class => "Namespace",
    namespaces => [ 'Blah' ]
);

localize

Localize the given string ID, using provided variables.

$localized_string = $loc->localize( $id, @args );

detect_languages

Detects the current set of languages to use. If used in an CGI environment, will attempt to detect the language of choice from headers. See I18N::LanguageTags::Detect for details.

add_localizer_map

Used internally.

set_languages

If used without any arguments, calls detect_languages() and sets the current language set to the result of detect_languages().

Actuall

TODO

Gettext style localization files -- Make it possible to decode them Check performance -- see benchmark/benchmark.pl

AUTHOR

Daisuke Maki <daisuke@endeworks.jp>

Parts of this code stolen from Locale::Maketext::Lexicon::Gettext.