custom function
-
Hi! I want to write a custom function to check for English letters and automatically translate some csv fields (name and description) into Russian. To do this, I use Yandex API. Code verification on the availability of English letters fulfills well. Translation also works, but only if you specify the exact text you want to translate. How do I add {name[1]} instead of the exact text? Here is my code:
<?php function is_english($name) { if (strlen($name) != strlen(utf8_decode($name))) { $yt_api_key = "my-secret-api"; $yt_lang = "en-ru"; $yt_text = "name"; $yt_link = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=".$yt_api_key."&text=".$yt_text."&lang=".$yt_lang; $result = file_get_contents($yt_link); $result = json_decode($result, true); $en_test = $result['text'][0]; echo $en_test; } else { echo $name; } } ?>
As me change string
$yt_text = "name";
to obtain there significance$name
or obtain not emptyecho $en_test
?If you need a Yandex API key for This, write where to send it.
Thank you in advance, very much waiting for an answer.
I apologize for my English, translated from Russian by Yandex API.
- The topic ‘custom function’ is closed to new replies.