0

是否可以使用 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 小部件,并且翻译是在您提供信息之后进行的,但在这种情况下,我们需要在提供信息之前进行翻译......

4

1 回答 1

0

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

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

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

于 2015-06-26T00:05:03.520 回答