Elxis CMS Forum

Support => General => Topic started by: ROUBOS on March 18, 2012, 17:49:38

Title: PHP for checking language?
Post by: ROUBOS on March 18, 2012, 17:49:38
Hi,
what's the php code we use when we want to check the language before we display some html code? For example display an image if Greek language is selected, and a different image when the English language is selected???

thanks
Title: Re: PHP for checking language?
Post by: webgift on March 18, 2012, 18:05:25
Hi,
In case that you want to write this piece of code inside a function you must call the global variable $lang first. In any other case such a index.php file of your template you can use the variable without call it.

global $lang;

if ($lang == 'greek') {
      echo '<img src="gr_image_path.filetype" alt="Image Description in Greek" width="80" height="80" />'."\n";
} elseif ($lang == 'english') {
     echo '<img src="en_image_path.filetype" alt="Image Description in English" width="80" height="80" />'."\n";
}
Title: Re: PHP for checking language?
Post by: ROUBOS on March 19, 2012, 12:14:33
Did not work. This is how I used it in my template's index.php:

Code: [Select]
<div id="banner-right">
if ($lang == 'Greek') {
echo '<a href="http://www.aslanisvillage.com/aitema-krateses.html"><img class="calendar-img" src="http://www.aslanisvillage.com/templates/aslanisvillage-template/images/reservation_request_gr.png" alt="Αίτημα Κράτησης" border="0" /></a>'."\n";
} elseif ($lang == 'English') {
echo '<a href="http://www.aslanisvillage.com/reservation-request.html"><img class="calendar-img" src="http://www.aslanisvillage.com/templates/aslanisvillage-template/images/reservation_request.png" alt="Reservation Request" border="0" /></a>'."\n";
}
</div>
Title: Re: PHP for checking language?
Post by: webgift on March 19, 2012, 14:11:44
You must open and close php ;)

<div id="banner-right">
<?php
            if ($lang == 'greek') {
               echo '<a href="http://www.aslanisvillage.com/aitema-krateses.html"><img class="calendar-img" src="http://www.aslanisvillage.com/templates/aslanisvillage-template/images/reservation_request_gr.png" alt="Αίτημα Κράτησης" border="0" /></a>'."\n";
            } elseif ($lang == 'english') {
               echo '<a href="http://www.aslanisvillage.com/reservation-request.html"><img class="calendar-img" src="http://www.aslanisvillage.com/templates/aslanisvillage-template/images/reservation_request.png" alt="Reservation Request" border="0" /></a>'."\n";
            }

?>         
</div>
Title: Re: PHP for checking language?
Post by: ROUBOS on March 19, 2012, 14:26:33
hahaha why didn't I think of that?
Thanks a lot.
Title: Re: PHP for checking language?
Post by: ROUBOS on March 19, 2012, 23:26:41
OK, what am I doing wrong, it's not showing anything now .
Code: [Select]
<div id="banner-right">
<?php
            
if ($lang == &#39;Greek&#39;) {
               
echo &#39;<a href="http://www.aslanisvillage.com/aitema-krateses.html"><img class="calendar-img" src="http://www.aslanisvillage.com/templates/aslanisvillage-template/images/reservation_request_gr.png" alt="Αίτημα Κράτησης" border="0" /></a>&#39;."\n";
            
} elseif ($lang == &#39;English&#39;) {
               
echo &#39;<a href="http://www.aslanisvillage.com/reservation-request.html"><img class="calendar-img" src="http://www.aslanisvillage.com/templates/aslanisvillage-template/images/reservation_request.png" alt="Reservation Request" border="0" /></a>&#39;."\n";
            
}

?>
         
</div>
Title: Re: PHP for checking language?
Post by: ROUBOS on March 20, 2012, 01:25:09
Problem was that Greek and English had to be entered in lower case greek, and english
Title: Re: PHP for checking language?
Post by: webgift on March 20, 2012, 11:20:22
Yes. It was my fault. ;) I corrected them.