Skip to content
Advertisement

Using the HTML Select tag to switch between languages in a multilingual website

Before
I have a website that i built to switch from English to Dutch just by clicking on a hyperlink i.e <a>
I had 2 files; de.php and en.php with following structures;

de.php

JavaScript

en.php

JavaScript

To load a specific language. User only has to click on the hyperlink

JavaScript

index.php

JavaScript

Now, there’s need for me to add other languages such as french, portugese and spanish. so I prepared
fr.php, pt.php and sp.php ` fr.php

JavaScript

etc for pt.php and sp.php

having users using links to load lnaguage of their choice isnt so professional and may be cluster the website.
So resorted to using select tag.

index.php

JavaScript

How do I go about this so that if a user selects a particular langauge from the drop down menu, the index.php page will load the corresponding sp.php or pt.php or en.php or fr.php accordingly?

Do I need AJAX for this as the page will have to reload without user having to submit or button?Obviously, there is submit button.

You can visit www.betensured.com to see the behaviour am looking for.
Observe how the page changes upon selecting a different language from the drop-down menu.

Advertisement

Answer

Here’s what I’ve done in a project

JavaScript

At the root of the project I had my languages sections (/fr/ , /en/, /esp/ …) each directory contain an index.php file, so when I select my language option the selected_language/index.php is loaded

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement