Skip ›Navigaton

Adding a language selector feature

2 April 2010

For a recent site that I created I wanted to add a language selector. I had look around the internet to try and find a suitable solution, but i couldn’t find any, so I developed my own. My finished solution seems to work perfectly for the site. if you want to add such a feature you can view my solution below.

This feature was created using php.

Here is the code for the buttons:-

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="image" name="lang" src="images/Flag_of_Italy.png" value="Italian" /> <input type="image" name="lang" src="images/language/Flag_of_Germany.png" value="German" /> <input type="image" name="lang" src="images/language/Flag_of_the_United_Kingdom.png" value="English" /> <input type="hidden" name="submitted" value="true" /> </form>

So I used flags for each of the buttons to represent the different countries. You will also need to add a value as i have done with the name of the country’s language.

Next you will need to add the following code the top of each of your pages:-

if (isset($_POST[‘submitted’])) { setcookie(‘language’, $_POST[‘lang’], time()+604800); header(“Location: index.php”);
}

if (isset($_COOKIE[‘language’])) { $cookieText = $_COOKIE[‘language’];
} else { $cookieText = “English”;
}

include(“text/” . $cookieText . “.php”);

If this is the first time on the site then this code adds a cookie to the user’s computer. It defaults the language to english. If one of the buttons is clicked then $_POST[‘submitted’] becomes true and then the users cookie gets updated with new value from the button. The language files come from a folder on the system called text. Inside here are several different php files. one for each language and each one is picked out depending on what the variable $cookieText is changed to.

In the ‘text’ folder pages, the following code is applied –

define(‘HOME_PAGE_MAIN’, ‘

As a web des…….

‘);
define(‘FREE_FRENCH_SITES_TITLE’, ‘Learn french the free way’);
define(‘FREE_FRENCH_SITES’, ‘

There are many…….’);
define(‘ADD_SITE_TITLE’, ‘Submit a suggestion’);

etc…….

And then you place the echo HOME_PAGE_MAIN . "<br />" where you want to add the text.

You can see this action on my Connect French site. Even though as the time of writing i’ve only added two languages it’s now very easy to add more.

Make a comment


New site - ConnectFrench.com

7 February 2010
ConnectFrench.com

A New site that i’ve created as a self project is now live at Connect French. I used this site to practice new php skills. I used the new mySQLi functions which should make my future sites more secure but resulted me having to upgrade my server to PHP 5, which i was a bit nervous about but my other sites on the server were all fine.

The site also includes a custom built CMS which i choose to use instead of using Textpattern as i did on this site.

Make a comment


Screen capture for the Mac

11 December 2009

One of the few things that I liked on the PC over the Mac was the keyboard print button. I use this button all the time on the PC at work. If there is an image on a site or on the screen that I want to copy and paste into photoshop then I simply press print and then control-v into Photoshop. For years on the mac I thought the only way to do this was to use the screen capture application Grab. Today I have found a mac tip on the apple web-site buried deep down in the pages giving me a shortcut to provide me with the same functionality as the print button on the PC. That short cut is Control-Shift-Command-3 . I now programme that into one of the F-keys and voila.

Make a comment


Best games for the Mac

26 October 2009
Machinarium

I’m not a big action game player and it’s just as well as I own a mac. If you want to buy a computer that has lots of games you don’t buy a mac. I just want to share 3 games that i’ve bought and played over the past year that I 100% recommend every mac user to try. If you’re like me and really love the witty creative puzzle game that has great presentation with lots of thought for the user and game play then I’ll think you’ll love these.

Machinarium(£11.87) – Click here for link

Braid($14.95) – click here for link

world of goo($20) – click here for link

If anyone has a suggestions for me then please add them to the comments. Thanks.

Make a comment


New site - Greenball

15 September 2009
Greenball

I’ve recently seen a new site go live that I helped to design, develop, build and will mantain. If anyone needs any Banner stands, pop Up displays, exhibition stands, display systems, posters or banners then please consider using Greenball. We are based Near Bristol (UK) so if you live in or near Bristol you can collect otherwise we will deliver. I’m Currently working on the SEO and the interest in the site is so far promising. The site was built using Zencart and we used worldpay as a payment system in order to take card payments.

Make a comment


My first After Effects CS4 Video

16 August 2009
After Effects CS4 Video

I’ve been learning After Effects CS4 for the past few months. I’ve learnt this mainly from both a Peach Pit learning book simply called After Effects CS4 and From two sets of learning videos on Lynda.com. Essential training and beyond the basics. From this, I’ve managed to create a 19 second intro movie for a potential new website I have in the works called IwannlearnFrench.com. I’ve uploaded the video to YouTube. Check it out here – After Effects intro video

Make a comment


New .tel domains

20 June 2009
telnic

I decided to jump aboard and grab myself one of the new .tel domain names that were not aloud to the general public until march 6th 09. This is not an ordinary domain but is a place to store contact details and allow its users to use this to pass out their contact details.
Reading the website of the .tel creator, Telnic (www.telnic.org). They show lots of promise for more future usage options. I bought into this and got one. I tried Jason, jayce, jas, jay, jace. Unfortunately all gone. I didn’t want jasoneyermann.tel as I wanted to forgo spelling my name if I were to pass out my contact details. I ended up choosing jason123.tel (www.jason123.tel). The telnic site said that .tel sites were SEO proficient but has yet to rate my name or jason123 in the google search engine.

Make a comment


BMW ad

25 May 2009

I came across this great BMW ad on the net. I hope it’s real.

Make a comment