use FindBin qw( $Bin );
use TopTable::Maketext;
has "lang" => (
is => "ro",
isa => "TopTable::Maketext",
builder => "_set_maketext",
lazy => 1,
);
sub _set_maketext {
my ( $self ) = @_;
my $class = $self->class;
my $app = $self->_app;
my (@locales, %inheritance);
my $config = $app->config->{I18N}{locales};
$app->log->debug( sprintf( "app: %s, class: %s", $app, $class ) );
printf( "app: %s, class: %s", $app, $class );
foreach my $locale (keys %$config) {
push(@locales, $locale);
$inheritance{$locale} = $config->{$locale}{inherits} if defined $config->{$locale}{inherits};
}
my $dir = Path::Class::Dir->new( "$Bin/..", "root", "locale" );
TopTable::Maketext->load_lexicon(
locales => \@locales,
directories => [$dir],
gettext_style => 1,
inheritance => \%inheritance,
);
return TopTable::Maketext->get_handle( "en_GB" );
}
####
sub _set_maketext {
return TopTable::Maketext->get_handle( "en_GB" );
}
####
package TopTable::Model::DB;
use strict;
use base 'Catalyst::Model::DBIC::Schema';
__PACKAGE__->config(
schema_class => 'TopTable::Schema',
connect_info => {
dsn => 'dbi:mysql:toptable',
user => '',
password => '',
}
);
use TopTable::Maketext;
sub ACCEPT_CONTEXT {
my ( $self, $c ) = @_;
# We have to check the ref of $c here because this model seems to get called by Catalyst as part of the instantiation, before my code kicks in
# and in these cases, $c is the string "TopTable", not a ref to the TopTable object.
$self->schema->_set_maketext( TopTable::Maketext->get_handle( $c->locale ) ) if ref( $c ) eq "TopTable";
return $self;
}
1;
####
use TopTable::Maketext;
has "lang" => (
is => "ro",
isa => "TopTable::Maketext",
writer => "_set_maketext",
);