Posted by Boland on March 21, 2010 at 7:15pm
I've translated the site using i18n module, everything works fine. I have to write some PHP code that, given default, original node ID, returns the full URL of the page.
So, e.g. full_url($nid=10) returns when English selected www.host.com/?q=node/10 , but in Dutch e.g. www.host.com/?q=nl/node/30
Is such a function available which will help me?
I have developed www.cloneboy.eu and in the image with products I've hardcoded the links to the product nodes. This will always show the English page. When you e.g. select French and click on a product, the English version is shown. In the block I want to make these URL's dynamic...
Comments
you can use this code, it
you can use this code, it make a list of translations for a given node #fnid (either current node or a different node)
<?phpglobal $language;
if(arg(0) == 'node' && is_numeric(arg(1))) {
$lList = array();
#$fnid = arg(1); #get current nid
$fnid = '6';
#$nl = $node;
$nl = node_load($fnid);
$nt = module_invoke('translation', 'node_get_translations', $nl->tnid);
foreach($nt as $fp) {
$fp->path = drupal_lookup_path('alias', 'node/'.$fp->nid, $fp->language);
$ll = language_list();
foreach($ll as $cl)
if ($cl->language == $fp->language) { $fp->native = $cl->native; $fp->prefix = $cl->prefix; }
$url_parts=parse_url((string)$_SERVER['SCRIPT_URI']);
$fl = l($fp->native, $fp->prefix?$fp->prefix.url($fp->path):$fp->path, $options = array());
array_push($lList, $fl);
}
print theme_item_list($lList, $title = NULL, $type = 'ul', array('id' => 'lLinks'));
}
?>
Thanks, I am going to try
Thanks, I am going to try this!
More simple way
Below is the code for getting translation of all nodes related to current node displayed. All links will be
inserted in $link array.
For Drupal 7 there is this
For Drupal 7 there is this method: http://api.drupal.org/api/drupal/includes!language.inc/function/language_negotiation_get_switch_links/7