Author image Nicholas Wehr
and 1 contributors

NAME

Catalyst::Plugin::Localize::Simple

SYNOPSIS

    in MyApp/lib/MyApp.pm

        use Catalyst 'Localize::Simple';

    in controller

        print $c->localize('de','theking');
     

    or harness the power of this module; when you have stored the language preferences in the session

        ...
        $c->session->{lang} = $c->req->param('language');
        ...
        $c->stash->{bio} = $c->socal('theking');
        $c->stash->{template} = $c->socal('welcome.tt2');
        ...
        $c->lang; # the language code

    from a template

        [% c.socal('theking') %]
      
        <a href="http://www.mysite.com?lang=[% c.lang %]">click here</a>
     

DESCRIPTION

This module allows you to setup and access language files very simply by defining dictionary YAML files for configuration. If you're looking for something a little more robust - check out Catalyst::Plugin::I18N and family. The dictionary files are accessed via YAML::Syck to ensure high performance.

This module intentionally avoids caching the data files to allow for "hot-swapping" of dictionary changes (won't require a Catalyst restart).

CONFIGURATION

    __PACKAGE__->config(
        'Localize::Simple' => {
                                        _sessionkey     => 'lang',
                                        en                                      => 'root/localize/en.yaml',
                                        de                                      => 'root/localize/de.yaml',
                                        fr                                      => 'root/localize/fr.yaml',
                                }       
    );

    in root/localize/en.yaml...

        ---
        yes: certainly
        no: nope
        welcome.tt2: welcome-en.tt2
        theking: Elvis Aaron Presley was an American singer, actor, and musician.

    in root/localize/de.yaml...

        ---
        yes: ja
        no: nein
        welcome.tt2: welcome-de.tt2
        theking: Elvis Aron Presley war ein US-amerikanischer Sänger und Schauspieler  

    maybe you should put your language files in a consistent location; like this:

        root/
        |
        `-- localize
            |-- de.yaml
            |-- en.yaml
            |-- es.yaml
            |-- fr.yaml
            |-- it.yaml
            `-- ja.yaml

METHODS

setup (internal Catalyst plugin constructor)

note: defines a default language 'en'

sessionkey

this is the session variable that is defined in the configuration file

note: defines a default key of 'lang'

lang

returns the language code as stored by your application (into $c->session->{$key} or $c->req->param($key))

note: returns the default language 'en' when neither are specified

localize (lang, term)
loc (lang, term)

this method is the meat and potatoes of this module. it will return the defined term in the dictionary for lang.

if a term is not found, this method will return a string _MISSING_TERM_|term. term is the term you asked for. this is very handy for tracking down missing terms.

localize_from_session (term)
socal (term)

this method combines the work of lang and localize into one handy little method call.

why is it called socal? just a plug for my hometown San Diego, California! ;)

AUTHOR

Nicholas Wehr <nicholas.wehr@bionikchickens.com>

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

1 POD Error

The following errors were encountered while parsing the POD:

Around line 83:

Non-ASCII character seen before =encoding in 'Sänger'. Assuming UTF-8