은 작업을 쉽게하기 위해 Google 번역 API의 래퍼입니다. 이 작동하지 않을 수 있습니다 많은 태그가 큰 XML을 위해, 또는 당신이 (태그) 전체 XML을 통과 할 수 있도록 구글이 각 IP 하루에 API 요청을 제한하는 것을
require_once ("include/GTranslate.php");
// original input xml
$orig_xml = "YOUR XML HERE";
// translate
$gt = new Gtranslate; // google translate object
$orig_text = array(); // original text
$trans_text = array(); // translated text
// extract text between tags
$split_tags_pattern = '|<[^>]+>([^<>]+)<\/[^>]+>|';
$tags = array();
preg_match_all($split_tags_pattern, $orig_xml, $tags, PREG_SET_ORDER);
/*
* preg_match_all returns:
*
* array() {
* array() {
* <xml tag>text</xml>,
* text
* },
* ...
* }
*/
// translate each tag's inner text
foreach ($tags as $tag) {
$text = trim($tag[1]);
if ($text != '') {
$orig_text[] = trim($tag[0]);
$trans_text[] = str_replace($text, $gt->en_to_ar($text), $tag[0]); // en_to_ar method is used to translate from english to arabic.
}
}
// replace original tag's inner text with translated ones
$trans_xml = str_replace($orig_text, $trans_text, $orig_xml);
참고 : 다음은 샘플 코드는 Google 번역 (이 경우에도 100,000 자 제한이 있지만 많은 경우 충분할 수 있음)을 선택한 다음 번역 결과에서 번역 된 내부 텍스트를 추출합니다.
Google에서 API를 업데이트 한 것으로 보입니다. 그리고 서비스는 지불됩니다. 기타 [여기]보기 (https://developers.google.com/translate/v2/getting_started) – pl71