Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function mt($text, $lang) {
  2.  
  3. $url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey . '&q=' . rawurlencode($text) . '&source=en&target=' . $lang;
  4. $handle = curl_init($url);
  5. curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  6. curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
  7. $response = curl_exec($handle);
  8. $responseDecoded = json_decode($response, JSON_UNESCAPED_UNICODE);
  9. $responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
  10.  
  11. curl_close($handle);
  12.  
  13. if($responseCode != 200) {
  14. $resultxt = 'not200result';
  15. }
  16. else {
  17. $resultxt = $responseDecoded['data']['translations'][0]['translatedText'];
  18. }
  19. return $resultxt;
  20. }
  21.  
  22. <value>&#x3088;&#x3046;&#x3053;&#x305D;&#xFF05;0 ST&#x6570;&#x5B66;</value>
  23.  
  24. $xml=simplexml_load_file('myfile.xml'); //Load source XML file
  25. $xml->addAttribute('encoding', 'UTF-8');
  26. $xmlFile = 'translation.xml'; //File that will be saved
  27. //Here I have a call to the MT function above and get it to the XML file at face value.
  28. $xml->asXML($xmlFile) //save translated XML file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement