Contributions API

l10n_client_footer

Definition

l10n_client_footer()
contributions/l10n_client/l10n_client.module, line 94

Description

Implementation of hook_footer().

Output a form to the page and a list of strings used to build the page in JSON form.

Code

<?php
function l10n_client_footer() {
  global $conf, $language;
  
  if (user_access('use on-page translation')) {
    // Get all strings used on the page.
    $strings = locale();
    
    if (is_array($strings) && isset($strings[$language->language])) {
      // If we have strings for the page language, restructure the data.
      $l10n_strings = array();
      foreach ($strings[$language->language] as $string => $translation) {
        $l10n_strings[] = array($string, $translation);
      }
      array_multisort($l10n_strings);
      // Include string selector on page.
      $string_list = _l10n_client_string_list($l10n_strings);
      // Include editing form on page.
      $l10n_form = drupal_get_form('l10n_client_form', $l10n_strings);
      // Include search form on page.
      $l10n_search = drupal_get_form('l10n_client_search_form');

      // We need this hack as JS addition does not work this late on the page.
      //$l10n_json = '<script type="text/javascript">jQuery.extend(Drupal, { l10nStrings: '. drupal_to_js($l10n_strings) .' });</script>';   
      $l10n_dom = _l10n_client_dom_strings($l10n_strings);

      // UI Labels
      $string_label = '<h2>'. t('Page Text') .'</h2>';
      $source_label = '<h2>'. t('Source') .'</h2>';
      $translation_label = '<h2>'. t('Translation to %language', array('%language' => $language->native)) .'</h2>';
      $toggle_label = t('Translate Text');


      $output = "
        <div id='l10n-client' class='hidden'>
          <div class='labels'>
            <span class='toggle'>$toggle_label</span>
            <div class='label strings'>$string_label</div>
            <div class='label source'>$source_label</div>
            <div class='label translation'>$translation_label</div>
          </div>
          <div id='l10n-client-string-select'>
            $string_list
            $l10n_search
          </div>
          <div id='l10n-client-string-editor'>
            <div class='source'>
              <div class='source-text'></div>
            </div>
            <div class='translation'>
              $l10n_form
            </div>
          </div>
        </div>
        $l10n_dom
      ";

      return $output;
    }
  }
}
?>