【问题标题】:Translate value before sending information在发送信息之前翻译值
【发布时间】:2015-09-12 18:57:04
【问题描述】:

是否可以使用 google api translate 或任何其他 api 来翻译 php 中的值...

<?php
   // 1.- Query to get information
   // 2.- build array with that query
   // Example array from query
   $data = array(
          '0' => array (
                   'name' => 'Zapatos',
                   'color' => 'Verde'
                 ),

          '1' => array (
                   'name' => 'Casa',
                   'color' => 'Rosa'
                 ),
           );
       // Now that the array has been build, lets make a translation
       // Which I have no idea how to do that but the final array should be

$final = array(
          '0' => array (
                   'name' => 'Zapatos',
                   'color' => 'Verde',
                   'name_en' => 'Shoes',
                   'color_en' => 'Green'
                 ),

          '1' => array (
                   'name' => 'Casa',
                   'color' => 'Rosa',
                   'name_en' => 'House',
                   'color_en' => 'Pink'
                 ),
           );

这个过程是可能的还是我只是在做梦?
我对 Goolge API 的工作原理知之甚少,因为我只使用 Google Translate 小部件,并且翻译是在您提供信息之后进行的,但在这种情况下,我们需要在提供信息之前进行翻译......

【问题讨论】:

    标签: php google-translate machine-translation


    【解决方案1】:

    Google 翻译 API 是一项付费服务​​。您需要从 google api services 获取 api 密钥: google translate API

    之后,您可以在从查询中获取结果后对 google api 进行 curl: curl 的示例网址: https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world&q=My%20name%20is%20Jeff

    您将以 JSON 对象的形式获取结果,执行 json_decode 并将结果添加到您的数组中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2016-11-13
      • 2012-11-15
      相关资源
      最近更新 更多