1

I know this is may be already asked but i'm not sure how it's called....

All what I need is PHP file with all the text replacement.

E.G.

$logo = MY Website Logo;
$vTitle1 = Video Tile First;


This is what i need to have in future multiple language website.

Denis
  • 103
  • 3
  • 10
  • May be you can use this http://stackoverflow.com/questions/6953528/best-way-to-internationalize-simple-php-website – Timothy Ha Nov 08 '14 at 14:53

1 Answers1

1

You can create number of files(e.g en.php, fr.php) then you can include any of them using:

include_once("en.php");

or more generic and safe way (thanks to @Timothy for the suggestion):

$langArray = array( "en" => "en.php", "es" => "es.php", "fr" => "fr.php" );
if (isset($langArray[$_POST['lang']]));
    include_once($langArray[$_POST['lang']]);
else // default language
    include_once("en.php")

Since above code is loading variables according to file name(language name), same variables can refer to different(language specific) values. For example:

en.php

$welcome = "Hello";
$submit  = "Submit";
$cancel  = "Cancel";

es.php

$welcome = "Hola";
$submit  = "Bla bla";
$cancel  = "bla bla2";

And the usage:

<?php include_once("en.php"); ?>
<html>
...
<div id='greetings'> <?php echo $welcome . " " . $username; ?> </div>
Batuhan Tasdoven
  • 798
  • 7
  • 19
  • Instead of including $lang.".php" using data which came in $_POST, you can make it safer a little by making an array which points to filenames, like $langfile = array("en"=>"en.php", "ru"=>"ru.php", "es"=>"es.php"); then you can ask for $langfile[$_POST['lang']], and if it's not found, default to English, for example. – Timothy Ha Nov 08 '14 at 15:13
  • The the answer given here will work, it is not the proper way to localize a website. Take a look at [gettext()](http://php.net/manual/en/function.gettext.php). – dotancohen Nov 08 '14 at 15:22