5102 Posts in 1520 Topics by 1116 members
|Go to End|
4 November 2009 at 6:42am
I need to extend Silverstripe to set the locale within the URL: e.g. /language-country/pagename
The following code is just a quick implementation but it works for nowâ€¦
1. First I had to add a new controller for extending the "ModelAsController" to handle the changed URL syntax:
2. Add a rule for calling the new controller within _config.php:
3. Rewrite the link targets (now with locale) within Page.php:
4. To allow setting the same page name in translated pages, I had to uncomment some lines within the core (SiteTree.php), which is definitely not the way it should be done. So if there are any new ideas please let me know!
It took a while to figure out that Versioned::reading_stage is not set when I use my "TranslatedModelAsController" -- if I use "ModelAsController" everything works as expected --therefore I added some lines with a small hack I found in the Silverstripe forums: TranslatedModelAsController > Line 17-22
Any improvements and comments are welcome!
6 November 2009 at 8:23am
Good to see its possible without too many modifications, thanks for sharing!
I think you'll get into trouble with the new nestedurls feature in trunk/2.4 though, so thats a "known limitation" I guess.
Would be nice if you could just "shift off" the first part of the URL after setting the locale, and re-initiating the request as normal.
7 November 2009 at 12:17am
Thanks Ingo for your hint!
Is the nestedurls feature in trunk stable enough to have a look on it to adjust my code? I'll have a try to "shift off" the first part of the url and do the rest as normal.
Best regards and greetings to NZ,
12 June 2010 at 10:10am
Sorry to dig this up again, but i just tried your approach with 2.4 and it throws an error:
Fatal error: Call to undefined method SiteTree::get_by_url() in /[...]/mysite/TranslatedModelAsController.php on line 96
Or is there another fix for this issue there? I already tried the pretty_i18n_url recipie and that didnt worked either (on 2.4).
Since i'm generating 5 translations for every new page automaticlly it looks pretty stupid with urls like
awesome would be something like
14 June 2010 at 8:58pm
Yes in 2.4 this proposal causes some errors. I will work on a version for 2.4 when I have time.
If you want to help, here are the two tasks to do:
1. Get and set locale from URL => something like that http://pastie.org/1003541
2. Allow same URL for pages in different langauges, have a look to the
Please let me know if you were successful
Thanks and best,
15 June 2010 at 4:09am
Yeah, would be awesome if you could make a 2.4 version. =)
I'm afraid I'm not that big of a help here, but i will try my best! Your little list of task is a good start, we will see how far i come ^^
23 July 2010 at 5:23pm
This subject is a very interesting option... I also need this way of URL rewriting... Is there already more information about it for SS 2.4.0?
18 October 2010 at 11:50pm
There is a working version for 2.4 version??
|Go to Top|