• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Starting homepage based on users browser language
PostPosted: Thu Jul 26, 2007 7:41 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Oct 25, 2006 8:29 pm
Posts: 4986
Location: Raalte, the Netherlands
For a MultiLanguage site I setup CMSMS in a specific way to have the language in the menu as first-level menu. It uses a UDT and switches to the default language of that user, showing all children (language specific pages) under that language.

My page structure looks like:

- Home
- NL
  - NLpage1
  - NLpage2
- EN
  - Enpage1
  - Enpage2
- FR
  - FRpage1
  - FRpage2

I created a UDT called "browserlanguage" that holds:

Code:
{
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($lang, 0, 2) == 'en')
{
header("Location: index.php?page=en");
} elseif (substr($lang, 0, 2) == 'fr')
{
header("Location: index.php?page=fr");
} else {
header("Location: index.php?page=nl");
}
}


The logic of the UDT, is to retrieve the language "if (substr($lang, 0, 2) == 'en')" leads to "en" and the page to be opened is "header("Location: index.php?page=en");", where "page=en" is the alias of the page to be opened.

Content-page 'Home' has this tag in the contentpage.

Insert in the template, where you want the flags to appear for the language. page="XX", where "XX" is the language page in the menu. This is to have the ability to choose a language different than their browser or the default.
Code:
   <div style="float: right;">
              {cms_selflink page="en" image="uploads/flags/lang_en.gif" alt="English" imageonly=1}
              {cms_selflink page="fr" image="uploads/flags/lang_fr.gif" alt="French" imageonly=1}
              {cms_selflink page="nl" image="uploads/flags/lang_nl.gif" alt="Nederlands" imageonly=1}
   </div>


The original {menu} needs an additional parameter (start_level) as it only has to show the children of the chosen parent,
Code:
{menu template='simple_navigation.tpl' start_level='2' collapse='1'}


By going to the site, the home-page will open, run the UDT and re-direct to the language set in the browser.

You can test this on http://demo.krijt.eu, where the code described above is active. For users on IE, the language pulled is the language on top in "Tools -> Internet Options -> Languages".

As you all can see the default language is "NL", so for most users that have their language set to "EN", the script should bring them to the English page.

Ronny


Last edited by RonnyK on Fri Aug 17, 2007 6:43 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Mon Jul 30, 2007 1:54 pm 
Offline
Support Guru
Support Guru

Joined: Mon Jul 24, 2006 3:27 pm
Posts: 3690
Location: Paris
Hello Ronny,

RonnyK wrote:
Code:
{
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($lang, 0, 2) == 'en')
{
 ...
} elseif (substr($lang, 0, 2) == 'fr')
{
 ...
} else {
 ...
}
}



Ronny, you know what ? you have begun to implement TCN in CMSms :-)

Pierre M.

_________________
-- Pierre, support team member. comodérateur du forum francophone.
Please read "how to submit installation/support requests" before posting. Don't send private messages to ask for support.
Want to contribute to CMSms ? Improve the wiki with your forum account.


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Tue Aug 14, 2007 1:08 pm 
Offline
Forum Members
Forum Members

Joined: Thu Apr 05, 2007 3:29 pm
Posts: 19
Thanks for your contribution Rony !
Very good job ! That's the cheapest solution I've ever seen !

Thanks :)


Last edited by DeMZed on Tue Aug 14, 2007 1:21 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Tue Aug 14, 2007 1:24 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Oct 25, 2006 8:29 pm
Posts: 4986
Location: Raalte, the Netherlands
DeMZed,

what do you exactly mean? The way the logic works is as follows. The UDT that is the only content in the page that is marked as the mainpage. The UDT determines the language that is set in the users browser.

F.E.

Code:
if (substr($lang, 0, 2) == 'en')
{
header("Location: index.php?page=en");


is that if the language is "en", the page to be opened is " index.php?page=en" the startpage for the English site. The calling of the menu, as these languages are the main-level of the menu, needs to be changed, to only show the child of the language level down. The examples of these changes are reflected in my opening topic.

Ronny


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Wed Aug 15, 2007 8:53 am 
Offline
Forum Members
Forum Members

Joined: Thu Apr 05, 2007 3:29 pm
Posts: 19
RonnyK wrote:
What do you exactly mean?


Well, I think our answer was just at the same moment I've edited my thread !
Your descriptions are enough clear to make it work ;)

