You are here

protected function TMGMTLocaleSourcePluginController::updateTranslation in Translation Management Tool 7

Updates translation associated to a specific locale source.

Parameters

string $lid: The Locale ID.

string $target_language: Target language to update translation.

string $translation: Translation value.

Return value

bool Success or not updating the locale translation.

1 call to TMGMTLocaleSourcePluginController::updateTranslation()
TMGMTLocaleSourcePluginController::saveTranslation in sources/locale/tmgmt_locale.plugin.inc
Saves a translation.

File

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

Class

TMGMTLocaleSourcePluginController
Translation plugin controller for locale strings.

Code

protected function updateTranslation($lid, $target_language, $translation) {
  $languages = locale_language_list('name', TRUE);
  if (!$lid || !array_key_exists($target_language, $languages) || !$translation) {
    return FALSE;
  }
  $exists = db_query("SELECT COUNT(lid) FROM {locales_target} WHERE lid = :lid AND language = :language", array(
    ':lid' => $lid,
    ':language' => $target_language,
  ))
    ->fetchField();
  $fields = array(
    'translation' => $translation,
  );
  if (module_exists('l10n_update')) {
    module_load_include('inc', 'l10n_update');
    $fields += array(
      'l10n_status' => L10N_UPDATE_STRING_CUSTOM,
    );
  }

  // @todo Only singular strings are managed here, we should take care of
  //   plural information of processed string.
  if (!$exists) {
    $fields += array(
      'lid' => $lid,
      'language' => $target_language,
    );
    db_insert('locales_target')
      ->fields($fields)
      ->execute();
  }
  else {
    db_update('locales_target')
      ->fields($fields)
      ->condition('lid', $lid)
      ->condition('language', $target_language)
      ->execute();
  }

  // Clear locale caches.
  _locale_invalidate_js($target_language);
  cache_clear_all('locale:' . $target_language, 'cache');
  return TRUE;
}