PHP

Language Translation in PHP

This article will teach about you the language translation in PHP, by saving the body texts into an array we can translate the words into any language. Simply we need to save the texts in .php file as an array and echo the array in the body page. Below is a simple example for language translation in php. Language translation in PHP is very simple, texts in an array and echo it in the files where do you want to display the texts in other languages.

First create a folder called lang and check the permissions it has 755

Create language files

Create language files and save it to seperate folder in their language code name. All the language files and folders that are all inside of the ‘lang’ folder must be in the name of thier language code.

First create we will create language folder and file for English,

Create a folder called ‘en’ inside of the ‘lang’ folder and create a php file inside ‘en’ folder called ‘en.php’

Thus the ‘en.php’ containing directory will be like this :

for more languages create the language files like above. In this example i have created files for 3 languages like,

Put your texts in ‘en.php’ file in an array for English:

Put your texts in ‘ar.php’ file in an array for Arabic:

Put your texts in ‘es.php’ file in an array for Spanish:

Create a library file outside of ‘lang’ folder:



Design the index file:

Finally the directory design will be like this:

NOTE : For single language jus remove the select box in index file and change the $_SESSION[“language”] = “en”; value in library