views:

171

answers:

1

Afternoon,

Bit of a tricky question this one, I have a website and need to translate the pages into french, I am using google translate API to do the translation. What I am doing is loading in the HTML templates into a string using PHP and then need to translate the text copy on the pages and then save as for example:

fr_master_header.html
de_master_header.html

The problem I have is identifying the text copy on the page ignoring the HTML, replacing the copy in the extact place and then saving the file with the HTML tags and trasnlated text copy.

Cheers in advanced.

A: 

Thinking about translating your application before you write it is going to save a massive amount of time/money. You might be able to go back and fix the HTML, but this is going to be seriously masochistic. You are far better off with the Goolge Ajax Language API if you are adding language support after you've built the app.

I took care of this problem by using variables for every piece of text. Then I check what the language the user wants and I include the corresponding language file. My template system takes care of where to place these variables. These language files look something like this:

$_TEXT['Login']['title']="Enter Username and Password";
$_TEXT['Login']['error']['pass']="incorrect password";
$_TEXT['Login']['error']['name']="invalid username";

The variable name is always going to be the same regardless of the language. This is very scalable, I can support as many languages as Google will translate without making any modifications.

Rook