I really can't do this in 10 lines, so I have tried to make it as clear as possible. Don't be frightened by the size of the topic and the amount of code. When you take a closer look at it, you will see the minor changes you have to make to let it all work. And you really don't need to have all explained features in a small multilingual website...
Beside some playing with basic CMSMS tags, you need to create an User Defined Tag.
This tag reads the language setting of the visitors webbrowser. This value is passed to the template with the parameter $lang. Based on this language the visitor is diverted to his language homepage, and creates the content of the Error 404 template.
Some features:
- Pretty urls like http://www.buispost.eu/e and http://www.buispost.eu/e/contact
- Opening the website root http://www.buispost.eu diverts the visitor based on browserlanguage automatically to the homepage of his language
- Uses different templates for each language, so no need to use cookies
- If set, internal links to the same pages with different languages. If not set, diverts to the language homepage
- Multilingual Breadcrumbs
- Error 404 page in browserlanguage
- Forms in different languages >>
- Search box in different languages >>
Okay, a few known shortcomings:
- You can't have a different style for an active parent, due to the Internal Link to the homepage. I use the Internal Link here, to get nicer URLs. The custom-url feature in the coming 1.9 will solve this I think. I will change this topic after the releasing of 1.9.
- Modules like News, CompanyDirectory, etc. can't have urls with the language step in it. But using detailpages for each language the layout will change.
1. Install pretty url
When you use pretty url (mod_rewrite) on the website you get the best results. At least thats my opinion... ;)
Look here to read which steps you have to take:
http://forum.cmsmadesimple.org/index.ph ... 912.0.html
Or do a quick search in the forum or wiki on this.
(Note: If you have questions on how to create pretty url, please don't use this multilingual topic... It is a bit off-topic)
2. Page structure
1 default [default page]
2 Start [Important: set page alias in options tab to 'nl']
2.1 Start [Set Internal Link to 2 ^ ]
2.2 Dutch page 1
2.3 Dutch page 2
3 Accueil [Important: set page alias in options tab to 'fr']
3.1 Accueil [Set Internal Link to 3 ^ ]
3.2 French page 1
3.3 French page 2
4 Anfang [Important: set page alias in options tab to 'd']
4.1 Anfang [Set Internal Link to 4 ^ ]
4.2 German page 1
4.3 German page 2
5 Homepage [Important: set page alias in options tab to 'e']
5.1 Homepage [Set Internal Link to 5 ^ ]
5.2 English page 1
5.3 English page 2
6 Error 404 [Errorpage 404]
3. Create UDT get_browserlanguage
Opening the right entry page based on the visitors browser language setting
UDT: get_browserlanguage
Code: Select all
$gCms = cmsms();
// Read browser language
$foo = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
// Only need the first two characters
$lang = substr($foo,0,2);
// Passing the parameter $lang to the template
$smarty = &$gCms->GetSmarty();
$smarty->assign('lang', $lang);
4. Call UDT in the default index page
Open Page 1 - index
Set the WYSIWYG editor off in the Options tab.
Put into the content field:
Code: Select all
{get_browserlanguage}
{if $lang == 'nl'}
{redirect_page page="nl"}
{elseif $lang == 'fr'}
{redirect_page page="fr"}
{elseif $lang == 'de'}
{redirect_page page="d"}
{else}
{redirect_page page="e"}
{/if}
5. Create Global Content Blocks with country flags
Create for each language a Global Content Block.
These blocks will show the flag images on the frontend and create the link to the alternative page in another language. If not set it will go to the language homepage.
Upload your own images to your folder, and edit the right path in the code below.
If you don't have any images yourself... You will find them here: http://en.wikipedia.org/wiki/List_of_countries
Global Content Block, named: flag-nl
Code: Select all
{if $dutch_version}
{cms_selflink page=$dutch_version image="images/layout/flag-nl.png" title="Nederlandstalige versie" alt="Nederlandstalige versie" imageonly=1}
{else}
{cms_selflink page="nl" image="images/layout/flag-nl.png" title="Nederlandstalige versie" alt="Nederlandstalige versie" imageonly=1}
{/if}
Code: Select all
{if $french_version}
{cms_selflink page=$french_version image="images/layout/flag-fr.png" title="Version Française" alt="Version Française" imageonly=1}
{else}
{cms_selflink page="fr" image="images/layout/flag-fr.png" title="Version Française" alt="Version Française" imageonly=1}
{/if}
Code: Select all
{if $german_version}
{cms_selflink page=$german_version image="images/layout/flag-de.png" title="Deutschsprachige Version" alt="Deutschsprachige Version" imageonly=1}
{else}
{cms_selflink page="d" image="images/layout/flag-de.png" title="Deutschsprachige Version" alt="Deutschsprachige Version" imageonly=1}
{/if}
Code: Select all
{if $english_version}
{cms_selflink page=$english_version image="images/layout/flag-uk.png" title="English version" alt="English version" imageonly=1}
{else}
{cms_selflink page="e" image="images/layout/flag-uk.png" title="English version" alt="English version" imageonly=1}
{/if}
6. Create a Global Content Block footer for each language
You can create for each language a different footer.
Besides text in different languages, you can also use this for different links to the language homepage, sitemap, copyright text, etc.
You should give the blocks the names:
- footer-nl
- footer-fr
- footer-d
- footer-e
7. Creating HTML templates
First thing you do is create a working HTML template based on only one language!!
If this one is working fine, you can copy it to create a template for each language.
In the following example templates you will find some basic layout parts.
In red you will see the small changes that are needed for each language.
You should add the code you need to your own template, and style it yourself.
Dutch template
Code: Select all
{process_pagedata}
{sitename} - {title}
{metadata}
{cms_stylesheet}
{menu template="accessible_simple_navigation.tpl" start_element='2.1' show_root_siblings="1" number_of_levels='3'}
{content block="german_version" assign="german_version" wysiwyg="false" oneline="true" label="Page alias German Alternative"}
{content block="english_version" assign="english_version" wysiwyg="false" oneline="true" label="Page alias English Alternative"}
{content block="french_version" assign="french_version" wysiwyg="false" oneline="true" label="Page alias French Alternative"}
{global_content name='flag-d'}
{global_content name='flag-e'}
{global_content name='flag-fr'}
{breadcrumbs starttext='U bent hier' root='nl' delimiter='>'}
{title}
{content}
{global_content name='footer-nl'}
Code: Select all
{process_pagedata}
{sitename} - {title}
{metadata}
{cms_stylesheet}
{menu template="accessible_simple_navigation.tpl" start_element='3.1' show_root_siblings="1" number_of_levels='3'}
{content block="dutch_version" assign="dutch_version" wysiwyg="false" oneline="true" label="Page alias Dutch Alternative"}
{content block="german_version" assign="german_version" wysiwyg="false" oneline="true" label="Page alias German Alternative"}
{content block="english_version" assign="english_version" wysiwyg="false" oneline="true" label="Page alias English Alternative"}
{global_content name='flag-nl'}
{global_content name='flag-d'}
{global_content name='flag-e'}
{breadcrumbs starttext='Vous êtes ici' root='fr' delimiter='>'}
{title}
{content}
{global_content name='footer-fr'}
Code: Select all
{process_pagedata}
{sitename} - {title}
{metadata}
{cms_stylesheet}
{menu template="accessible_simple_navigation.tpl" start_element='4.1' show_root_siblings="1" number_of_levels='3'}
{content block="dutch_version" assign="dutch_version" wysiwyg="false" oneline="true" label="Page alias Dutch Alternative"}
{content block="english_version" assign="english_version" wysiwyg="false" oneline="true" label="Page alias English Alternative"}
{content block="french_version" assign="french_version" wysiwyg="false" oneline="true" label="Page alias French Alternative"}
{global_content name='flag-nl'}
{global_content name='flag-e'}
{global_content name='flag-fr'}
{breadcrumbs starttext='Sie sind hier' root='d' delimiter='>'}
{title}
{content}
{global_content name='footer-d'}
Code: Select all
{process_pagedata}
{sitename} - {title}
{metadata}
{cms_stylesheet}
{menu template="accessible_simple_navigation.tpl" start_element='5.1' show_root_siblings="1" number_of_levels='3'}
{content block="dutch_version" assign="dutch_version" wysiwyg="false" oneline="true" label="Page alias Dutch Alternative"}
{content block="german_version" assign="german_version" wysiwyg="false" oneline="true" label="Page alias German Alternative"}
{content block="french_version" assign="french_version" wysiwyg="false" oneline="true" label="Page alias French Alternative"}
{global_content name='flag-nl'}
{global_content name='flag-d'}
{global_content name='flag-fr'}
{breadcrumbs starttext='You are here' root='e' delimiter='>'}
{title}
{content}
{global_content name='footer-e'}
Error 404 template
Code: Select all
{process_pagedata}
{sitename} - {title}
{metadata}
{cms_stylesheet}
{get_browserlanguage}
{if $lang == "nl"}
{menu template='accessible_simple_navigation.tpl' start_element='2.1' show_root_siblings="1" number_of_levels='3'}
{elseif $lang == "fr"}
{menu template='accessible_simple_navigation.tpl' start_element='3.1' show_root_siblings="1" number_of_levels='3'}
{elseif $lang == "de"}
{menu template='accessible_simple_navigation.tpl' start_element='4.1' show_root_siblings="1" number_of_levels='3'}
{else}
{menu template='accessible_simple_navigation.tpl' start_element='5.1' show_root_siblings="1" number_of_levels='3'}
{/if}
{if $lang != "nl"}
{global_content name='flag-nl'}
{/if}
{if $lang != "fr"}
{global_content name='flag-fr'}
{/if}
{if $lang != "de"}
{global_content name='flag-d'}
{/if}
{if $lang != "en"}
{global_content name='flag-e'}
{/if}
{title}
{content label="Dutch text" assign="content_dutch"}
{content block="german" wysiwyg="true" label="German text" assign="content_german"}
{content block="english" wysiwyg="true" label="English text" assign="content_english"}
{content block="french" wysiwyg="true" label="French text" assign="content_french"}
{if $lang == "nl"}
{$content_dutch}
{elseif $lang == "fr"}
{$content_french}
{elseif $lang == "de"}
{$content_german}
{else}
{$content_english}
{/if}
{if $lang == "nl"}
{global_content name='footer-nl'}
{elseif $lang == "fr"}
{global_content name='footer-fr'}
{elseif $lang == "de"}
{global_content name='footer-d'}
{else}
{global_content name='footer-e'}
{/if}
8. Changing template for the matching language
We want to have the template dropdown in the main tab of the page editor:
Site Admin >> Global Settings >> Advanced setup >> Basic Properties >> Select 'Template'
Now you can open each page and assign the matching language template.
9. Assigning page alternatives
When the website content is finished, you can assign alternative page aliases to each page.
In the page editor you will find 3 fields where you can fill in the page alias of the same page in a different language.
Clicking on a flag of a certain page will open the same page in a different language
10. The Error 404 page
Opening the Error 404 page in the page editor, you will find 4 editors.
Each language has his own WYSIWYG box.
You can write your own 404 message in these boxes.
When a visitor tries to open a not excisting page, the Error 404 template will create a page based on the browserlanguage.
For example the browserlanguage is set to French.
The navigation is in French, the content text is in French, the footer text is in French, and so on...
You should have a real multilingual website now...
It is a lot of text and code, I can't guarantee there aren't little errors in it right now. Please let me know it if you find one.
Hope this helps, Rolf :)