Thursday 09 April 2009 3:17:57 am
Hi there, As I saw that on many forums people were asking about how to display flag picture instead of language name label, I thought it was good to put here an example of code to display just on flag if, for example your site has only two languages contents (for example French and English). With this piece of code, you'll be able to display an English flag when you're on a French content and a French flag when you're on an English content offering you the possibility to switch to the other language translation: The following has to be inserted in the pagelayout.tpl : at the beginning of the pagelayout.tpl I defined a variable which will get the right part (on 3 positions) of the current language code (for example if we are on a French content, the variable $langue will be equal to "fre-FR" and the variable $indice_langue will be equal to "fre" (you'll see why, below in this piece of code).
{def $langue = ezini( 'RegionalSettings', 'Locale', 'site.ini' )}
{set $indice_langue = $langue|extract_left(3)}
then I modify the div named "languages" which you find in the default pagelayout.tpl to make it fit the following
<div id="languages">
{* we read all available translation values (labels, codes of translations) of the site *}
{def $locales=fetch( 'content', 'translation_list' )}
<ul>
{foreach $pagedesign.data_map.language_settings.content.rows.sequential as $row}
{def $site_url = $row.columns[0]
$language = $row.columns[2]}
<li>
{*
if the current page language is not equal to the current read value of language translation
we display the flag of the language. It will do the job, as if I'm on a French content and the current value of translation is English, we will display the English flag.
*}
{if ne($row.columns[1],$indice_langue)}
<a href="{concat( "http://", $site_url,"/",
$DesignKeys:used.url_alias
)}">
{* my pictures are named flag_fre.gif and flag_eng.gif *}
<img src={concat('flag_', $row.columns[1], '.gif')|ezimage()} alt="{$language}" title="{$language}"/>
</li>
{/if}
{/foreach}
</ul>
</div>
If you have any suggestion concerning this please fill free to write. Best regards.
|