/** * @brief Applies translations from a translation memory to the webpage contents. It returns another SweteWebpage * object representing the same webpage but in the destination language of the translation memory. * No changes are saved to the database.. you need to save the resulting SweteWebpage to make the changes * persist. * * Note: If there are no matches in the translation memory, then the resulting object will just contain * the source language. This could be overwriting a previous translation so be very careful before * saving. * * @param XFTranslationMemory $mem The translation memory to apply to the webpage contents. * @param array &$stats Out array of stats from the translation. This array contains the following * keys: * <ul> * <li><b>misses</b> - The number of strings for which there were no translations in the memory.</li> * <li><b>matches</b> - The number of strings that were replaced with a translation.</li> * </ul> * @param int $minStatus The minimum approval status to accept for a translation. * @param int $maxStatus The maximum approval status to accept for a translation. * @returns SweteWebpage A webpage in the destination language including the translations. */ public function applyTranslationsFromMemory(XFTranslationMemory $mem, &$stats, $minStatus = 3, $maxStatus = 5) { if ($mem->getSourceLanguage() != $this->getLanguage()) { throw new Exception("Translation memory language does not match the record language."); } import('inc/ProxyWriter.php'); $proxy = new ProxyWriter(); $proxy->setTranslationMemory($mem); $proxy->setMinTranslationStatus($minStatus); $proxy->setMaxTranslationStatus($maxStatus); $html = $proxy->translateHtml($this->_rec->val('webpage_content'), $stats); $out = $this->getTranslation($mem->getDestinationLanguage()); $out->getRecord()->setValue('webpage_content', $html); return $out; }