How to get the URL of an object in chosen language version

Author Message

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

Jean-Luc Nguyen

Thursday 12 November 2009 3:50:26 am

Thanks Kristof,

I'll check that and tell you if it works.

http://www.acidre.com

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 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 :)

"

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 29 2025 23:50:59
Script start
Timing: Jan 29 2025 23:50:59
Module start 'layout'
Timing: Jan 29 2025 23:50:59
Module start 'content'
Timing: Jan 29 2025 23:50:59
Module end 'content'
Timing: Jan 29 2025 23:50:59
Script end

Main resources:

Total runtime0.0113 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0046 588.3906151.2422
Module start 'layout' 0.00460.0018 739.632836.7109
Module start 'content' 0.00640.0038 776.343898.3594
Module end 'content' 0.01020.0011 874.703137.9922
Script end 0.0113  912.6953 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002017.4008140.0001
Check MTime0.00097.8443140.0001
Mysql Total
Database connection0.00076.548410.0007
Mysqli_queries0.001815.650630.0006
Looping result0.00000.069410.0000
Template Total0.00087.510.0008
Template load0.00065.549210.0006
Template processing0.00021.889010.0002
Override
Cache load0.00054.013610.0005
General
dbfile0.00021.907980.0000
String conversion0.00000.063140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs