Forums / Developer / How to get the URL of an object in chosen language version
Jean-Luc Nguyen
Tuesday 03 November 2009 4:28:20 am
http://ez.no/fr/developer/forum/developer/how_to_get_url_of_an_object_in_chosen_language_version
As in Piotrek KaraĆ code example, both $node->urlAlias() returns same URL, but $node->name() returns localised node titles.
<?php $node = eZContentObjectTreeNode::fetch( 67, 'pol-PL' ); //default lang var_dump( $node->urlAlias() ); $node = eZContentObjectTreeNode::fetch( 67, 'eng-US' ); var_dump( $node->urlAlias() ); ?>
http://www.acidre.com
Kristof Coomans
Saturday 07 November 2009 6:59:11 am
Hi Jean-Luc
Apparently the urlAlias() method does not take into account the language you fetched the node in. It completely relies on eZURLAliasML, which on its turn relies on eZContentLanguage and the prioritized language list as defined for your site access.
Although I did not try this, I think you can modify the prioritized language list, get the URL alias you want, and then restore the prioritized language list to its original value. Some code that might get you started:
$node = eZContentObjectTreeNode::fetch( 67, 'eng-US' ); $originalPrioritizedLanguages = eZContentLanguage::prioritizedLanguageCodes(); eZContentLanguage::setPrioritizedLanguages( array( 'eng-US' ) ); var_dump( $node->urlAlias() ); eZContentLanguage::setPrioritizedLanguages( $originalPrioritizedLanguages );
Let us know if that worked :)
independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org
Thursday 12 November 2009 3:50:26 am
Thanks Kristof,
I'll check that and tell you if it works.
Andy Caiger
Monday 28 December 2009 6:19:03 am
What I want to do is have the same URLs in all the different languages, basically turn off multilanguage URL aliases, or (to put it another way) force all siteaccesses to show the URL aliases for the main language. Do I have to write a custom method like the above or is there an easier way, like a setting somewhere, that will do this? Thanks!
EAB - Integrated Internet Success Offices in England, France & China. http://www.eab.co.uk http://www.eab-china.com http://www.eab-france.com
Pablo Pernot
Wednesday 19 May 2010 5:35:31 am
hi Kristof, I have needed that and I can say now it works well. thanks
Pablo Pernot http://www.smartview.fr http://www.areyouagile.com