php 找不到Google翻译框架

xzv2uavs  于 2023-04-10  发布在  PHP
关注(0)|答案(1)|浏览(119)

`我正在使用此翻译代码将我的网站翻译为特定语言,并遇到了错误。
我也想使用自定义的国旗。
下面是我使用的代码,但我有这个错误“错误:找不到Google翻译框架”

<script src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.2/js/bootstrap-select.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript">
    function googleTranslateElementInit() {
        new google.translate.TranslateElement({ pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false }, 'google_translate_element');
    }

    function translateLanguage(lang) {
        googleTranslateElementInit();
        var $frame = $('.goog-te-menu-frame:first');
        if (!$frame.size()) {
            alert("Error: Could not find Google translate frame.");
            return false;
        }
        $frame.contents().find('.goog-te-menu2-item span.text:contains(' + lang + ')').get(0).click();
        return false;
    }

    $(function(){
        $('.selectpicker').selectpicker();
    });
</script>
ylamdve6

ylamdve61#

我想这就是你要找的:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="src/style.css" />
    <script src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js" type="text/javascript"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.2/js/bootstrap-select.min.js" type="text/javascript"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script>
    <script type="text/javascript">
      function googleTranslateElementInit() {
        new google.translate.TranslateElement({ pageLanguage: "en", includedLanguages: "es,fr", autoDisplay: false }, "google_translate_element");
      }

      function translateLanguage() {
        var $frame = $(".goog-te-menu-frame:first");
        if (!$frame.size()) {
          alert("Error: Could not find Google translate frame.");
        }
        var $element = $("#translate_me");
        var text = $element.html();
        google.translate.translate(text, "en|es|fr", function (result) {
          if (result.translation) {
            $element.html(result.translation);
          }
        });
      }

      $(function () {
        $(".selectpicker").selectpicker();
      });
    </script>
  </head>
  <body>
    <div>This is the text that will be translated.</div>
    <div id="google_translate_element"></div>
  </body>
</html>

相关问题