Hi i am devloping sample site in php i need to translate whole website in to persian. how can it possible in php?? I have tried using the following code.. This code will working fine for deutsch conversion.
1. class.translation.php
2.Register.php
*
*
»
Is it possible to transilate to other laguages using this code?? I changed register1.php?lang=de to register1.php?lang=fa[persian].. But nothing hapens..anybody plese help
asked Nov 1, 2012 at 7:20
4
AS per me you can try this method.This method is already implemented in our system and it is working properly.
Make php file of each language and define all the variables and use those variables in pages.
for e.g For english
english.php
$hello="Hello";
persian.php
$hello=html_entity_decode[htmlentities["سلام"]];
Now use this variable to page like this.
your_page.php
You have load specific language file as per get language variable from URL.
It is better that you have define this language variable into config file.
config.php
if[isset[$_GET['lang']] && $_GET['lang']=='persian']
{
require_once['persian.php'];
}
else
{
require_once['english.php'];
}
answered Nov 1, 2012 at 8:27
HkachhiaHkachhia
4,3136 gold badges38 silver badges74 bronze badges
3
If I were you, I'd do it like this:
/inc/lang/en.lang.php
define['_HELLO', 'Hello'];
/inc/lang/fa.lang.php
define['_HELLO', 'سلام'];
index.php
// $_SESSION['lang'] could be 'en', 'fa', etc.
require_once '/inc/lang/' . $_SESSION['lang'] . 'lang.php';
echo _HELLO;
Benchmark: Constants vs. Variables
Here you see why I offered using Constants
not Variables
:
const.php
echo memory_get_usage[] . '
'; // output: 674,576
for [$i = 0; $i lang[$this->language]]] { echo $this->lang[$this->language][$str]; return; } echo $str; } private ...