DarkDragonLord
New Member
- Messages
- 782
- Reaction score
- 0
- Points
- 0
Greetings guys!
Finally i could manage to find a great script that supports Multi-language websites WITHOUT databases
As always, no english tutorial could help me and never worked. So i've searched in my home language and gotcha, i found
Very nice for small / mid website but might be a little hard to manage in Big websites.
It uses only 1 + 1*x files (where X is the number of languages you want) then, 2 languages are 3 files.
Credits goes to user Cerrito (MRS) from " iMasters Fóruns " ( http://forum.imasters.com.br/index.php?showtopic=124045 ) that created the code
And zé_violeiro ( http://forum.imasters.com.br/index.php?showtopic=224115 ) that changed code to make it work with images instead of a Drop Down Menu.
I've translated most of the comments xD
Ok, Lets start!
First, create a file named setlanguage.php
Now, to the language files!
en.php or es.php or pt.php or anything .php.. Just remember of making sure to add it at setlanguage.php where check the language if valid.
pt.php
And en.php
explanation:
$texto['VARIABLE_YOU_WANT'] = "The meaning of the variable";
a better example:
You want to have all your Menu links to be language changeable.
so you make:
simple isn't it? always make the variable inside [' '] same in every languages
Ok, next step.
In the index.php (or the page you want) add at beggining:
For the Change Language Links / Images is this:
the $_SERVER is to make the php get itself, this way you dont need to write the php file name all time (so if you want to rename it later, you'll have to change in the links) and the php and echo is used with those arrays you set up at beggining of setlanguage.php. If you want a image instead of a name, just put
With all set up, now lets add our variables at where you want.
a common menu:
Now, the new menu that will change the names if changed language:
Its done!
When you change the languages, the menu automatically changes the names ^^
I think this could be made with all texts too but you will have to write each text twice, one in english one in the other language then add the <?php echo $texto['VARIABLE']; ?>
I hope this help most of people to make a Multi-language website.
I know, i could charge everyone to make it work for you but i think its better this way. (but i still can do for you if you are lazy enough for some credits )
see you ^^
If you think this tutorial post was helpful, click in the reputation button in the beginning of this post, in the right side (
).
And if you think it worth something i translated and shared it with you, i would be grateful if you donate some credits ^^
Finally i could manage to find a great script that supports Multi-language websites WITHOUT databases
As always, no english tutorial could help me and never worked. So i've searched in my home language and gotcha, i found
Very nice for small / mid website but might be a little hard to manage in Big websites.
It uses only 1 + 1*x files (where X is the number of languages you want) then, 2 languages are 3 files.
Credits goes to user Cerrito (MRS) from " iMasters Fóruns " ( http://forum.imasters.com.br/index.php?showtopic=124045 ) that created the code
And zé_violeiro ( http://forum.imasters.com.br/index.php?showtopic=224115 ) that changed code to make it work with images instead of a Drop Down Menu.
I've translated most of the comments xD
Ok, Lets start!
First, create a file named setlanguage.php
PHP:
<?php
/*** BY MRS 05/06/2004 ****\
* *** *
* this file check if the user choosed a language. If true, it changes and saves a cookie for that setting *
* with a 1month duration, so next time it comes, already is in the language he previously set. *
* if false, it check for a language cookie, if dont have, it get the browsers idiom and set as it *
* +++ *
/******************************************************** */
$texto['portuguese'] = "Portugues";
$texto['english'] = "English";
$texto['spanish'] = "Espanol";
// here you add the languages.
ob_start();
$default = "en"; // default will be english...
if( isset( $_GET['lang'] ) )
{
require $_GET['lang'] . ".php";
setcookie("saveLang", $_GET['lang'], time()+3600*24*30, '/'); // cookie that will expire in 1 month
}
else
if( isset($_COOKIE["saveLang"]) )
{
require $_COOKIE["saveLang"] . ".php";
}
else
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
require $default .".php";
}
else
{
$language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$language = substr($language,0,2); // splitting languages....
if( ( $language == "pt") or ( $language == "es") or ( $language == "en") ) // checking if language is valid .. here you can change or add the languages
{
require $language. ".php";
}
else
{
require $default . ".php";
}
}
ob_end_flush();
?>
Now, to the language files!
en.php or es.php or pt.php or anything .php.. Just remember of making sure to add it at setlanguage.php where check the language if valid.
pt.php
PHP:
<?
$texto['titulo'] = "Informações do sistema";
$texto['usada'] = "Usado";
$texto['livre'] = "Livre";
$texto['espacoTotal'] = "Tamanho";
$texto['dataHora'] = "Data/Hora";
$texto['nomeDaMaquina'] = "None do servidor";
$texto['dominio'] = "Dominio";
$texto['host'] = "Host";
$texto['uptime'] = "Tempo de vida";
$texto['numeroProcessos'] = "Numero de Processos";
$texto['sistemaOperacional'] = "Sistema operacional";
$texto['vKernel'] = "Versão do Kernel";
$texto['usuarios'] = "Usuários";
?>
And en.php
PHP:
<?php
$texto['titulo'] = "System Information";
$texto['usada'] = "Usage";
$texto['livre'] = "Free";
$texto['espacoTotal'] = "Space total";
$texto['dataHora'] = "Date/time";
$texto['nomeDaMaquina'] = "Computer Name";
$texto['dominio'] = "Domain";
$texto['host'] = "Host address";
$texto['uptime'] = "Server time life";
$texto['numeroProcessos'] = "Processors number";
$texto['sistemaOperacional'] = "Operational System";
$texto['vKernel'] = "Kernel Version";
$texto['usuarios'] = "Users";
?>
explanation:
$texto['VARIABLE_YOU_WANT'] = "The meaning of the variable";
a better example:
You want to have all your Menu links to be language changeable.
so you make:
PHP:
FOR EN.PHP
<?php
$texto['home'] = "Home";
$texto['downloads'] = "Downloads";
$texto['support'] = "Support";
$texto['contact'] = "Contact";
?>
FOR PT.PHP
<?php
$texto['home'] = "Página Inicial";
$texto['downloads'] = "Downloads";
$texto['support'] = "Suporte";
$texto['contact'] = "Contato";
?>
simple isn't it? always make the variable inside [' '] same in every languages
Ok, next step.
In the index.php (or the page you want) add at beggining:
PHP:
<?php
include "setlanguage.php";
?>
For the Change Language Links / Images is this:
HTML:
<a href="<?php $_SERVER['PHP_SELF'] ?>?lang=pt"><?php echo $texto['portuguese']; ?></a>
<a href="<?php $_SERVER['PHP_SELF'] ?>?lang=en"><?php echo $texto['english']; ?></a>
the $_SERVER is to make the php get itself, this way you dont need to write the php file name all time (so if you want to rename it later, you'll have to change in the links) and the php and echo is used with those arrays you set up at beggining of setlanguage.php. If you want a image instead of a name, just put
HTML:
<a href="<?php $_SERVER['PHP_SELF'] ?>?lang=en"><img src="IMAGE" border="0"></a>
With all set up, now lets add our variables at where you want.
a common menu:
HTML:
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=home">HOME</a> <br />
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=downloads">DOWNLOADS</a> <br />
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=support">SUPPORT</a> <br />
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=contact">CONTACT</a> <br />
Now, the new menu that will change the names if changed language:
HTML:
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=home"><?php echo $texto['home']; ?></a> <br />
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=downloads"><?php echo $texto['downloads']; ?></a> <br />
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=support"><?php echo $texto['support']; ?></a> <br />
<a href="<?php $_SERVER['PHP_SELF'] ?>?id=contact"><?php echo $texto['contact']; ?></a> <br />
Its done!
When you change the languages, the menu automatically changes the names ^^
I think this could be made with all texts too but you will have to write each text twice, one in english one in the other language then add the <?php echo $texto['VARIABLE']; ?>
I hope this help most of people to make a Multi-language website.
I know, i could charge everyone to make it work for you but i think its better this way. (but i still can do for you if you are lazy enough for some credits )
see you ^^
If you think this tutorial post was helpful, click in the reputation button in the beginning of this post, in the right side (
And if you think it worth something i translated and shared it with you, i would be grateful if you donate some credits ^^
Last edited: