Welcome to Geeklog, Anonymous Monday, April 29 2024 @ 08:06 am EDT

Geeklog Forums

How to link to a multilingual page


Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Hello,

For a multilingual site I set 2 Language Files and 2 Languages in the config.

fr >> french
en >> english

I set also a contact_fr page and a contact_en page.

The question is: How to display the good page to users? If I use a link to the contact_fr page, how can I get the contact_en page if the user language is set to english?

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Do you mean how to link from within your site? You can only do it on your own in PHP staticpages/blocks using COM_getLanguageId():

Text Formatted Code

global $_CONF;
$contact = array(
'en' => 'Contact me',
'fr' => 'Contactez-moi'
);
$contact = $contact[COM_getLanguageId()];

echo COM_createLink($contact, COM_buildURL($_CONF['site_url'] . '/article.php/contact_' . COM_getLanguageId())); // don't forget the "_" in "contact_"
 
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Yes I try to make a contact page available in the menu elements via glmenu plugin.

Thanks.

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
The current concept (to avoid the word "hack" ...) doesn't support a language-neutral link to a multilingual page.

It's been a while since I used glMenu. Can you not hook up a function to a menu entry? That function could then use the correct link, depending on the current language.

bye, Dirk
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Yes thank you.

So I added a function in the lib-custom.php file

Text Formatted Code
function glmenu_showpage_contact() {
 
    global $_CONF;
       
    $labels = array(
        'en' => 'Contact me',
        'fr' => 'Contactez-moi'
    );

        $label = $labels[COM_getLanguageId()];
        $retval = '<li>' . COM_createLink($label, COM_buildURL($_CONF['site_url'] . '/staticpages/index.php/contact_' . COM_getLanguageId())) . '</li>';
       
        return $retval;
}


and set this function in the glmenu Edit menuitem aera.

It's working but it's a long job because I need to set this for 20 different labels (1 per page) and I will need to implement a new function for each new page.

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Better change
Text Formatted Code
$label = $labels[COM_getLanguageId()];

to
Text Formatted Code

$default = "en";
$label = "";
if (isset($labels[COM_getLanguageId()]))
   $label = $labels[COM_getLanguageId()];
elseif (isset($labels[$default]))
   $label = $labels[$default];
 


Right now you have to hardcode the default. There's a feature request of having a setting for it (and a corresponding function to retrieve it).
 Quote

All times are EDT. The time is now 08:06 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content