PHP Trasnlate html page using google translate

After noon,

Slightly tricky question, I have a website and I need to translate pages to French, I am using google translation API to translate. I am doing loading in HTML templates to string using PHP and then need to translate text copy into pages and then save as for example:

fr_master_header.html
de_master_header.html

The problem is to identify the text copy on the page, ignore the HTML, replace the copy in the final location, and then save the file with HTML tags and drag and drop copy of the text.

Greetings advanced.

+2


a source to share


1 answer


Thinking about translating your application before writing it will save you a huge amount of time / money. You might be able to go back and fix the HTML, but that would be seriously masochistic. If you've added language support after you've created your app, you'll be much better off with the Goolge Ajax API .

I took care of this problem by using variables for each piece of text. Then I check which language the user wants and I include the corresponding language file. My templating 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 will always be the same regardless of the language. It's very scalable, I can support as many languages ​​as google will translate without any changes.

+3


a source







All Articles