Home / Blog / Web Development

Web Development

How to Develop a Multi-Language Website in PHP

Building a multi-language website is easier than many new developers expect. This guide shows the smallest approach that works for a small PHP site.

In this article
  1. The concept
  2. Implementation
  3. Important notes
  4. Bigger sites
  5. Frequently asked questions

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.

The Ucodice Team is a group of passionate developers, designers and strategists delivering web, mobile and software solutions to clients worldwide.

Ready to take the next step?

Explore our web development services or tell us about your project. A senior member of our team will get back to you with clear next steps.

Let's start your project

Tell us what you want to build or grow. We'll reply within one business day with clear next steps.

Phone: 9560430495  ·  Email: contact@ucodice.com

Office: Ucodice Technologies, IHDP Business Park, Street Number 7, Sector 127, Noida, Uttar Pradesh 201304. Also serving Delhi NCR and clients worldwide.

Trusted and certified

  • Google PartnerCertified for Google Ads
  • Meta business PartnerCertified for Meta Ads
  • 4.3 / 5 on Google47 Google reviews
  • 4.9 / 5 on Freelancer.in245 reviews

Free consultation

Tell us about your project.

Get a free quote