diff --git a/docusaurus.config.js b/docusaurus.config.js index d901179..9f12bf5 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -194,6 +194,11 @@ const config = { position: 'left', dropdownActiveClassDisabled: true, }, + { + type: 'html', + position: 'right', + value: '
', + }, { href: 'https://developers.scalar-labs.com/docs/', position: 'right', diff --git a/src/helper/google-translate.js b/src/helper/google-translate.js new file mode 100644 index 0000000..ef758d3 --- /dev/null +++ b/src/helper/google-translate.js @@ -0,0 +1,6 @@ +function googleTranslateElementInit() { + new google.translate.TranslateElement( + {pageLanguage: 'en'}, + 'google_translate_element' + ); +} diff --git a/src/theme/NavbarItem/HtmlNavbarItem.tsx b/src/theme/NavbarItem/HtmlNavbarItem.tsx new file mode 100644 index 0000000..cd5a7a6 --- /dev/null +++ b/src/theme/NavbarItem/HtmlNavbarItem.tsx @@ -0,0 +1,78 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React, {useEffect} from 'react'; +import clsx from 'clsx'; + +import type {Props} from '@theme/NavbarItem/HtmlNavbarItem'; + +function loadGoogleTranslateScript() { + if (typeof window !== "undefined" && typeof document !== "undefined") { + const addScript = document.createElement('script'); + addScript.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'; + addScript.async = true; + document.body.appendChild(addScript); + window.googleTranslateElementInit = async function () { + // Function to initialize the Google Translate widget + const initGoogleTranslate = () => { + new google.translate.TranslateElement( + { pageLanguage: 'en', includedLanguages: 'ja' }, + 'google_translate_element' + ); + }; + + // Function will wait for element id to be available + const waitForElement = () => { + return new Promise