<?php $txt_file = file_get_contents('test.ucs'); $rows = explode("\n", $txt_file); $payload = []; foreach ($rows as $row) { $values = explode("\t", $row); $payload[] = [ 'key' => $values[0], 'value' => translate($values[1]) ]; if (count($payload) >= 1) { break; } } foreach ($payload as $value) { file_put_contents('BTmod.new.ucs', sprintf("%s\t%s\n", $value['key'], $value['value']), FILE_APPEND); } function translate($message) { if (mb_strlen(trim($message)) == 0) { return ''; } $query = http_build_query([ 'auth_key' => '', 'text' => $message, 'target_lang' => 'ru', ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://api-free.deepl.com/v2/translate?" . $query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $data = json_decode($output, true); return $data ? $data['translations'][0]['text'] : $message; }