마이크로소프트 빙 번역기 라이브러리입니다.

· 2016-04-18 (월) 10:41:13 · 7821 · 2
<?php
class BingTransrator
{
protected $_token;

public function getToken() {
$postData = array (
'client_id' => '클라이언트 아이디',
'client_secret' => '클라이언트 시크릿키',
'grant_type' => 'client_credentials',
'scope' => 'http://api.microsofttranslator.com'
);

$ch = curl_init("https://datamarket.accesscontrol.windows.net/v2/OAuth2-13");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);
$result = json_decode($result);

if (!is_object($result) || empty($result->access_token)) {
die("Access Token Error");
}

$this->_token = $result->access_token;
}

// 바꿀문자, 기존언어, 변경할언어
public function translate($content, $languageFrom = 'en', $languageTo = 'ko') {
$postData = array(
'text' => $content,
'from' => $languageFrom,
'to' => $languageTo,
'contentType' => 'text/plain'
);

$ch = curl_init('http://api.microsofttranslator.com/V2/Http.svc/Translate?' . http_build_query($postData));
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->_token));

$translation = curl_exec($ch);
return trim($translation);
}

}

/* 사용법
include_once(G5_LIB_PATH.'/translate.bing.lib.php');

$bing = new BingTransrator();
$bing->getToken();

echo htmlspecialchars_decode($bing->translate('변경할 문자', '기존언어', '변경할언어'));
?>


빙번역은 찾아도 없길래 올려봅니다 ''
( 구글번역은 유료라서....하앍...)

1. https://datamarket.azure.com/account 에서 아이디 생성
2. https://datamarket.azure.com/dataset/bing/microsofttranslator 에서 0원짜리 2만 캐릭터를 구매한다 [결제없음]
3. https://datamarket.azure.com/developer/applications/register 에서 어플을 하나 생성한다.
(주의 : Redirect URI는 http://를 포함해서 본인의 사이트를 써도돼고, http://www.google.com 을 써도 됨
단 http:// 무조건 포함)
4. 위의 라이브러리를 그누보드 라이브러리 폴더에 translate.bing.lib.php 저장한다.
5. translate.bing.lib.php 저장한 파일을 열어서 client_id에는 위에서 생성한 cliend_id 복붙, client_secret도 마찬가지로 복붙
6. 번역할 페이지 가서 include 해준 후 사용
7. 끗
|

댓글 2개

2016-04-18 (월) 11:16:02
좋은 정보 감사합니다 .!! 시간날때 사용해보겠습니다. ~~ 복받으세요 ~
감사합니다 : )
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
16-06-08 조회 1.1만
16-06-03 조회 9,725
16-06-01 조회 2.5만
16-06-01 조회 8,830
16-06-01 조회 1.1만
16-05-31 조회 9,408
16-05-30 조회 8,827
16-05-25 조회 1.1만
16-05-23 조회 8.1만
16-05-19 조회 7,384
16-05-18 조회 6,826
16-05-17 조회 9,061
16-05-04 조회 1만
16-05-02 조회 8,225
16-04-18 조회 7,822
16-04-15 조회 8,507
16-04-08 조회 2.2만
16-04-07 조회 7,919
16-04-07 조회 9,104
16-04-06 조회 9,723
16-03-30 조회 8,152
16-03-23 조회 1.1만
16-03-23 조회 1.2만
16-03-20 조회 1만
16-03-18 조회 1.2만
16-03-17 조회 8,893
16-03-17 조회 9,118
16-03-17 조회 7,147
16-03-15 조회 1.2만
16-03-09 조회 7,268