Share » Forums » Developer » Example of code for one flag picture...

Example of code for one flag picture for translation

Example of code for one flag picture for translation

Thursday 09 April 2009 3:17:57 am - 3 replies

Modified on Thursday 09 April 2009 8:46:30 am by Mahmoud BECHAA

Author Message

Yannick Komotir

Thursday 09 April 2009 7:26:04 am

hi,

why don't use the native code ?

{def $site_languages=ezini('RegionalSettings', 'SiteLanguageList')}
{def $locales=fetch('content','locale_list')}
{foreach $site_languages as $lang}
        {foreach $locales as $locale}
                 {if eq($locale.locale_code, $lang)}
                 <a href={concat('index.php/',$locale.language_code|downcase())|ezroot}>
       <img src={$locale.locale_code |flag_icon} alt="{$locale.language_name}" title="{$locale.language_name}"/>&nbsp;
   </a>
                     {break}
                 {/if}
        {/foreach}
{/foreach}

<|- Software Engineer @ eZ Publish developpers -|>
@ http://twitter.com/yannixk

Mahmoud BECHAA

Thursday 09 April 2009 8:45:07 am

Yes Yannick,

Your code is cleaner and easier. I didn't try it but I think that it should work fine. I'll make a try as soon as possible. Thank you for this suggestion.

I tried also to preserve, as much as possible, the default code of pagelayout.tpl template page (a newbie reflex).

Yours Sincerely.

Mahmoud BECHAA

Friday 10 April 2009 3:26:04 am

After testing Yannick's Code, I finally kept my initial code as it was not really what I wanted to do. Yannick's code scans the whole language possibilities of EZP and displays flags for all languages (Catalan, Spanish, Chinese, Japanese, English, Canadian...). It was not really what I wanted to do. My aim was to display just One flag (on the two translation languages which are avalaible on my site, see my first post upper in this page).

Changing Yannick's code to something a bit lighter, could do the job except for language_name to be displayed as tip which, for the moment, I did'nt find an easy way to get it passing the equivalent locale_code. So, if someone has some advice concerning this ...

Here is the code which I tested and works correctly (except for what I said) :


<div id="languages">

         {def $langue = ezini( 'RegionalSettings', 'Locale', 'site.ini' )}
         {def $site_languages=ezini('RegionalSettings', 'SiteLanguageList')}




{foreach $site_languages as $lang}


                {if ne($langue, $lang)}
                <a href={concat('index.php/',$lang|extract_left(3)|downcase())|ezroot}>
		      <img src={$lang |flag_icon} alt="{$lang}" title="{$lang}"/>&nbsp;

                 </a>


                    {break}


                {/if}




{/foreach}

</div>   




You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu