/** * Translate provided text to requested language * Configured method is used (default translation is a COPY) * * @param string $source_lang_code - two-letters language code (ISO 639-1) * @param string $src_text * @param string $dest_lang_code - two-letters language code (ISO 639-1) * @param string $translate_method (optional) * @return null * @throws AException */ public function translate($source_lang_code, $src_text, $dest_lang_code, $translate_method = '') { $this->registry->get('extensions')->hk_InitData($this, __FUNCTION__); if (empty($source_lang_code) || empty($src_text) || empty($dest_lang_code)) { return null; } //check what method is selected for translation if (empty($translate_method)) { $translate_method = $this->registry->get('config')->get('translate_method'); } $extensions = $this->registry->get('extensions')->getEnabledExtensions(); if (in_array($translate_method, $extensions)) { $ex_class = DIR_EXT . $translate_method . '/core/translator.php'; if (file_exists($ex_class)) { /** @noinspection PhpIncludeInspection */ require_once $ex_class; } else { throw new AException(AC_ERR_LOAD, 'Error: Could not load translations class ' . $ex_class . '!'); } /** @noinspection PhpUndefinedClassInspection */ $translate_driver = new translator($this->registry->get('config')); /** @noinspection PhpUndefinedMethodInspection */ $result_txt = $translate_driver->translate($source_lang_code, $src_text, $dest_lang_code); if (!$result_txt) { $result_txt = $src_text; } ADebug::checkpoint("AlangugeManager: Translated text: {$src_text} from {$source_lang_code} to {$dest_lang_code}"); } else { //fail over to default 'copy_source_text' method $result_txt = $src_text; } $this->registry->get('extensions')->hk_UpdateData($this, __FUNCTION__); return $result_txt; }