Many new developers think a multi-language website is very hard to build. For small sites it is not. This guide shows a simple method using one array per language, then explains when to move to a proper localization library.
Key takeaways
- Store each message in an array, one array per language.
- Use the same array key in every language.
- Print content through one variable so your HTML never changes.
- For large sites, use a localization library and add hreflang tags for SEO.
The concept: one array per language
Each message is stored in its own array for each language, and the same key identifies the same message in every array. A message with the key content1 has an English version in one array and another-language version in a second array.
$en_array['content1'] = "Message in English";
$other_language['content1'] = "Message in other language";
How to implement it
Use a single variable, $message, to print content on the page. The page always reads from $message['index'], so the HTML does not change. The language the visitor chooses decides which array is assigned to $message.
// When somebody chooses English
$message = $en_array;
// When somebody chooses another language
$message = $other_language;
// In your HTML
echo $message['content1'];
To add new content, add the same key to every language array and print it with $message['key'].
Important notes
- The array key must be identical in every language array.
- Print the same key through the $message variable in your HTML.
- Save the visitor's choice in a session or cookie so it persists between pages.
- This is the smallest and easiest approach. It is not fully optimized and suits small sites only.
When to use something bigger
For larger sites, use a proper localization library such as gettext or the translation component of your framework. Also give each language its own URL (for example /en/ and /fr/) and add hreflang tags so search engines show the right version to the right visitor.
Need a multilingual website built properly? Talk to our web development team.
Frequently asked questions
Is the array method good for large sites?
No. It works well for small sites. Large sites are easier to manage with gettext or a framework translation system.
How do I remember the visitor's language?
Store it in a session or cookie, or put the language code in the URL.
Does a multi-language site help SEO?
It can, if each language has its own URL and you use hreflang tags so search engines can match the right page to the right audience.



