Page 1 of 1

Language Converter

Posted: Wed Apr 12, 2006 1:41 am
by sakthi
Hi everybody,

This is my first post.I need a help from you.
i have to display some contents from database in different languages.
This is depends on the EndUser.

He/She shall like to view in Chinese or Japanese or arebian. Whatever
it is, i have to provide the facility to convert to the desired language
from english.

how can i achive in PHP.


anybody can help!, please.


thankyou...

Posted: Wed Apr 12, 2006 4:31 am
by jito
may be it's my fault that i can't understand it properly, but will u explain a bit. what u really want to do? u hava web page displaying data from a database in english and u want to translate that page in any other language at runtime? is it?

Language Converter - reply

Posted: Wed Apr 12, 2006 5:37 am
by sakthi
hello jito,

your understand is correct.

that is my requirement.i have to produce in different language
at runtime.

Posted: Wed Apr 12, 2006 6:15 am
by s.dot
PHP will not convert languages by using a set of functions. You would have to define your data in the different languages you will be allowing, and then call the correct data from the database.

Posted: Wed Apr 12, 2006 7:51 am
by BDKR
One option is to have the text to be used defined (as constants) based on the language desired. After that, define constants or a hash table that represents bits of the text you wish to use. For example:

Code: Select all

switch($language)
    {
    'English':
        {
        define('PAGE_TITLE', 'Hello!');
        define('SHOW_LOVE', 'I Love You');
        }

    'Spanish':
        {
        define('PAGE_TITLE', 'Hola!');
        define('SHOW_LOVE', 'Te Amo');
        }

    'Dutch':
        {
        define('PAGE_TITLE', 'Halo!');
        define('SHOW_LOVE', 'Ik houd van u');
        }
    }
The above is just an example. But as far as examples go, it's not entirely a good one. The reason being that we are talking about language. Your site will need a lot of definitions for the various bits of text that will be used on the site. A better option would be ...

Code: Select all

switch($language)
    {
    'English':
        { require_once('english_definitions.php'); }

    'Spanish':
        { require_once('spanish_definitions.php'); }

    'Dutch':
        { require_once('dutch_definitions.php'); }
    }
Lastly, you may not want to use constants. Setting up hundreds of these may be a bit slower then creating a big hash table (associative array).

Hope that helps. :wink:

Cheers,
BDKR

Posted: Wed Apr 12, 2006 10:39 am
by timvw
BDKR wrote:

Code: Select all

'Dutch':
        {
        define('PAGE_TITLE', 'Halo!');
        define('SHOW_LOVE', 'Ik houd van u');
        }
    }
Should be 'Hallo' and 'Ik hou van jou' :)

Posted: Wed Apr 12, 2006 11:12 am
by BDKR
timvw wrote:
BDKR wrote:

Code: Select all

'Dutch':
        {
        define('PAGE_TITLE', 'Halo!');
        define('SHOW_LOVE', 'Ik houd van u');
        }
    }
Should be 'Hallo' and 'Ik hou van jou' :)
Thanx! My Dutch is really rusty as you can see. :oops: