1

I am using Internationalization module to translate content. How to get work this module with l function?

for example, when I create programatically link to content:

l(t('About us'), 'node/22');

I would like to achieve, that path 'node/22' will change when I switch website to another language. With Internationalization module, each translation of node creates another node, so I need to change paths in links on website.

For this time, I can create just if-else condition:

<?php
if ($language->language == 'en')
$output = l(t('About us'), 'node/22');
elseif (($language->language == 'de') 
$output = l(t('About us'), 'node/23');
?>

IS it possible to use l function in that way, that I don't need to write else-if condition?

2

There's no easy way to do this, but you can do something like this:

$nid = 22;
$node = node_load($nid);
if ($node) {
  $translations = translation_node_get_translations($node->tnid);
  $nid = isset($translations[$language->language]) ? $translations[$language->language]->nid : $nid;
}

Or use the Entity translation module, which relies on the ability of fields to have values in multiple languages and then the node id doesn't change.

| improve this answer | |
0

I would try:

l(t('About us'), t('node/22'));

and translate node/22 to node/23, but this maybe wrong it's just an idea.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.