{"id":16576,"library":"vue-gtranslate","title":"Vue Google Translate Integration Component","description":"The `vue-gtranslate` package provides a Vue.js component designed to integrate Google Translate's 'Website Translator' widget into a Vue application. It facilitates on-the-fly page translation, supporting approximately 40 languages, and allows for basic visual customization through CSS classes. As of version 2.0.20, the project is actively maintained but explicitly cautions users about potential instability and the expectation of bugs, suggesting a more community-driven or less rigorously tested release cycle. Its core differentiator lies in simplifying the embedding process of the Google Translate script and its associated UI within a Vue component, thereby abstracting some of the direct DOM manipulation typically required. This solution wraps Google's client-side translation widget and does not offer an offline or server-side translation mechanism.","status":"maintenance","version":"2.0.20","language":"javascript","source_language":"en","source_url":"https://github.com/Katalyst33/vue-gtranslate","tags":["javascript","translator","vue js","gtranslate","google translate"],"install":[{"cmd":"npm install vue-gtranslate","lang":"bash","label":"npm"},{"cmd":"yarn add vue-gtranslate","lang":"bash","label":"yarn"},{"cmd":"pnpm add vue-gtranslate","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary component for rendering the Google Translate widget.","wrong":"const Translator = require('vue-gtranslate');","symbol":"Translator","correct":"import Translator from 'vue-gtranslate';"},{"note":"This CSS import is crucial for styling the widget and, importantly, for hiding the default Google Translate pop-up/banner. Ensure it's imported in your main app component or globally.","wrong":"import 'vue-gtranslate/src/translator.css';","symbol":"translator.css","correct":"import 'vue-gtranslate/translator.css';"}],"quickstart":{"code":"<!-- public/index.html (or equivalent root HTML file) -->\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Vue GTranslate App</title>\n    <script type=\"text/javascript\">\n        function googleTranslateElementInit() {\n            new google.translate.TranslateElement(\n                { pageLanguage: \"en\", autoDisplay: false }, // autoDisplay: false to manage display via Vue\n                \"google_translate_element\"\n            );\n        }\n    </script>\n    <script\n        type=\"text/javascript\"\n        src=\"//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit\"\n    ></script>\n</head>\n<body>\n    <div id=\"app\"></div>\n    <div id=\"google_translate_element\" style=\"display: none;\"></div> <!-- Hidden div for Google widget -->\n    <script type=\"module\" src=\"/src/main.js\"></script> <!-- Assuming Vue CLI/Vite setup -->\n</body>\n</html>\n\n// src/App.vue\n<template>\n  <div id=\"app\">\n    <h1>Welcome to My App</h1>\n    <p>This content will be translated.</p>\n    <Translator/>\n  </div>\n</template>\n\n<script setup>\nimport Translator from \"vue-gtranslate\";\nimport \"vue-gtranslate/translator.css\"; // Important for styling and hiding pop-up\n</script>\n\n<style>\nbody {\n  font-family: Arial, sans-serif;\n}\n.vg-body {\n  display: flex;\n  gap: 10px;\n  padding: 10px;\n  background: #f0f0f0;\n  border-radius: 5px;\n  justify-content: center;\n}\n.vg-container {\n  padding: 5px 10px;\n  font-size: 16px;\n  text-align: center;\n  background: white;\n  border: 1px solid #ddd;\n  border-radius: 3px;\n}\n.vg-text {\n  color: #333;\n  padding-left: 5px;\n}\n.vg-items {\n  display: flex;\n  align-items: center;\n}\n.vg-flag {\n  height: 24px;\n  vertical-align: middle;\n}\n</style>","lang":"typescript","description":"This quickstart demonstrates how to integrate `vue-gtranslate` into a Vue 3 application. It includes the necessary external Google Translate script setup in `index.html` and shows how to import and use the `Translator` component along with its crucial CSS for proper functionality and UI control."},"warnings":[{"fix":"Add `import 'vue-gtranslate/translator.css';` to your main Vue component or global stylesheet entry point.","message":"The Google Translate Website Translator widget injects its own pop-up or banner by default. To hide this, you *must* import `vue-gtranslate/translator.css` into your application. Without it, users will see an additional 'Google Translate' banner.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Be prepared to implement custom CSS overrides or JavaScript workarounds for common issues. Monitor the package's GitHub issues for known problems and community solutions. Consider testing thoroughly in production-like environments.","message":"The library explicitly states it 'may be unstable sometimes' and to 'expect bugs'. This indicates potential runtime issues, UI glitches, or unexpected behavior. It relies heavily on Google's external script, which is outside the control of this package.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Ensure the `<script>` tags for `element.js` and the `googleTranslateElementInit` function are correctly placed in your `index.html` `<head>` or `<body>` section as demonstrated in the quickstart, and that the `google_translate_element` div exists in the DOM.","message":"This package is merely a Vue wrapper around Google's client-side 'Website Translator' script. It critically depends on the external `element.js` script and the `googleTranslateElementInit` function being present and correctly initialized in your `index.html` file *before* your Vue application mounts. Failure to include this external script will result in the `Translator` component not functioning.","severity":"breaking","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Verify network connectivity, ensure no browser extensions are blocking the Google script, and confirm the `element.js` script and `googleTranslateElementInit` function are correctly embedded in your `index.html` file and loaded before your Vue application attempts to use `vue-gtranslate`.","cause":"The Google Translate external script (`element.js`) either failed to load, was blocked, or the `googleTranslateElementInit` callback was invoked before `google.translate` object was available.","error":"TypeError: Cannot read properties of undefined (reading 'TranslateElement')"},{"fix":"Ensure the `div` with the ID specified in `new google.translate.TranslateElement()` is present in your `index.html`. If you are manually controlling the widget's visibility, ensure your CSS or component logic correctly displays it. The `vue-gtranslate` component typically handles rendering it within its own template.","cause":"The target `div` for the Google Translate widget (e.g., `google_translate_element`) is missing from the DOM or hidden by CSS, or the `autoDisplay: false` option was used without a mechanism to trigger its display.","error":"The Google Translate widget is not visible or only shows a small flag icon without the language dropdown."}],"ecosystem":"npm"}