in a website I am creating I want to include several languages.
Below is how I identify what language should I show.
<?php
$pagename = $_SERVER["REQUEST_URI"];
if (strpos($pagename,'?en') !== false)
{
echo 'english';
here is when I have to include a language template file for english language.
}
?>
My goal is to include language template files instead of duplicating all of my websites for any language.
So what I think about it, is for example in index.php the variable will be the same for all languages, but the content will be changed.
<div id="main">
<?php echo $main_description; ?>
</div>
How should I include a language file for this to work?
$main_description ="this is the main description written in english"
You could use something similar to the if statement that you have and include the specific file with all the variables.
But here, all of your strings will be in variables an you have to be careful not to use/overwrite those variables in the rest of your code.
This page offers a pretty simple and easy to follow example on how to do it JSON encoded language file that the script loads and finds the text you want and returns the translated text.