You are here

function l10n_client_submit_translation in Localization client 7

Same name and namespace in other branches
  1. 6.2 l10n_client.module \l10n_client_submit_translation()
  2. 6 l10n_client.module \l10n_client_submit_translation()

Submit translation to the server.

1 call to l10n_client_submit_translation()
l10n_client_save_string in ./l10n_client.module
Menu callback. Saves a string translation coming as POST data.

File

./l10n_client.module, line 595
Localization client. Provides on-page translation editing.

Code

function l10n_client_submit_translation($langcode, $source, $translation, $user_key, $user_token) {
  $server_uid = current(explode(':', $user_key));
  $signature = md5($user_key . $langcode . $source . $translation . $user_token);
  $server_url = variable_get('l10n_client_server', 'https://localize.drupal.org/');
  $response = xmlrpc($server_url . '/xmlrpc.php', array(
    'l10n.submit.translation' => array(
      $langcode,
      $source,
      $translation,
      (int) $server_uid,
      $user_token,
      $signature,
    ),
  ));
  if (!empty($response) && isset($response['status'])) {
    if ($response['status']) {
      $message = t('Translation sent and accepted by @server.', array(
        '@server' => $server_url,
      ));
      watchdog('l10n_client', 'Translation sent and accepted by @server.', array(
        '@server' => $server_url,
      ));
    }
    else {
      $message = t('Translation rejected by @server. Reason: %reason', array(
        '%reason' => $response['reason'],
        '@server' => $server_url,
      ));
      watchdog('l10n_client', 'Translation rejected by @server. Reason: %reason', array(
        '%reason' => $response['reason'],
        '@server' => $server_url,
      ), WATCHDOG_WARNING);
    }
    return array(
      $response['status'],
      $message,
    );
  }
  else {
    $message = t('The connection with @server failed with the following error: %error_code: %error_message.', array(
      '%error_code' => xmlrpc_errno(),
      '%error_message' => xmlrpc_error_msg(),
      '@server' => $server_url,
    ));
    watchdog('l10n_client', 'The connection with @server failed with the following error: %error_code: %error_message.', array(
      '%error_code' => xmlrpc_errno(),
      '%error_message' => xmlrpc_error_msg(),
      '@server' => $server_url,
    ), WATCHDOG_ERROR);
    return array(
      FALSE,
      $message,
    );
  }
}