Soma Posted June 15, 2013 Share Posted June 15, 2013 Ryan the localUrl doesnt work if theres 404 thrown for a url. When you call a url that doesnt exist it will stay at that url and renders the 404 page. There it fails because something with the page names language module doesnt have a language set or something I cant remember. I think its maybe also only if not default language or the user has alternative language set. Try that changing user language and see. Link to comment Share on other sites More sharing options...
maba Posted June 16, 2013 Share Posted June 16, 2013 Ryan, is always the localUrl call. To try it locally: - install the default PW profile - install all the Language* modules - add a second language (Italian in my example) - in head.inc add <?php echo "<ul id='subnav' class='nav'>"; foreach($languages as $language) { if(!$page->viewable($language)) continue; // check if page not published for this language $url = wire('page')->localUrl($language); $title = $language->title; echo "<li><a href='$url'>$title</a></li>"; } echo "</ul>"; ?> Now call: http://pw.dev/ http://pw.dev/it/ http://pw.dev/http404/ http://pw.dev/it/http404/and there are no problems.. but if you call http://pw.dev/error http://pw.dev/it/error you can see the error in sidebar. Obviously if the menu is on the very top of the page you see only a blank page. Link to comment Share on other sites More sharing options...
ryan Posted June 16, 2013 Share Posted June 16, 2013 Thanks guys, these are good clear instructions. I will try to duplicate and fix here. Link to comment Share on other sites More sharing options...
maba Posted June 16, 2013 Share Posted June 16, 2013 Ryan, is always the localUrl call. ... http://pw.dev/error http://pw.dev/it/error Ooops.. to be clear (not a / problem.. ) http://pw.dev/error/ http://pw.dev/it/error/ Link to comment Share on other sites More sharing options...
ryan Posted June 18, 2013 Share Posted June 18, 2013 I've pushed an update that fixes this issue: https://github.com/ryancramerdesign/ProcessWire/commit/9e1f46d3d1c69bebbd0415f58baad627a0d194d2 It was also a fairly simple matter to make it identify the language from the URL, when present. So I added that too. Meaning, if something about the URL points to a language (like /it/ at the beginning, for example) then it'll deliver the 404 in Italian rather than the default language. 2 Link to comment Share on other sites More sharing options...
maba Posted June 19, 2013 Share Posted June 19, 2013 Thanks Ryan, it works well. In your opinion, make sense rewrite url in switch language menu when it deliver the 404 error page? $url = (wire('page')->template != 'notfound') ? wire('page')->localUrl($language) : wire('pages')->get('/')->localUrl($language); Link to comment Share on other sites More sharing options...
ryan Posted June 20, 2013 Share Posted June 20, 2013 I originally missed the issue with language switchers not working on the 404 page because all the instances where I'm using language switchers, I was only have it show the language switcher if the page was not the 404 page. The reasoning there is just that in my case, there wasn't much point in being able to show different language versions of a 404 page. If your situation is similar, I recommend simply not showing the language switcher when on a 404 page. Though if you want the switcher to redirect back to the homepage, that seems like another decent approach. But here's what I did: if($page->id != $config->http404PageID){ // render the language switcher } 2 Link to comment Share on other sites More sharing options...
maba Posted June 20, 2013 Share Posted June 20, 2013 Yes, good point. Thanks Link to comment Share on other sites More sharing options...
adrianmak Posted January 14, 2015 Share Posted January 14, 2015 how to setup two seperate trees for two language as illustrated in post #1 ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now