How to Create Multilingual Website in PHP
Adding multilingual/multi-regional support to a website can be particularly challenging. Since you may have multiple versions of your site, any issues will be multiplied. Offering content in several languages can add many layers of complexity to web development. Translating articles is only one of them. To structure a multilingual website properly you have to follow several best practices for multilingual websites.
The first thing that is needed to create a multi-language PHP website is to create a couple of files that contain the text for each language that is supported by the site. You have to use a class that allows implementing multiple languages to the site developer by the PHP language.

The language class detects the browser automatically and displays the site content in the correct language and also helps to implement a system to change the language. These checks the HTTP request User-Agent and Accept Language headers and determine the users preferred language. It also loads the PHP scripts with locale text definitions for the preferred language.
I recommend to Use a framework or CMS. It doesn’t really matter which one – all the big names support this really well. I’ve built multi-lingual sites in Drupal and Symfony2, and their built-in support has made it really easy. There’s already a suggestion for Joomla – I’ve not used it, but it probably also has internationalisation support baked in. Don’t try and build it yourself in raw PHP. There are so many variations you would never even imagine in different languages.
Steps to create multilingual php website.
first build your data files, example :
hello_customer;Hello dear customer;
special_price;Special Price;
hello_customer;Bonjour cher client;
special_price;Prix spécial; |
Then install and configure redis (key / value in memory database).
Get the extension (for instance for php : https://code.google.com/p/phpredis/)
Now build a script to populate your redis database. Maybe something along these lines:
<?php $csv_path = 'path/to/csv/files'; function redis_import($f_name){ $handle = @fopen($f_name, "r"); $redis = new Redis(); $lang = explode('.', basename($f_name))[0]; if ($handle) { $redis->connect('127.0.0.1', 6379); while (($buffer = fgets($handle, 4096)) !== false) { list($key, $value) = explode(';', trim($buffer)); $redis->set($lang.'.'.$key, $val); } if (!feof($handle)) { echo "Erreur: fgets() a échoué\n"; } fclose($handle); } } if ($handle = opendir($csv_path)) { while (false !== ($entry = readdir($handle))) { if (!is_dir($entry)) { redis_import($csv_path.PATH_SEPARATOR.$entry); } } closedir($handle); } |
So whenever the csv files are modified, launch this script to populate the database.
Then you’ll need a function in your script to fetch language data.
You could use sessions to store user language. Assuming you used $_SESSION[‘user.lang’] to do so, you could craft something like this :
function __translate($key){ $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $translation = $redis->get($_SESSION['user.lang'] . $key); $redis->close(); return $translation; } |
This solution is very fast there are just memory accesses, and still with the usage of csv files the real database is safe, and easily human accessible.
IF you looking for PHP Multilingual Libraries or Examples for your web based application. If yes then in this post I am going to share hand picked top rated PHP Multilingual Libraries or Examples. You can use these popular PHP Multilingual Website Libraries or Examples to make your web application perform on multi language.
35+ PHP Multilingual Libraries or Examples
Following are the list of popular top rated hand picked PHP Multilingual Libraries or Examples.
- cms:- Multilingual PHP CMS built with Laravel and bootstrap
- Platform:- A modular multilingual CMS built with Laravel 5.
- package-metadata:- Multilingual package information for the Contao Manager
- linguist:- Easy multilingual urls and redirection support for the Laravel framework
- dokuwiki-plugin-translation:- Easily setup a multi-language DokuWiki
- Localization:- Localization package for Laravel 5
- laravel-translator:- An Eloquent translator for Laravel
- realurl_404_multilingual:- This TYPO3 extension creates a multilingual 404 page with realurl
- babel:- Babel is an Extra for MODx Revolution that creates linked documents across different contexts. The easy way for your m…
- yii2-translate-manager:- Translation Manager
- f3-multilang:- Create multilingual apps with this localization plugin for the PHP Fat-Free Framework
- TimeParser:- A parser for date and time written in natural language for PHP.
- multibyte-keyword-generator:- Extracts keywords from multibyte strings.
- php-translation-class:- Single-file php class to help building multilingual websites.
- yii-multilingual:- Multilingual toolkit for the Yii PHP framework.
- udemy.com-Multilingual-CMS-Website-with-PHP-MySQL-jQuery-code-examples:- [udemy.com] Multilingual CMS Website with PHP, MySQL, jQuery [2013, ENG]
- boxshop:- Laravel ecommerce platform
- langrid-php-library:- Multilingual Studio is a set of APIs for using the multi-language functions provided by the Language Grid, such as ba…
- four:- Bolt 4 prototype
- Nuclear:- Polymorphic CMS powered by Laravel 5
- slim-3-multilingual:- Middleware for multi language support in Slim 3 PHP framework
- multilingual:- A lib to replace get text php extension
- multilingual:- Exercise files for the course Multilingual Content Management System with PHP, MySQL and jQuery
- translate-wordpress:- Translate your WordPress website easily.
- phpBB-multilingual-forums:- Allows you to use multiple languages in forum and category names
- multilingual:- to retrieve. Of course you can pass any length of string following this criteria ‘dir.dir.dir.file.key’. dir: is a d…
- php-multilingual:- A simple Multilingual Web Application by PHP
- multilingual-php:- A multilingual sites in PHP
- php-multilingual:- Useful classes for working with multilingual apps
- pruebasPHP:- multilingual support
- Zen-Cart-Multilingual-EZ-Pages:- This module provides multi-language support for the EZ-Pages module that was included in the Zen Cart v1.3.0 release.…
- gestor-inventarios-it:- Sistema de Gestión de Activos Fijos con Laravel 5.7
- MultilingualSourceCode:- 使用ä¸åŒè¯è¨€å¼€å‘ ASP,PHP,JSP,JS,CSharp,nodejs,python
- Multilingual-Website:- Creating Multilingual Website With PHP
- PHPMultilingual:- Add PHP Multilingual Support
- phproject-docs:- Multilingual Phproject documentation site
- Forge:- A multilingual PHP framework
- Pair:- a lightweight PHP framework as the air
- cms:- A modular multilingual CMS built with Laravel 5.
- php-multi-lingual:- Multilingual web app in PHP
I Hope you liked Hand-picked list of PHP Multilingual Website Libraries or Examples, Don’t forget to Subscribe My Public Notebook for more useful Hand-picked PHP and MySql code examples, tutorials and articles.