Hi everyone - apologies, I'll try and make this as clear as I can. I have a Catalyst app that has internationalisation via
CatalystX::I18N. This includes the ability to call
$c->maketext($msgid, $params).
Essentially, I want to be able to use these in my DB model so that I can generate response messages in the relevant language. The only way I have thought of to do this so far (don't shoot me, I know it's not recommended!) is by passing $c->maketext as part of the parameters into the method I'm calling:
$c->model("DB::$resultset")->do_something({
language => sub{ $c->maketext( @_ ); }
});
What I would
like is to be able to use a maketext model (which seems to be available via
CatalystX::I18N::Model::Maketext) so that I can
use App::Maketext in my result and resultset classes and then use ->maketext() directly in those, if that makes sense?
I have set this up and can debug the following:
$c->log->debug( sprintf( "maketext: '%s'", $c->maketext("menu.title.
+news") ) );
$c->log->debug( sprintf( "model maketext: '%s'", $c->model("maketext")
+->maketext("menu.title.news") ) );
Both of these give the same output from the function calls:
[debug] maketext: 'News Index'
[debug] model maketext: 'News Index'
However, I don't seem to be able to call this from
outside Catalyst (which I need to be able to call it from the DB model) - I've run up a little test script and I was initially trying to load the config from my app's config file:
#!/usr/bin/perl
use strict;
use warnings;
use FindBin qw( $Bin );
use lib "$Bin/../lib";
use App::Maketext;
use Config::ZOMG;
my $config = Config::ZOMG->new( name => 'App' );
my $config_hash = $config->load;
my $maketext_info = $config_hash->{"Model::Maketext"};
my $lang = TopTable::Maketext->new($maketext_info);
printf "%s\n", $lang->maketext( "menu.title.news" );
However, I get the foillowing response:
maketext doesn't know how to say:
menu.title.news
as needed at bin\maketext-demo.pl line 16.
Then I thought I'd pass in the directories manually (at least for the time being):
my $dir = Path::Class::Dir->new( "$Bin/..", "root", "locale" );
my $lang = TopTable::Maketext->new(directories => $dir);
Finally I tried passing in the locale as well:
my $dir = Path::Class::Dir->new( "$Bin/..", "root", "locale" );
my $lang = TopTable::Maketext->new(directories => $dir, locales => "en
+-GB");
All of which give the same result. I am sure I'm missing something about the way it all hangs together and would be hugely greatful for any pointers that could be given!
Many thanks in advance.