현재 사이트의 텍스트를 외국어로 번역하는 jQuery 스크립트를 작성 중입니다. 이를 위해 Google Translate API를 사용하고 있습니다. 페이지에 En Espanol이라는 링크가 포함되어 있고 En Espanol을 클릭하면 페이지의 본문이 영어로 표시되는 링크를 제외하고 스페인어로 번역됩니다. 사용자가 해당 링크를 클릭하면, 페이지 본문이 영어로 되돌아갑니다. 아래의 코드는 내가 지금까지 가지고있는 것이다. 어떤 도움이라도 대단히 감사하겠습니다. 고맙습니다.jQuery translate + toggle, 둘을 연결하는 방법?
JQuery와 :
$(document).ready(function(){
// hide all blocks that have class hide
//$('.hide').hide();
// toggle link1 with container1
// using chaining for performance and ease
// changing html of link
$('.showhide').toggle(function(){
//$(this).parent().next().slideDown('slow').removeClass('hide').preventDefault;
$(this).html('English');
},function(){
//$(this).parent().next().slideUp('slow').addClass('hide').preventDefault;
$(this).html('En Espanol');
})
});
HTML :
<p><a id="link1" class="showhide" href="#container1" onclick="translate('es');">
En Espanol</a></p>
<!--Calls Google Translate via div -->
<div id="translation"></div>
<div id="article">
<p>Google Inc is set to introduce on Tuesday a new Web browser designed to handle text
and graphics.</p>
</div>
무엇이 질문입니까? 언제 또는 어떻게 토글 할 것인가? Google의 API를 호출합니까? –
죄송합니다. 두 가지 질문이 있습니다. 링크를 토글하고 링크를 통해 Google API를 호출하여 텍스트를 번역하게하는 방법. – user160347