Soy realmente nuevo en JavaScript y me preguntaba qué objeto en JS podría usar para traducir (en el idioma) ciertos elementos identificados cuando hago clic en un enlace. Por ejemplo, cuando hago clic en un enlace que dice:
Traducir al alemán
Toda la página se traducirá al alemán.
Entiendo que puedo usar getElementByID, pero realmente no sé específicamente cómo.
Puedes usar Google Translate. Aquí hay un ejemplo (tomado de W3Schools):
<!DOCTYPE html> <html lang="en-US"> <body> <h1>My Web Page</h1> <p>Hello everybody!</p> <p>Translate this page:</p> <div id="google_translate_element"></div> <script type="text/javascript"> function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en', includedLanguages: 'de,en' // remove this line if you want to include all languages },'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>Míralo en vivo aquí