NAME

Cake::Plugin::I18N

SYNOPSIS

##in your settings.json
{
    "plugins" : [
        "I18N" : {
            "path" : "/full/path/to/your/language/files",
            "lang" : "en"
        },
        ....
    ]
}

##or in your App.pm
plugins [
    'I18N' => {
        path => '/full/path/to/your/language/files',
        lang => 'en' #default language
    },
    ....
];

###now create your language files inside language folder
###you set above {lang}.po

##-- en.po
msgid "test"
msgstr "test Hello from english file"

##-- ar.po
msgid "test"
msgstr "مرحبا بك"

##this plugin will export set_lang() & loc() functions to your application by default

use Cake 'Controller';

get '/lang' => sub {
    my $self = shift;
    my $c = shift;
    
    my $text = $c->loc('test');
    $c->body($text);
};

###to change language
$c->set_lang('ar');

Description

I18N Cake Plugin is a simple pure Perl translation plugin

Methods

loc(%args)

$c->loc('Hello %1 %2',['mamod','mehyar']);

##or
$c->loc('Hello',['mamod','mehyar']);

##and in your po file
##please make sure msgid match the first argument in loc() method

##-- en.po
msgid "Hello %1 %2"
msgstr "Hello %1 %2"

##-- ar.po
msgid "Hello %1 %2"
msgstr "%2 %1 مرحبا بك"

set_lang()

accepts a single string argument which defines the current language

$c->set_lang('ar');

Sub translations

Sometimes your translation files are huge and better with distributing them across multiple files, to do that you can create a sub folder under your original language path with the same name as the language so for english files for example create a sub folder "en" then put .po files inside with different name like "forms.po"

To call that file instead of the default translation file "en.po" you need to pass an array ref as the first argument to your loc method for fisrt index is the file to be called.

$c->loc(['form','Hello %1 %2'],['Mamod','Mehyar']);
##this will call "Hello %1 %2" msgid from
##/path/to/translation/en/form.po

1 POD Error

The following errors were encountered while parsing the POD:

Around line 130:

Non-ASCII character seen before =encoding in '"مرحبا'. Assuming CP1252