Php code for language translation

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 ...

What is localization PHP?

A "Locale" is an identifier used to get language, culture, or regionally-specific behavior from an API. PHP locales are organized and identified the same way that the CLDR locales used by ICU [and many vendors of Unix-like operating systems, the Mac, Java, and so forth] use.

How can I convert Arabic to English in PHP?

What you could do as a makeshift solution is this : dynamically append a "dir=rtl" attribute to your html tag [or whatever tag containing text to be translated] and then somehow redirect to a google translated version of that page.

How do I translate HTML into another language?

To translate attributes inside an HTML element:.
Add the placeholder to the translation area, then click on it..
A modal will appear. ... .
When you're done translating the attributes, click the Apply button. ... .
After you're finished translating the string, hit Save..

Chủ Đề