views:

297

answers:

3

Hi friends,

I have created a website, i want to add localisation for this website - multilingual website. I have created this using PHP, javascript and ajax.

I had tried for google language translator API. Is there any other way to do this. Could you please suggest me how to implement this in my website.

A: 

One solution comes to my mind - you can use something like an internal dictionary. But this will require replacing all your text with special keywords that will later be automatically converted to a text in a corresponding language.

How to implement it is up to you. I have seen one implementation of this system using Smarty. There was a special function that looked up text by keyword from a database, inside a template it looked like this:

<p>{dictionary word="hello_world_text"}</p>
<form action="" method="post">
    <input type="text" name="hello_world[text]" value="{dictionary word="default_text_value"}" />
    <input type="submit" name="submit" value="{dictionary word="submit_text"}" />
</form>

When a template is be displayed, Smarty's internal function will lookup all the texts and place them into the page. Of course, you will have to first put all of the texts in different languages into the database.

Igor Zinov'yev
+1  A: 

zinigor's idea will work for you... or you can look into implementing resource bundles somehow in PHP. The latter will be faster.

Jas Panesar
A: 

It is straight forward to use Google Language API and rather than me post copies of it here i suggest you walk through some of the tutorials Google provide. It is JavaScript based and connects directly to Google so need for code to be downloaded.

However beware of machine translation. In certain circumstances it is fine in others it can be problematical, inaccurate misleading etc.

You can use a tag based approach as suggested and replace the text on the fly depending on the users preferences. But that is where it becomes interesting. How do you know what language the user wants? Sniff the browser language setting? Ask the user? Also once you go beyond one language you have the maintenance aspect of keeping it all up to date and in sync.

Before embarking on localisation you really need to work out if you actually need it and if the development and maintenance costs are going to be repaid.

PurplePilot