Using Google Translator within a page or post
Posted February 13, 2007 at 03:02am in Programming
This snippet of code will translate any inline text into the language of your choice. My site already makes use of the translator offered by Google, but with languages such as Arabic where you read it right to left it seems to flip my entire site. I am working on making this a plugin to make it easier.
Code: func.translate.phps
Example: This is an example of inline translation of “Hello Visitors, this is Arabic” مرحبا زوار هذا العربية . Being that it is in Arabic you actually read it right to left.
Language Codes:
"ar|en" Arabic to English BETA
"zh|en" Chinese to English BETA
"zh-CN|zh-TW" Chinese (Simplified to Traditional) BETA
"zh-TW|zh-CN" Chinese (Traditional to Simplified) BETA
"en|ar" English to Arabic BETA
"en|zh-CN" English to Chinese (Simplified) BETA
"en|zh-TW" English to Chinese (Traditional) BETA
"en|fr" English to French
"en|de" English to German
"en|it" English to Italian
"en|ja" English to Japanese BETA
"en|ko" English to Korean BETA
"en|pt" English to Portuguese
"en|ru" English to Russian BETA
"en|es" English to Spanish
"fr|en" French to English
"fr|de" French to German
"de|en" German to English
"de|fr" German to French
"it|en" Italian to English
"ja|en" Japanese to English BETA
"ko|en" Korean to English BETA
"pt|en" Portuguese to English
"ru|en" Russian to English BETA
"es|en" Spanish to English








March 31st, 2007 at 6:05 pm
Hello,
I’ve been trying your code with all kinds of inputs, and it always fails…
I’ve tried to see what the $str_result contains through a var_dump, and it’s always set to bool(false).
What could be wrong ? There’s nothing else but your function in the PHP code.
Thanks in advance for your answer !
Wing.
March 31st, 2007 at 9:07 pm
If $str_result is false it sounds like the curl extension is not enabled. I just retested it and everything works fine. Also make sure that when you get it working that the head had a UTF-8 specification so it displays correctly.
April 1st, 2007 at 1:07 am
Oh stupid me… I thought that curl was enabled by default.
I’ll try it again. Thanks for your answer, and for your script !