Simple Language Selection for One Pager

Image | CC0 pixabay

When building a One Pager with Bootstrap, I sometimes need to implement a simple language switcher. I usually do this with PHP and have the index.php include head, header, content and footer according to the selected language. This approach has a significant advantage regarding design: I can set different languages depending on text length and make them all pretty independently.

Let’s assume we build our One-Pager in three languages: German, French and English with English being the default language. This is what you want to include at the top of your index.php.


The first thing we need to check is if the user has just switched languages with a click on the appropriate button or link. If french was clicked we would load the page with a GET-parameter ?fr, telling us that the french version has been requested. We can now write the choice to a cookie for later use and display everything in french.

If there has not been a GET-Parameter the user did not actively chose the language this time, but maybe he/she did before and we have that stored in a cookie already. If this is the case, we just take that language to display our page.

If neither of this has happened, we ask the user’s browser which language it accepts per configuration, and try to set our cookie and display-language accordingly. 


Share on facebook
Share on twitter
Share on linkedin

Related Posts

WooCommerce SQL

Howto Manipulate WooCommerce Metadata via SQL

With Germanized on board, WooCommerce has several ways to save article numbers. Has the intern spent two days entering the EAN in the wrong field for the 3000 articles in the WooCommerce online shop? Then an SQL superhero has to save the day who can copy content from one field to another in no time.

eCommerce Sales

5 eCommerce Lockdown Tips

eCommerce is booming because since Corona everyone understands the importance of online stores and digitization. We have been supporting online stores since the beginning of the millennium, when you still had to program them yourself, and we would like to tell you here how your eCommerce tools can make good sales and keep you afloat in a crisis.