You are here

function l10n_client_contributor_help in Localization client 8

Implements hook_help().

File

l10n_client_contributor/l10n_client_contributor.module, line 22
Submits translations to a remote localization server.

Code

function l10n_client_contributor_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.l10n_client_contributor':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Localization Client Contributor allows users to contribute translations to the community from the convenience of their site. The community server is configured globally while each user needs access on the server and their own API key configured locally to identify with the server for contribution to happen.') . '</p>';
      $output .= '<p>' . t('The default community server is <a href=":server">:server</a> and may be changed on <a href=":configure">the configuration page</a>.', array(
        ':server' => 'https://localize.drupal.org/',
        ':configure' => Url::fromRoute('locale.settings'),
      )) . '</p>';
      $output .= '<p>' . t('Users need the <em>Contribute translations to localization server</em> permission to contribute to the community server as well as their personal API key configured on their user profile.') . '</p>';
      $output .= '<p>' . t('To contribute to a community server, permissions are required on the server side as well. <a href=":server">To contribute to :server, see the <em>How to contribute</em> section there.</a>', array(
        ':server' => 'https://localize.drupal.org/',
      )) . '</p>';
      return $output;
    case 'locale.translate_page':

      /** @var \Drupal\user\UserInterface $account */
      $config = \Drupal::config('l10n_client_contributor.settings');
      if (!$config
        ->get('use_server')) {
        return;
      }
      $account = User::load(\Drupal::currentUser()
        ->id());
      if ($account
        ->hasPermission('contribute translations to localization server')) {
        if ($account
          ->hasField('l10n_client_contributor_key')) {
          if ($account
            ->get('l10n_client_contributor_key')
            ->isEmpty()) {
            \Drupal::messenger()
              ->addWarning(t('<a href=":edit">Set your personal API key</a> to contribute translations automatically to :server. Thanks for contributing!', array(
              ':edit' => Url::fromRoute('entity.user.edit_form', array(
                'user' => $account
                  ->id(),
              ))
                ->toString(),
              ':server' => $config
                ->get('server'),
            )));
          }
          else {
            return '<p><strong>' . t('All changes made will be automatically submitted to :server too. Thanks for contributing!', array(
              ':server' => $config
                ->get('server'),
            )) . '</strong></p>';
          }
        }
        else {
          \Drupal::messenger()
            ->addWarning(t('The Localization Client Contributor module was not properly installed. The contributor API key field is missing from user accounts. Translation submissions will not be saved remotely.'));
        }
      }
      break;
  }
}