mkchris has asked for the wisdom of the Perl Monks concerning the following question:
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:
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->model("DB::$resultset")->do_something({ language => sub{ $c->maketext( @_ ); } });
Both of these give the same output from the function calls:$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") ) );
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:[debug] maketext: 'News Index' [debug] model maketext: 'News Index'
However, I get the foillowing response:#!/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" );
Then I thought I'd pass in the directories manually (at least for the time being):maketext doesn't know how to say: menu.title.news as needed at bin\maketext-demo.pl line 16.
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);
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.my $dir = Path::Class::Dir->new( "$Bin/..", "root", "locale" ); my $lang = TopTable::Maketext->new(directories => $dir, locales => "en +-GB");
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Catalyst: accessing maketext from a model
by kcott (Archbishop) on Jan 21, 2022 at 13:35 UTC | |
by mkchris (Sexton) on Jan 21, 2022 at 14:59 UTC | |
Re: Catalyst: accessing maketext from a model
by mkchris (Sexton) on Jan 21, 2022 at 12:35 UTC | |
Re: Catalyst: accessing maketext from a model
by mkchris (Sexton) on Jan 22, 2022 at 00:29 UTC |
Back to
Seekers of Perl Wisdom