Title: custom function
Last modified: October 2, 2019

---

# custom function

 *  Resolved [Chupizdik](https://wordpress.org/support/users/chupizdik/)
 * (@chupizdik)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/custom-function-5/)
 * 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 empty `echo $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.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/custom-function-5/#post-11990704)
 * Hi [@chupizdik](https://wordpress.org/support/users/chupizdik/)
 * > As me change string $yt_text = “name”;to obtain there significance $name or
   > obtain not empty echo $en_test?
 * You can replace **“name”** with **$name** to use the data from the import element
   in your function. See: [http://www.wpallimport.com/documentation/advanced/execute-php/](http://www.wpallimport.com/documentation/advanced/execute-php/).
 * Also, to check if it’s empty, you can use an IF conditional with the empty() 
   function:
 * [https://www.w3schools.com/php/php_if_else.asp](https://www.w3schools.com/php/php_if_else.asp)
   
   [https://www.php.net/manual/en/function.empty.php](https://www.php.net/manual/en/function.empty.php)
 *  Thread Starter [Chupizdik](https://wordpress.org/support/users/chupizdik/)
 * (@chupizdik)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/custom-function-5/#post-11990749)
 * “You can replace “name” with $name to use the data from the import element in
   your function.” – It doesn’t work! $en_test Blank…
 *  Thread Starter [Chupizdik](https://wordpress.org/support/users/chupizdik/)
 * (@chupizdik)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/custom-function-5/#post-11990846)
 * [https://www.php.net/manual/en/function.empty.php](https://www.php.net/manual/en/function.empty.php)–
   Thanks. He says the $name variable is empty.
 *  Thread Starter [Chupizdik](https://wordpress.org/support/users/chupizdik/)
 * (@chupizdik)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/custom-function-5/#post-11991999)
 * Спасибо, я разобралась вроде)))

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘custom function’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Chupizdik](https://wordpress.org/support/users/chupizdik/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/custom-function-5/#post-11991999)
 * Status: resolved