【问题标题】:How to use Google translate api to translate specific word only如何使用谷歌翻译 api 仅翻译特定单词
【发布时间】:2013-03-08 05:18:41
【问题描述】:

我只想翻译我的 PHP 网站中的特定单词。

例如

    Data      Language      Translation
---------------------------------------------
    Hello     select        ___________

当用户从下拉列表中选择语言时,翻译字段应更新为将 Hello 翻译成所选语言。

【问题讨论】:

    标签: transactions google-translate google-translator-toolkit


    【解决方案1】:

    你可以使用gtranslate-api-php,使用起来非常简单。

    <?php
          require("GTranslate.php");
    
          try{
             $gt = new Gtranslate;
             echo "Translating [Hello World] from English to German => ".$gt->english_to_german("hello world")."<br/>";
             echo "Translating [Ciao mondo] Italian to English => ".$gt->it_to_en("Ciao mondo")."<br/>";
          } catch (GTranslateException $ge)
          {
            echo $ge->getMessage();
          }
    ?>
    

    顺便说一句,当用户将语言选择到包含此代码的 php 文件(如果您不使用框架)时,您应该发出 ajax 请求,然后返回值并填充必填字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多