[dancer-users] Different INCLUDE_PATH for localized sites

Gabor Szabo gabor at szabgab.com
Thu Mar 28 09:38:13 GMT 2013


Hi,

The http://perl5maven.com/ site is using Dancer and Template::Toolkit.
Since the opening of the Brazilian Portuguese translation at
http://br.perl5maven.com/
They both run from the same instance of the application.

I made some change to accommodate for the multiple language - the source of
the pages are in separate directories now, and in the config.yml I
have a section
with some configuration parameters for each site.
The application itself looks at request->host and pick the correct
part of the configuration.

So far it was good, but there were a few things that were left in
English in the Portuguese site,
and some things where I had both the English and the Portuguese text
in the central template.
As I am expecting a few more translations to appear[1] I wanted to
split some of the templates too.

The problem I found is that I cannot set the  INCLUDE_PATH dynamically
as I don't seem
to have access to the Template::Toolkit object. If I am not mistaken
it is located in the
$_engine variable in the Dancer::Template::TemplateToolkit module and
it is not accessible
from the outside world.

So what I did was adding the following to the before hook:

# Create a new Template::Toolkit object for every call because we
cannot access the existing object
# and thus we cannot change the include path before rendering
my $engines = config->{engines};
$engines->{template_toolkit}{INCLUDE_PATH} = ["$appdir/views",
mymaven->{articles} . '/templates'];
Dancer::Template::TemplateToolkit->new( name => 'template_toolkit',
type => 'template' , config => $engines->{template_toolkit});


This is hacky. Do you have a better suggestion to solve this issue?


regards
   Gabor

[1] If you know someone who'd be interested in helping in
translations, please let me know.


More information about the dancer-users mailing list