Thanks


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Wed Aug 15, 2007 12:59 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 15, 2007 11:28 am
Posts: 44
Location: Auckland, New Zealand
Hi,

Firstly thanks for this post!

I used it to implement differnt menu items based which country flag the user selected. and it worked perfectly.

But I have a query.

Lets take the same example as RonnyK and add Company profile under NL.
- Home
- NL
  - CompanyProfile
  - NLpage1
  - NLpage2
- EN
  - Enpage1
  - Enpage2
- FR
  - FRpage1
  - FRpage2

If I have a Company Profile page under NL and I wanted it to be displayed under EN and FR as well? How would I do that? Why I am asking is because I am creating a website for a company who has branches in 3 different regions. The company profile is the same for all three of them. So is investor relations, Contact Us, etc...

And if I have sperate page under each country. I would need to edit all corresponding pages seperately? Is that correct?

Thanks in advance.

Any comments are welcome.

_________________
Asfahaan Mirza
Auckland, New Zealand


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Wed Aug 15, 2007 1:14 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Oct 25, 2006 8:29 pm
Posts: 4986
Location: Raalte, the Netherlands
I thought that you wanted to have the text on the page, in your case "CompanyProfile" to be different in the languages. If so, you can name the page and menu-page the same, while the page-alias on the options-tab should be different, for example "companyprofile-nl" and "companyprofile-de" the name in the menu and title can still be "CompanyProfile". All three pages are seperate pages and can be edited in the different languages.

If you want to share the text on the three pages, you should check "ContentAlias" in the development area.

Ronny


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Wed Aug 15, 2007 1:48 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 15, 2007 11:28 am
Posts: 44
Location: Auckland, New Zealand
Hi ROnny,

I think we are not realy on the same page... i think its my mistake as its 3am right now...

This doesnt have anything to do with different language.

Its for Global / Australia / New Zealand.

All are english based regions. Its just that i wanted to use the same content e.g. company profile on all of regions.... rather than having a seperate page for each of them.

i will look into "ContentAlias".

Thanks man

_________________
Asfahaan Mirza
Auckland, New Zealand


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Wed Aug 15, 2007 1:52 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Oct 25, 2006 8:29 pm
Posts: 4986
Location: Raalte, the Netherlands
The link:

http://dev.cmsmadesimple.org/projects/contentaliases/

Ronny


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Wed Aug 15, 2007 2:43 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 15, 2007 11:28 am
Posts: 44
Location: Auckland, New Zealand
Cheers for the link.. thats exactly what i wanted :) :) ta

_________________
Asfahaan Mirza
Auckland, New Zealand


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Mon Sep 03, 2007 6:34 am 
Offline
Forum Members
Forum Members

Joined: Sat Jul 07, 2007 11:26 am
Posts: 16
RonnyK wrote:
For a MultiLanguage site I setup CMSMS in a specific way to have the language in the menu as first-level menu. It uses a UDT and switches to the default language of that user, showing all children (language specific pages) under that language.

My page structure looks like:

- Home
- NL
  - NLpage1
  - NLpage2
- EN
  - Enpage1
  - Enpage2
- FR
  - FRpage1
  - FRpage2

I created a UDT called "browserlanguage" that holds:
.......

You can test this on http://demo.krijt.eu, where the code described above is active. For users on IE, the language pulled is the language on top in "Tools -> Internet Options -> Languages".

As you all can see the default language is "NL", so for most users that have their language set to "EN", the script should bring them to the English page.

Ronny



That is working excellent for me. One quirk is that the cms_selflink div=next when it gets to the end of one language displays the first page of the next language. This isn't nice so as a fix that kind of works for me I have created a patch on the cms_selflink code that only shows the next "sibling" i.e. the same menu parent. If you have gaps in your menus because it is jumping to the next language tree then the parent won't be the same so next doesn't display anything. I've called my option nextsibling

See,  http://dev.cmsmadesimple.org/tracker/in ... 6&atid=103


Top
 Profile  
 
 Post subject: Re: Starting homepage based on users browser language
PostPosted: Sat Sep 15, 2007 7:34 pm 
Offline
Forum Members
Forum Members

Joined: Mon Oct 23, 2006 4:43 pm
Posts: 78
Hi

I "scanned" only very quick over this thread and concerning the user language I think it would be way easier to use this:
http://techpatterns.com/downloads/php_l ... ection.php

Olaf

--
* together for better software *
* http://www.team-noehring.de *


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Arvixe - A CMSMS Partner