을 몇 가지 개선 나쁜 번역이나 영어 문제를 피하기 위해 - http://jsfiddle.net/F248G/3/
0 도움을 주셔서 감사합니다 순전히 - 물론
// Set the original/default language
var lang = "en";
var currentClass = "currentLang";
// Load the language lib
google.load("language", 1);
// When the DOM is ready....
window.addEvent("domready", function() {
// Retrieve the DIV to be translated.
var translateDiv = document.id("languageBlock");
// Define a function to switch from the currentlanguage to another
var callback = function(result) {
if (result.translation) {
translateDiv.set("html", result.translation);
}
};
// is language set? if so, auto translate
(function() {
// to avoid "lost in translation" on stacking up, i.e.
// translate from english to spanish, then from translated spanish back to english or others
// with errors, always use english as base language.
if (!translateDiv.retrieve("orig_en")) {
translateDiv.store("orig_en", translateDiv.get("html"));
}
// check cookie and if so, translate and set new base language
var toLang = Cookie.read("googleLang");
if (toLang && toLang != lang) {
google.language.translate(translateDiv.retrieve("orig_en"), lang, toLang, callback);
lang = toLang;
}
})();
// Add a click listener to update the DIV
$$("#languages a").addEvent("click", function(e) {
// Stop the event
if (e) e.stop();
// Get the "to" language
var toLang = this.get("rel");
if (toLang === lang)
return;
// Set the translation into motion
google.language.translate(translateDiv.get("html"), lang, toLang, callback);
// Set the new language
lang = toLang;
// Add class to current
this.getSiblings().removeClass(currentClass);
this.addClass(currentClass);
// ... and add here the code to save the last choice
Cookie.write("googleLang", toLang, {
path: "/"
});
});
});
, 당신은 단지 http://mootools.net/docs/core/Utilities/Cookie
헤이 디미타르 볼 수 있었다. – Pennf0lio
나는 그것을 올바르게하고있다 (http://jsbin.com/ovage5)? – Pennf0lio
번호. 업데이트 된 답변. 분명히 조각보다 더 많은 것을 필요로합니다 ... tbh 필자는이 코드 스 니펫을 직접 다 언어 작업의 기반으로 사용할 수 있다고 생각하기 때문에이 코드를 다시 작성합니다. –