almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
I want to translate whole page..text ...not redirect page to translator...
You dont already have a frame breaker in your ?
<script language='Javascript' type='text/javascript'>
<!--
if (top.location != self.location) { top.location = self.location.href }
//-->
</script>
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
keep dropdpwn names written in the target language.
Francais
Espanol
deutsch
suomi
with the greves & cedillas carets etc
They are not words in the source of the language pair so are skipped in translation, the labels dont change.
If you examine the sample link title text and innerHtml both are written in the the target language, so the labels do not alter.
a user looking for a german translation of your site for readability, expects to see 'deutsch', not allemande german njemački německy
google translate Babelfish, already offer their sites localized, so all language pairs are available to all persons pretty much in their own language.
$_SERVER['request_url'] is the url requesting the page, if the translator is working it is the translator.
the original was PHP_SELF which works
If you change something and it ceases to work, then the change is the fault
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Thought I'd write a PHP implementation of the Google Language API.
/**
* Translating language with Google API
* @author gabe@fijiwebdesign.com
* @version $id$
* @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
*
* Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
*
*/
class Google_Translate_API {
/**
* Translate a piece of text with the Google Translate API
* @return String
* @param $text String
* @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
* @param $to String[optional] Language to translate $text to
*/
function translate($text, $from = '', $to = 'en') {
$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
$response = file_get_contents(
$url,
null,
stream_context_create(
array(
'http'=>array(
'method'=>"GET",
'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
)
)
)
);
if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
return self::_unescapeUTF8EscapeSeq($matches[1]);
}
return false;
}
/**
* Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
* @return UTF-8 String
* @param $str String
*/
function _unescapeUTF8EscapeSeq($str) {
return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
}
}
Example use:
$text = 'Welcome to my website.';
$trans_text = Google_Translate_API::translate($text, '', 'it');
if ($trans_text !== false) {
echo $trans_text;
}
I've added this to the snippets section: http://www.daniweb.com/code/showsnippet.php?codeid=1069
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
hi,digital-ether
I want to do like this
http://demo.oscommerce.com/index.php
In this at right column there are languages ...
If click on image change language of whole page....
i already post my code for to images with translated link...in post no 6
when click for English language link is
http://demo.oscommerce.com/index.php?language=en
it converts that to selected language and rewrite to
suppose..
For Deutsch
http://demo.oscommerce.com/index.php?language=de
How to do like this??
With the google api you'll need to translate pieces of text from your site. You can't really translate the whole page at once.
If the content of your site is taken from a database, you can translate the content from the database before display.
It may even be good to save the translation locally.
OSCommerce works exactly in this way, but manually. There are multiple translations of their content in the database. Even menu items have different translations.
This is similar to how the Joomla CMS, Drupal CMS, etc. handle translations also, but like OSCommerce they are manual translations.
So if you have the code that retrieves the contents for your website, you can just plug in the code to translate that content there, depending on the chosen language.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101