Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mt($text, $lang) {
- $url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey . '&q=' . rawurlencode($text) . '&source=en&target=' . $lang;
- $handle = curl_init($url);
- curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
- $response = curl_exec($handle);
- $responseDecoded = json_decode($response, JSON_UNESCAPED_UNICODE);
- $responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
- curl_close($handle);
- if($responseCode != 200) {
- $resultxt = 'not200result';
- }
- else {
- $resultxt = $responseDecoded['data']['translations'][0]['translatedText'];
- }
- return $resultxt;
- }
- <value>ようこそ%0 ST数学</value>
- $xml=simplexml_load_file('myfile.xml'); //Load source XML file
- $xml->addAttribute('encoding', 'UTF-8');
- $xmlFile = 'translation.xml'; //File that will be saved
- //Here I have a call to the MT function above and get it to the XML file at face value.
- $xml->asXML($xmlFile) //save translated XML file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement