getOption('translator', $scriptProperties); /** @var modResource $resource */ $resource = $modx->getOption('resource', $scriptProperties); /** @var string $tvname */ $tvname = $modx->getOption('tvname', $scriptProperties); /** @var string $value */ $value = $modx->getOption('value', $scriptProperties); /** @var modResource $to */ $fromCulture = $modx->getOption('fromCulture', $scriptProperties); /** @var string $toCulture */ $toCulture = $modx->getOption('toCulture', $scriptProperties); $corePath = $modx->getOption('babeltranslate.core_path', null, $modx->getOption('core_path') . 'components/babeltranslate/'); /** @var BabelTranslate $babeltranslate */ $babeltranslate = $modx->getService('babeltranslate', 'BabelTranslate', $corePath . 'model/babeltranslate/', [ 'core_path' => $corePath ]); switch ($tvname) { case 'myTV': // Restrict the translation to the TV with this name. $migxFields = ['title', 'text']; // Translate the array values of MIGX TV using the keys in the array. break; default: $migxFields = []; break; } $migxValues = json_decode($value, true); if (is_array($migxValues)) { foreach ($migxValues as &$migxValue) { foreach ($migxFields as $migxField) { $translation = $babeltranslate->translator->translate($migxValue[$migxField], $fromCulture, $toCulture); if ($translation) { $migxValue[$migxField] = $translation; } else { if ($babeltranslate->getOption('debug')) { $modx->log(xPDO::LOG_LEVEL_ERROR, 'Invalid translation result of the value ' . $migxValue[$migxField] . ' of the MIGX TV ' . $tvname, '', 'BabelTranslateMigxTV Plugin'); } } } } } $resource->setTVValue($tvname, json_encode($migxValues)); return;