You are here

function i18n_string_l10n_client_save_string in Internationalization 7

Menu callback. Saves a string translation coming as POST data.

1 string reference to 'i18n_string_l10n_client_save_string'
i18n_string_menu in i18n_string/i18n_string.module
Implements hook_menu().

File

i18n_string/i18n_string.pages.inc, line 262
Internationalization (i18n) package - translatable strings reusable admin UI.

Code

function i18n_string_l10n_client_save_string() {
  global $user, $language;
  if (user_access('use on-page translation')) {
    $textgroup = !empty($_POST['textgroup']) ? $_POST['textgroup'] : 'default';

    // Other textgroups will be handled by l10n_client module
    if (!i18n_string_group_info($textgroup)) {
      return l10n_client_save_string();
    }
    elseif (isset($_POST['source']) && isset($_POST['target']) && !empty($_POST['context']) && !empty($_POST['form_token']) && drupal_valid_token($_POST['form_token'], 'l10n_client_form')) {
      $name = $textgroup . ':' . $_POST['context'];
      if ($i18nstring = i18n_string_get_source($name)) {

        // Since this is not a real form, we double check access permissions here too.
        if ($error = $i18nstring
          ->check_translate_access()) {
          $message = theme('l10n_client_message', array(
            'message' => t('Not saved due to: !reason', array(
              '!reason' => $error,
            )),
            'level' => WATCHDOG_WARNING,
          ));
        }
        else {
          $result = i18n_string_translation_update($name, $_POST['target'], $language->language, $_POST['source']);
          if ($result) {
            $message = theme('l10n_client_message', array(
              'message' => t('Translation saved locally for user defined string.'),
              'level' => WATCHDOG_INFO,
            ));
          }
          elseif ($result === FALSE) {
            $message = theme('l10n_client_message', array(
              'message' => t('Not saved due to insufficient permissions.'),
            ));
          }
          else {
            $message = theme('l10n_client_message', array(
              'message' => t('Not saved due to unknown reason.'),
            ));
          }
        }
      }
      else {
        $message = theme('l10n_client_message', array(
          'message' => t('Not saved due to source string missing.'),
        ));
      }
    }
    else {
      $message = theme('l10n_client_message', array(
        'message' => t('Not saved due to missing form values.'),
      ));
    }
    drupal_json_output($message);
    exit;
  }
}