manlio Posted February 21, 2017 Share Posted February 21, 2017 Hello, I have a problem and I'm not sure if it is an intended behaviour or not. I'm building some url with something like echo $page->url.$item->name but the $item->name remains the same in every language although is translated. In my mind I was thinking it automatically changes based on language, but this doesn't happen. Is this a normal behaviour or am I missing something? Thank you Link to comment Share on other sites More sharing options...
Harmen Posted February 21, 2017 Share Posted February 21, 2017 Hi Manlio, Are you sure you've set a name in different languages? So if your page is called 'Prodotti' in Italiano, is it 'Products' in English? ~Harmen 1 Link to comment Share on other sites More sharing options...
manlio Posted February 21, 2017 Author Share Posted February 21, 2017 Yes I have set different names for each language. As a test I tried with $item->title (also translated) and it works. Link to comment Share on other sites More sharing options...
Wanze Posted February 21, 2017 Share Posted February 21, 2017 The name property is not translated, it is a unique identifier for a page together with the parent_id. You should not build urls manually like this, you should use the following method: $page->localUrl() See: https://processwire.com/api/ref/page/ Edit: The name is translated as well, but calling $page->name always returns the (unique) name of the default langauge. Use $page->localName() to get the translated name of a language. 3 Link to comment Share on other sites More sharing options...
manlio Posted February 21, 2017 Author Share Posted February 21, 2017 Ok Wanze thank you! As I suspected is an intended behaviour. In this case, I don't need to get the full url because I have to rebuild a "fake" URL. I'm filtering records based on Urlsegments and names. I think that I can solve the link problem using something like //instead of echo $page->url.$item->name // I can use echo $page->url.sanitizer->pageName($item->title) but now I have a new problem when I arrive in the destination page where I filter records like this $pages->find("template=mytemplate,pageref_category.name=$urlSegment1"); //now this doesn't return anything because it is comparing something like "prima-categoria" with "first-category" My new question is : How can I properly filter records based on every languages? Is there any alternative still using Urlsegments? Thank you for your help. Link to comment Share on other sites More sharing options...
manlio Posted February 21, 2017 Author Share Posted February 21, 2017 Thanks to this post I discovered that I can access local names in this way $item->localName($user->language) Now I just need to understand if it is possible to do the same thing in a selector to filter the results. EDIT: I have just found that I'm not alone Link to comment Share on other sites More sharing options...
Robin S Posted February 21, 2017 Share Posted February 21, 2017 10 hours ago, manlio said: Now I just need to understand if it is possible to do the same thing in a selector to filter the results. To find a page using a multilanguage name you have to append the ID of the language to 'name' in your selector. Each multilanguage page name is stored separately like this. So suppose you had a page named 'three' in the default language, and added a French name for the page 'trois'. In a simplified example, if you wanted to get the page by name in the default language you would do... $p = $pages->get("name=three"); But if you wanted to get the page by name in French you would do... $p = $pages->get("name1234=trois"); ...where 1234 is the ID of the French language. So if you are working from the user's language you could do... $p = $pages->get("name{$user->language->id}=trois"); 1 1 Link to comment Share on other sites More sharing options...
manlio Posted February 22, 2017 Author Share Posted February 22, 2017 Thank you Robin S. I had tried before this approach but I receive this error Unknown subfield: name11658 When I used in a selector like this template=mysubcategory,pageref_category.name{$user->language->id}=$urlSegment1 //pageref_category is a multiarray page field type) So I tried a different not elegant route that uses directly title. Before putting into the selector I convert the dashes into spaces $urlTitle1 = str_replace("-", " ", $urlSegment1); //convert dashes into spaces //the selector becomes something like template=mysubcategory,pageref_category.title=$urlTitle1 Now everything seems to work although maybe I can have new problems if the title has to remain the same in different languages. Anyway now I ahve a new problem (or maybe I'm tired ) I have a multiarray page fieltype and I'm using alternate multilanguage fields. The problem is that when I use this $selector = "template=prodotto,pageref_categoria.title=$urlTitle1"; $items = $pages->find("$selector"); although the user changes language, it continues to filter data based on pageref_categoria default language.... Maybe I need a rest Link to comment Share on other sites More sharing options...
Robin S Posted February 22, 2017 Share Posted February 22, 2017 1 hour ago, manlio said: I had tried before this approach but I receive this error Unknown subfield: name11658 Maybe the multilanguage name is not made available as a subfield. You could do this: $p = $pages->get("name{$user->language->id}=$urlSegment1"); // you should probably include a parent or template in this selector too $selector = "template=mysubcategory,pageref_category=$p"; As for the other problem, it looks like your screenshot shows the name of those pagefields is different for each language. So you need to search the right one for the language: pageref_categoria or pageref_categoria_en or pageref_categoria_fr. 1 Link to comment Share on other sites More sharing options...
manlio Posted February 22, 2017 Author Share Posted February 22, 2017 Thank you very much Robin S I will try without using sub selector. For the second problem ok! I read better the documentation and I think I need to target every language. Thank you! 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