[Catalyst] Multi-language and REST
Ian Docherty
catalyst at iandocherty.com
Fri Apr 25 15:26:43 BST 2008
Christopher H. Laco wrote:
> Ian Docherty wrote:
>> I have been pondering how to take an existing Catalyst application
>> and make it multi-lingual.
>>
>> I would prefer to use a RESTful method, so this would translate
>> /foo/bar to /en/foo/bar or /fr/foo/bar (for English and French
>> respectively).
>>
>> The problem as I see it is how to do this. I don't want to move all
>> my controllers, e.g. MyApp::Controller::Foo::Bar to
>> MyApp::Controller::Lang::Foo::Bar
>>
>> What other alternatives are there?
>>
>> Regards
>> Ian
>
> Well, I'm sure there's a somewhat elegant way to do this with Chained,
> but it the other controllers don't use Chained now, that could get fun.
I have considered chained, and would be prepared to re-write the
existing controllers. A bigger decision would be renaming the
controllers or moving them.
e.g. existing MyApp::Controller::Foo::Bar maps to URI /foo/bar
To match against /<lang>/foo/bar either I can leave the controller where
it is (lib/MyApp/Controller/Foo/Bar.pm) or move it
(lib/MyApp/Controller/Lang/Foo/Bar)
The first approach is less work (only using chained) the second is more
work, but maps the URI namespace more logically to the Class names.
What would people do if they were writing a Catalyst App from scratch
with this feature? That would tell me what the 'best practice' is even
if it means a big re-write exercise.
>
> The brute force way is to inspect the request and rip out the language
> portion before sending it on to get dispatched...just like the Flavour
> plugin does with file extensions:
>
> sub prepare_path {}
One of my pet peeves is exemplified in the 'Flavour' plugin. It is such
minimal documentation that it neither tells you what it does or why it
does it. OK, I can look at the code, but it is too much effort unless I
think I have a good reason to do so. I assume in this case that it is
something to do with date strings in the URI (for blogging?). I can't be
ar**d!
More information about the Catalyst
mailing list