You are here

public function TMGMTLocaleSourcePluginController::saveTranslation in Translation Management Tool 7

Saves a translation.

Parameters

TMGMTJobItem $job_item: The job item entity.

Return value

boolean TRUE if the translation was saved successfully, FALSE otherwise.

Overrides TMGMTSourcePluginControllerInterface::saveTranslation

File

sources/locale/tmgmt_locale.plugin.inc, line 197
Provides the locale source controller.

Class

TMGMTLocaleSourcePluginController
Translation plugin controller for locale strings.

Code

public function saveTranslation(TMGMTJobItem $job_item) {
  $job = tmgmt_job_load($job_item->tjid);
  $data = $job_item
    ->getData();
  if (isset($data['singular'])) {
    $translation = $data['singular']['#translation']['#text'];

    // Update the locale string in the system.
    // @todo: Send error message to user if update fails.
    if ($this
      ->updateTranslation($job_item->item_id, $job->target_language, $translation)) {
      $job_item
        ->accepted();
    }
  }

  // @todo: Temporary backwards compability with existing jobs, remove in next
  //   release.
  if (isset($data[$job_item->item_id])) {
    $translation = $data[$job_item->item_id]['#translation']['#text'];

    // Update the locale string in the system.
    // @todo: Send error message to user if update fails.
    if ($this
      ->updateTranslation($job_item->item_id, $job->target_language, $translation)) {
      $job_item
        ->accepted();
    }
  }
}