Jump to content

Doc

Members
  • Posts

    108
  • Joined

  • Last visited

Everything posted by Doc

  1. Hi, How do you check if a user exists or not ? I'm using this code : $item = $users->get("email=example@processwire.com"); echo $item->name; but whatever the email exists or not, I never get null in $item. I also tried : if ($item) { case 1 else case 2 and case 1 always wins. Do I have to check $item->id then ? Thanks
  2. Hello (again), My project is a multilanguage one. On the homepage, I have a header menu where I display link of features, example : <?php $lg = $session->lg; echo $page->localHttpUrl("$lg").'dashboard'?> ?> My website displays french by default. The homepage is : www.website.com/ (in french default language) The link in the code above is rendered as : www.website.com/dashboard When I click on this link, it does a 301 -> www.website.com/fr/dashboard dashboard is a child page of the homepage. When I does the same in a non default language, such as 'en' / english for example, it doesn't do that 301 because the generated link in my code is www.website.com/en/dashboard I know there is an option in the core module LanguageSupportPageName to prefix the page of the default language by 'fr' (in my case), but apparently it's not recommended. "Choose Yes if you want the homepage of your default language to be served by the root URL / (recommended). Choose No if you want your root URL to perform a redirect to /name/ (where /name/ is the default language name of your homepage)." Maybe it's not recommended because it's causing a 301 when you arrive the first time on the homepage (from / to /fr). So how I could generate my link in the menu such as it displays www.website.com/fr ? I can do it by hacking some php of course, but perhaps there is a PW way to do it ? Thanks
  3. thanks Klenkes, I could think about a thing like that...
  4. Thanks Harmen, I can borrow some part of your code for future manipulation within the childen categories. Actually I have a header with a menu which displays all the children pages, hardcoded, I want them all displayed at once. So I don't have to navigate here. Links are for example : website.com/cycle/race -> show a list of that categories website.com/motorbike/roadsters -> show a list of that categories I was wondering myself how to handle the case where a user doesn't click on a link but directly go to website.com/cycle for example, and how to deal with that. I guess I can use your code to detect if /cycle has children page, if yes, display the first one for example, otherwise redirect to the homepage.
  5. Hi, I'm building new categories below the homepage, such as : home /cycle /race /city /motorbike /roadsters /sports How do you handle what's going on if a user hits /home/cycle only ? I have nothing to show here. For now I've associated /cycle with the 'basic-page' template... Do I have to redirect to the first sub-page such as /home/cycle/race for example ? or do you redirect to /home in such a case ? Thanks
  6. Thanks @LostKobrakai Well, I'm ok with that, but I'd like to catch that case (browser doesn't accept cookies) rather than displaying a too_many_redirect error message on the user's browser. Perhaps there is a way to do so ? Otherwise, for that particular case, I could use the url variable we were talking about yesterday, but the session solution was more elegant
  7. Hi guys, I'm hitting a "too_many_redirect" problem on a test I was doing by forcing my browser to not accept any cookies : if (!$session->lg) { echo "session not set<br>"; $lg = 'en'; $session->lg = $lg; echo $session->lg; // I see 'en' $url = $page->localHttpUrl("$lg"); echo $url; // I see the good URL : http://www.mywebsite.com/en $session->redirect("$url"); } else { echo "session set<br>"; exit; } I never hit the 'else' case and my browser eventually stops working and display a too_many_redirection error. How can I detect the $session->lg hasn't been saved correctly ? Thanks
  8. OK... I didn't know the guest user was associated with a language. I've just checked in the admin and it's 'fr', mystery solved, thanks !
  9. Hello, I'm wondering how that variable is filled up ? $user->language Language User language, applicable only if LanguageSupport installed. It says 'fr' for me, and it's the default language I chose for the website I'm building, is it taken from here ? Thanks
  10. Regarding the redirections, SEO purpose apparently, but I'm not expert in this. It also increases the loading time. I didn't know for the sessions, I think I can use that unexpected feature, thanks
  11. I should add : thanks for all the help you brought me this week-end @LostKobrakai !
  12. I'm speaking about a user who isn't logged in, so I suppose session can't work here ? ok for cookies or url. I've read other posts this afternoon and they confirmed it isn't very good to make a 301 or 302 as soon as you land on the homepage. So, for now, and only for the homepage, I've decided to use multi-language fields and I dynamically feed them with 'fr' or 'en' whatever the url is. $page->of(false); // turn off outputFormatting (if it's not already) $lg_id = $languages->get('en'); // get the language we want $body = $page->body->getLanguageValue($lg_id); // get the unformatted value in english That's many fields to add (30 maybe ?) but for now I'll go with that (on the homepage only). I'll see if I need to hack this later. I plan to buy Ryan's profiler to see the bottlenecks when I will be live, maybe the homepage won't show up
  13. hi, I have 2 languages defined, default (fr) and english (en). When I do : $lg_id = $languages->get('en'); // get the english language echo $page->myfield->getLanguageValue($lg_id); It displays english, fine. To display french I have to use 'default' : $lg_id = $languages->get('default'); // get the french language I'd rather have 'en' and 'fr' for example, is it possible ? I watched in the admin section area but 'default' is apparently a field I can't modify. Thanks
  14. Looks like a good idea but how to do that without falling into infinite redirect loops ? I mean, I'm doing this check in the homepage, the one loaded by www.website.com/ Let's take the scenario where my default url, www.website.com/ is french. A user comes in, english one, I detect english as its preferred language, he's not logged in. My code would be : $lg = detect_lg(); // retrieve the browser's preference here if((!$user->isLoggedin()) && ($lg != 'fr')) { $url = $page->httpUrl; // we now have 'http://www.website.com/' in $url $url .= 'en'; // we now have 'http://www.website.com/en' in $url $session->redirect("$url"); // goes to http://www.website.com/en } So at the end of that code, we're going to http://www.website.com/en/ and my home.php will start again inside that same 'if', which will go to http://www.website.com/en/en and -> not found. I can add something like '?redir=1' on the url uses by the first redirect so I can catch this later to avoid running one more time the 'if' block ? Another solution would be to make the redirect on the homepage (home.php template), and that homepage will only do that, and then redirect to a children page such as www.website.com/en/welcome ? What do you think ?
  15. Hi guys, I was advised to ask that question here rather than in general, so here it is : I detect the default language from the user browser. Let's say that user is not loggedin, I don't know anything about him. I'd like to display the page in the language retrieved from the browser. What I have now : - a multi-language homepage : displaying french (the default language) if user goes to www.website.com/ or english if user goes to www.website.com/en -> I'm using multi-language fields for that. I'm able to use translatable strings also, such as : echo __("My text to translate"); It works when I switch the url "/" to "/en" for example. I'd like to do that without manual intervention : - detect the browser's language - load the right version of the homepage (User not loggedin, never seen him before scenario). I know how to do it with multi-language : $page->of(false); // turn off outputFormatting (if it's not already) $lg_id = $languages->get('en'); // get the language we want $body = $page->body->getLanguageValue($lg_id); // get the unformatted value in english Is there a similar way to do it with translatable strings ? Thanks
  16. Good idea, I'm switching to the dedicated forum for this one.
  17. Thanks Robin S, I'm reading/testing stuff from the documentation right now. The menu is dynamic (the url changes according to the language setting, so does the text in the menu). I'm actually trying to find a solution to my first problem : https://processwire.com/talk/topic/15330-how-to-load-the-right-language/#comment-137135 I'm not still satisfied with my way to handle it. Lostkobrakai gave me translatable strings and now I'm trying to dynamically load them in the right language whatever the url (it works when I switch '/' to '/en'). I'd like to "force" the english translation without '/en' url...
  18. Thanks to both of you. @Robin S, I don't have URL in the links now but there will be soon I've just pasted the code before filling them. That menu is not designed to navigate within a single page but through the whole website.
  19. One more question I ask myself : I've just made a test and it works (echo __("...")) So, when do you choose to use that way of translating stuff vs use a textarealanguage field for example ? I guess if it's a huge description -> go for the field, and if it's tiny (a sentence or two) -> go for the translatable string ?
  20. ok... ! I've totally misunderstood that part. Thanks again for the explanations
  21. I've already read that one what makes me think I wasn't clear enough (or maybe I've myself misunderstood the documentation you pointed out) Actually I want to translate my menu, but not automatically through a translation function, I prefer to do that myself. Until now I'm using the multi-language-url functionnalities, I'm adding fields and translate them in the admin, and I'm happy with that, it works. I'm using it for large part of text, such as a feature description, and so on. The menu is composed of ~15 links and I don't know if I have to go with 15 fields more on the homepage or only one with html code inside.
×
×
  • Create New...