Welcome to Geeklog, Anonymous Sunday, December 22 2024 @ 04:28 pm EST
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
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
11
10
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():
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_"
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_"
12
8
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
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
11
10
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
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
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
8
13
Quote
Status: offline
LWC
Forum User
Full Member
Registered: 02/19/04
Posts: 818
Better change
to
$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).
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).
9
9
Quote
All times are EST. The time is now 04:28 pm.
- 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