Програмно переводим сущности(entity)

Перевод сущности темина таксономии и его полей

  1. //Translate term ru
  2. $lang_first = 'ru';
  3.  
  4. $lang = array('en','ru');
  5. $term_title = $term->name_field['en'][0]['value'];
  6. $translate_term_title =custom_translate_data($lang,$term_title);
  7. $translate_term_title = $translate_term_title['text'][0];
  8. $term_title = $term->name_field['ru'][0]['value'] = $translate_term_title;
  9.  
  10.  
  11. $handler = entity_translation_get_handler('taxonomy_term', $term);
  12.  
  13. $translation = array(
  14. 'translate' => 0,
  15. 'status' => 1,
  16. 'language' => $lang_first,
  17. 'source' => 'en',
  18. );
  19.  
  20. $handler->setTranslation($translation, $term);
  21.  
  22. taxonomy_term_save($term);

Перевод сущности commerce product

  1. $lang_az = array('en','az');
  2. $text_title_az = $product->title_field['en'][0]['value'];
  3. $translate_title_az = custom_translate_data($lang_az,$text_title_az);
  4. $translate_title_az = $translate_title_az['text'][0];
  5.  
  6.  
  7. $handler = entity_translation_get_handler('commerce_product', $product); // Create a handler from entity translation
  8.  
  9. // Configuration about what to translate
  10. $translation = array(
  11. 'translate' => 0,
  12. 'status' => 1,
  13. 'language' => 'ru', // here is the language you're translating to
  14. 'source' => $product->language, // here is the source language
  15. );
  16.  
  17. $handler->setTranslation($translation);
  18. $handler->saveTranslations();
  19.  
  20.  
  21. $handler_az = entity_translation_get_handler('commerce_product', $product); // Create a handler from entity translation
  22.  
  23. commerce_product_save($product);
Russian
Категория: 
The code has been tested and works

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Target Image