Page 1 of 1

switching language

Posted: Fri Jan 04, 2008 10:48 pm
by linoleum
Hi,

I would like to have a bilangual website without flags to make switch the language.
I means , if we are in English and want to switch to French, you have just to click on "french" and when you are in French
just click on "English" but not have the both option in the same time.

I'm not a php developper but just a integrator. I would really appreciate if someone can help me to solve this issue.

Thanks

Re: switching language

Posted: Sat Jan 05, 2008 10:11 am
by alby
linoleum wrote: I would like to have a bilangual website without flags to make switch the language.
I means , if we are in English and want to switch to French, you have just to click on "french" and when you are in French
just click on "English" but not have the both option in the same time.

I'm not a php developper but just a integrator. I would really appreciate if someone can help me to solve this issue.
You must go to MLE version or wait for 2.0 release

Alby

Re: switching language

Posted: Sun Jan 20, 2008 12:05 am
by reneh
By using the top menu level as languages and use two diferent templates you should acomplish this.
Just hardcode the flags for the languages as top level and set the showing menu to start at level two.
Make the english flag show in the french template and the french flag in the english template. And set all english pages to english template and french to use french template.
(But then you click the flag you will always end on same landing page.)

Re: switching language

Posted: Sun Jan 20, 2008 6:52 am
by RonnyK
I use the top-level for the languages as well.....

I also use a UDT to show the browser-language as the first page to be shown, but that is optional....

http://forum.cmsmadesimple.org/index.ph ... 805.0.html

You dont need the UDT, and can set any page as the default landing-page, but with the UDT on the landingpage, you push the viewer to the page with their language if available, else it goes to the default-page......

Ronny

Re: switching language

Posted: Fri Sep 26, 2008 7:21 pm
by inyerface
linoleum wrote: Hi,

I would like to have a bilangual website without flags to make switch the language.
I means , if we are in English and want to switch to French, you have just to click on "french" and when you are in French
just click on "English" but not have the both option in the same time.

I'm not a php developper but just a integrator. I would really appreciate if someone can help me to solve this issue.

Thanks
Simple insert in the header of your website (or where you want users to toggle)
===================================================
English | French

NOTE: I changed the English and French acronym to "en" and "fr" (the defaults were "usa" and "fra" (sorry but Canadians are English and some French so I preferred to use a 2-letter acronym for the language instead of the originating Country))

I just installed this module moments ago - thank goodness for it and thanks to the developers!!  Here's what I did to quickly toggle between languages....

NOTE: I am using CMSMS Version 1.4.1

Good luck and enjoy this great addon!!

Re: switching language

Posted: Fri Sep 26, 2008 7:51 pm
by alby
inyerface wrote: Simple insert in the header of your website (or where you want users to toggle)
===================================================
English | French
This is MLE sintax, for language trees depend from method used

Alby

Re: switching language

Posted: Tue Sep 22, 2009 4:53 am
by joeri
I used to use the above code as well, just problem is that you will always be redirected again to the homepage. So what you basically want is to use the current URL with the language parameter added to it, so you will return to your current page, just within the language of your choice.

As I am fairly new to cmsms, I could not find an existing TAG to retrieve the current URL, so I wrote a small UDT named: get_url. It pretty much does what it says it does: returning your current URL. It comes with the options to remove and add certain variables.

How to use it? I created a global content block for the language options (so it changes with the language in MLE version or v2.x)

Code: Select all

<a title="English" href="{get_url add='hl=en_US'}"><img src="images/lang/gb.png" alt="English" /></a>
<a title="Nederlands" href="{get_url add='hl=nl_NL'}"><img src="images/lang/nl.png" alt="Nederlands" /></a>
<a title="Francais" href="{get_url add='hl=fr_FR'}"><img src="images/lang/fr.png" alt="Francais" /></a>
Note: You could unlink the language you are showing at the moment.

Code to insert into your UDT (User defined tag):

Code: Select all

/*
 * Get the current URL
 * Parameters:
 * - remove (array of vars to remove from URL)
 * - add (array of vars to add to URL)
 *
 * Examples:
 * {get_url remove="hl" add="hl=us_US:returnid=15"
 *
 * NOTE: Variables are seperated by a ":"
 
*/

$pageURL = 'http';
$REQUEST_URI = $_SERVER["REQUEST_URI"];
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
	$pageURL .= "s";
}
$pageURL .= "://";


if( isset($params['add']) || isset($params['remove']) ) {
	list($file_name, $file_params_string) = explode("?", $REQUEST_URI);
        if( stripos($file_params_string, "&") ) {
	        $file_params_array = explode("&", $file_params_string);
        } else {
	        $file_params_array = array();
		}
        foreach($file_params_array as $value) {
            if( stripos($value, "=") ) {
                list($k,$v) = explode("=", $value);
            } else {
                $k = $value;
                $value = "$k=";
            }
            $file_params[$k] = $value;
        }

        if( isset($params['remove']) ) {
		$params['remove'] = explode(":", $params['remove']);

                foreach($params['remove'] as $k) {
			unset($file_params[$k]);
		}
	}
	if( isset($params['add']) ) {
                $params['add'] = explode(",", $params['add']);
		foreach($params['add'] as $key) {
                        if( stripos($key, "=") ) {
                            list($k,$v) = explode("=", $key);
                        } else {
                            list($k,$v) = array($key, "");
                        }
			$file_params[$k] = "$k=$v";
		}
	}
	$REQUEST_URI = $file_name;
	if( count($file_params) ) {
		$REQUEST_URI .= "?" . implode("&", $file_params);
	}
}


if ($_SERVER["SERVER_PORT"] != "80") {
	$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$REQUEST_URI;
} else {
	$pageURL .= $_SERVER["SERVER_NAME"].$REQUEST_URI;
}
return $pageURL;
I am pretty sure the CMSMS Team will include something like this in the new version, but for now, it works for me.

Good luck!

Re: switching language

Posted: Wed Sep 23, 2009 9:01 pm
by alby
joeri wrote: I used to use the above code as well, just problem is that you will always be redirected again to the homepage. So what you basically want is to use the current URL with the language parameter added to it, so you will return to your current page, just within the language of your choice.

As I am fairly new to cmsms, I could not find an existing TAG to retrieve the current URL, so I wrote a small UDT named: get_url. It pretty much does what it says it does: returning your current URL. It comes with the options to remove and add certain variables.
Have you look to lang plugin?

Alby

Re: switching language

Posted: Sat Sep 26, 2009 5:22 am
by joeri
Found it yesterday... ahuh! :(

Thanks anyway.

PS. Too bad documentation is not up to date. I understand its done by fanatics in their spare time, just if they would list the functions/modules they write, ppl would at least know something exists like this.

Re: switching language

Posted: Sat Sep 26, 2009 7:55 pm
by alby
joeri wrote: PS. Too bad documentation is not up to date. I understand its done by fanatics in their spare time, just if they would list the functions/modules they write, ppl would at least know something exists like this.
Tips and Tricks #2

Alby

Re: switching language

Posted: Sun Sep 27, 2009 9:31 am
by joeri
Ok. I implemented it, but it doesnt get the correct URL for switching purposes when you are in a module. So, still need my own code to do this.

Thanks anyways.

Re: switching language

Posted: Sun Sep 27, 2009 9:21 pm
by alby
joeri wrote: but it doesnt get the correct URL for switching purposes when you are in a module.
Obviously that module does not use CMSMS API
It could be a problem with new versions of CMSMS

Alby