Translate text with PHP
Posted: Wed May 30, 2012 4:28 am
Hi,
i'm working on a website where i have to translate the text. i have to create 3 files:
lang_pt.php
lang_en.php
common.php
lang_pt and lang_en i create the array writing the translations and the common.php i include those files and call the arrays according to the language. if it's 'pt' it goes portuguese if 'en' english then the default - portuguese.
Then include the common in all the pages and do the "echo $lang['Contactos'].'<br />';".
Did you understand, i think i can be more clear.
Please help me...
i'm working on a website where i have to translate the text. i have to create 3 files:
lang_pt.php
Code: Select all
<?PHP
$lang['Family Office']="Family Office";
$lang['Multi Family Office']="Multi Family Office";
$lang['Foco']="Foco";
$lang['Serviços']="Serviços";
$lang['Valores']="Valores";
$lang['Seminários']="Seminários";
$lang['Contactos']="Contactos";
$lang['Português']="Português";
$lang['Inglês']="Inglês";
?>Code: Select all
<?PHP
$lang['Family Office']="Family Office";
$lang['Multi Family Office']="Multi Family Office";
$lang['Foco']="Foco";
$lang['Serviços']="Services";
$lang['Valores']="Values";
$lang['Seminários']="Seminars";
$lang['Contactos']="Contacts";
$lang['Português']="Portuguese";
$lang['Inglês']="English";
?>Code: Select all
<?php
include 'lang_pt.php';
include 'lang_en.php';
$lang = array('pt', 'en');
session_start();
if(isset($_SESSION['lang']) && array($_SESSION['lang'], $lang))
{
include 'lang_'.$_SESSION['lang'].'.php';
}
else
{
//Default
header ('Location: ?lang=pt');
die();
break;
}
echo $lang['Family Office'].'<br />';
echo $lang['Multi Family Office'].'<br />';
echo $lang['Foco'].'<br />';
echo $lang['Serviços'].'<br />';
echo $lang['Valores'].'<br />';
echo $lang['Seminários'].'<br />';
echo $lang['Contactos'].'<br />';
echo $lang['Português'].'<br />';
echo $lang['Inglês'];
?>Then include the common in all the pages and do the "echo $lang['Contactos'].'<br />';".
Did you understand, i think i can be more clear.
Please help me...