Ian Docherty wrote:
Christopher H. Laco wrote: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.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::BarWhat other alternatives are there? Regards IanWell, 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.e.g. existing MyApp::Controller::Foo::Bar maps to URI /foo/barTo 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.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!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 {}
It does just what just what Bill suggested. "I check if the prefix is a valid language (if it's one of the language files I loaded at startup), if so I then remove it from the request path and append it to the request base."In prepare_path.. you inspect the requested path.. yank out the language.. then pass along the remaining path...which should map to your existing controllers just fine.
As far as chained goes... I thought there was an example floating around that has Root::lang as Chained, then all other modules Chaine against /lang as their root instead of /...
-=Chris
signature.asc
Description: OpenPGP digital signature
_______________________________________________ List: [email protected] Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[email protected]/ Dev site: http://dev.catalyst.perl.org/
