我已经创建了一个网站,我想为此网站添加3种语言(台湾,中国,英语)-多语言网站。 我试图找到Google语言API教程,但我真的很了解他们的指南,并且不知道如何使用它。您有一些简单的编码示例可以为我介绍在网站上引用添加多语言吗?谢谢。
答案 0 :(得分:0)
答案 1 :(得分:0)
请使用以下代码与Google进行翻译:
function LoginResponse({ history, setUser }) {
const [error, setError] = useState(null);
useEffect(() => {
// the login redirect has been completed and we call the
// signinRedirectCallback to fetch the user data
userManager.signinRedirectCallback().then(user => {
// received the user data so we set it in the app state and push the
// router to the secure or bookmarked route
setUser(user);
history.push(postLoginUri.get());
}, ({ message }) => {
// userManager throws if someone tries to access the route directly or if
// they refresh on a failed request so we just send them to the app root
if (message && redirectErrors.includes(message)) {
history.push('/');
return;
}
// for all other errors just display the message in production it would be
// a good idea to initiate a sign out after a countdown
setError(message);
});
}, []);
return error;
}
export default LoginResponse;
答案 2 :(得分:0)
添加Google Translate API非常容易实现。您可以按照以下步骤添加Google翻译脚本。
步骤1:为Google API设置CDN路径。
步骤2:设置div元素以放置Translator。
第3步。为网页设置默认语言。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Google Translater for Website </title>
</head>
<body>
<h2>Your Web Page</h2>
<p>Click on the dropdown button to translate.</p>
<p>Translate this page:</p>
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<p>You can translate the content of this page by selecting a language in the select box.</p>
</body>
</html>
复制此代码并在任何编辑器上运行。 来源:https://www.coderepublics.com/howto/how-to-google-translate.php