function l10n_client_page_alter in Localization client 7
Implement hook_page_alter().
Output a form to the page and a list of strings used to build the page in JSON form.
File
- ./
l10n_client.module, line 197 - Localization client. Provides on-page translation editing.
Code
function l10n_client_page_alter(&$page) {
global $conf, $language;
// Check permission and get all strings used on the page.
if (l10n_client_access() && ($page_strings = _l10n_client_page_strings())) {
// If we have strings for the page language, restructure the data.
$l10n_strings = array();
foreach ($page_strings as $textgroup => $group_strings) {
foreach ($group_strings as $context => $context_strings) {
foreach ($context_strings as $string => $translation) {
$l10n_strings[] = array(
$string,
$translation,
$textgroup,
$context,
);
}
}
}
array_multisort($l10n_strings);
// Include string selector on page.
$string_list = _l10n_client_string_list($l10n_strings);
// Include editing form on page.
$form = drupal_get_form('l10n_client_form', $l10n_strings);
$l10n_form = drupal_render($form);
// Include search form on page.
$form = drupal_get_form('l10n_client_search_form');
$l10n_search = drupal_render($form);
// Generate HTML wrapper with strings data.
$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 = "\n <div id='l10n-client' class='l10n-client-minimized'>\n <div class='labels'>\n <span class='toggle'>{$toggle_label}</span>\n <div class='label strings'>{$string_label}</div>\n <div class='label source'>{$source_label}</div>\n <div class='label translation'>{$translation_label}</div>\n </div>\n <div id='l10n-client-string-select'>\n {$string_list}\n {$l10n_search}\n </div>\n <div id='l10n-client-string-editor'>\n <div class='source'>\n <div class='source-text'></div>\n <div class='context'></div>\n </div>\n <div class='translation'>\n {$l10n_form}\n </div>\n </div>\n </div>\n {$l10n_dom}\n ";
$page['page_bottom']['l10n_client'] = array(
'#type' => 'markup',
'#markup' => $output,
);
}
}